<commit_before>#ifndef MS_RTC_RTCP_FEEDBACK_PS_RPSI_HPP
#define MS_RTC_RTCP_FEEDBACK_PS_RPSI_HPP

#include "common.hpp"
#include "RTC/RTCP/FeedbackPs.hpp"

/* RFC 4585
 * Reference Picture Selection Indication (RPSI)
 *

   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |      PB       |
                  |0| Payload Type|
                                  |    Native RPSI bit string     |
  |   defined per codec          ...                | Padding (0) |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 */

namespace RTC
{
	namespace RTCP
	{
		class FeedbackPsRpsiItem : public FeedbackItem
		{
			const static size_t maxBitStringSize{ 6 };
			const static size_t bitStringOffset{ 2 };

		public:
			struct Header
			{
				uint8_t paddingBits;
				uint8_t zero : 1;
				uint8_t payloadType : 7;
				uint8_t bitString[maxBitStringSize];
			};

		public:
			static const FeedbackPs::MessageType messageType{ FeedbackPs::MessageType::RPSI };

		public:
			explicit FeedbackPsRpsiItem(Header* header);
			explicit FeedbackPsRpsiItem(FeedbackPsRpsiItem* item) : header(item->header)
			{
			}
			FeedbackPsRpsiItem(uint8_t payloadType, uint8_t* bitString, size_t length);
			~FeedbackPsRpsiItem() override = default;

			bool IsCorrect() const
			{
				return this->isCorrect;
			}
			uint8_t GetPayloadType() const
			{
				return this->header->payloadType;
			}
			uint8_t* GetBitString() const
			{
				return this->header->bitString;
			}
			size_t GetLength() const
			{
				return this->length;
			}

			/* Virtual methods inherited from FeedbackItem. */
		public:
			void Dump() const override;
			size_t Serialize(uint8_t* buffer) override;
			size_t GetSize() const override
			{
				return sizeof(Header);
			}

		private:
			Header* header{ nullptr };
			size_t length{ 0 };
		};

		// Rpsi packet declaration.
		using FeedbackPsRpsiPacket = FeedbackPsItemsPacket<FeedbackPsRpsiItem>;
	} // namespace RTCP
} // namespace RTC

#endif
<commit_msg>FeedbackPsRpsi.hpp: remove unused bitStringOffset const<commit_after>#ifndef MS_RTC_RTCP_FEEDBACK_PS_RPSI_HPP
#define MS_RTC_RTCP_FEEDBACK_PS_RPSI_HPP

#include "common.hpp"
#include "RTC/RTCP/FeedbackPs.hpp"

/* RFC 4585
 * Reference Picture Selection Indication (RPSI)
 *

   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |      PB       |
                  |0| Payload Type|
                                  |    Native RPSI bit string     |
  |   defined per codec          ...                | Padding (0) |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 */

namespace RTC
{
	namespace RTCP
	{
		class FeedbackPsRpsiItem : public FeedbackItem
		{
			const static size_t maxBitStringSize{ 6 };

		public:
			struct Header
			{
				uint8_t paddingBits;
				uint8_t zero : 1;
				uint8_t payloadType : 7;
				uint8_t bitString[maxBitStringSize];
			};

		public:
			static const FeedbackPs::MessageType messageType{ FeedbackPs::MessageType::RPSI };

		public:
			explicit FeedbackPsRpsiItem(Header* header);
			explicit FeedbackPsRpsiItem(FeedbackPsRpsiItem* item) : header(item->header)
			{
			}
			FeedbackPsRpsiItem(uint8_t payloadType, uint8_t* bitString, size_t length);
			~FeedbackPsRpsiItem() override = default;

			bool IsCorrect() const
			{
				return this->isCorrect;
			}
			uint8_t GetPayloadType() const
			{
				return this->header->payloadType;
			}
			uint8_t* GetBitString() const
			{
				return this->header->bitString;
			}
			size_t GetLength() const
			{
				return this->length;
			}

			/* Virtual methods inherited from FeedbackItem. */
		public:
			void Dump() const override;
			size_t Serialize(uint8_t* buffer) override;
			size_t GetSize() const override
			{
				return sizeof(Header);
			}

		private:
			Header* header{ nullptr };
			size_t length{ 0 };
		};

		// Rpsi packet declaration.
		using FeedbackPsRpsiPacket = FeedbackPsItemsPacket<FeedbackPsRpsiItem>;
	} // namespace RTCP
} // namespace RTC

#endif
<|endoftext|>


<commit_before>// (C) 2014 Arek Olek

#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/adjacency_matrix.hpp>

#include <omp.h>

#include "bfs.hpp"
#include "dfs.hpp"
#include "fifodfs.hpp"
#include "fivethree.hpp"
#include "lost.hpp"
#include "rdfs.hpp"
#include "random.hpp"
#include "ilst.hpp"
#include "greedy.hpp"

#include "test_suite.hpp"

#include "debug.hpp"
#include "graph.hpp"
#include "options.hpp"
#include "range.hpp"
#include "timing.hpp"

boost::adjacency_matrix<boost::undirectedS> typedef amatrix;
boost::adjacency_list<boost::hash_setS, boost::vecS, boost::undirectedS> typedef alist;

template<class Graph, class Tree>
std::function<Tree(Graph&)> make_construction(std::string name) {
  if (name == "bfs")
    return bfs_tree<Graph, Tree> ;
  if (name == "dfs")
    return dfs_tree<Graph, Tree> ;
  if (name == "rdfs")
    return rdfs_tree<Graph, Tree> ;
  if (name == "rdfs50")
    return rdfs_best_tree<Graph, Tree> ;
  if (name == "fifo")
    return fifo_dfs_tree<Graph, Tree> ;
  if (name == "random")
    return random_tree<Graph, Tree> ;
  if (name == "wilson")
    return wilson_tree<Graph, Tree> ;
  if (name == "greedy")
    return greedy_tree<Graph, Tree> ;
  if (name == "ilst")
    return ilst<Graph, Tree> ;
  if (name == "5/3")
    return five_three_tree<Graph, Tree> ;
  throw std::invalid_argument("Unknown construction method: " + name);
}

template<class Graph>
std::function<unsigned(Graph&)> make_upper(std::string name) {
  if (name == "5/3") {
    return [](const Graph& G) {
      return 5*(num_vertices(G)-3)/6;
    };
  }
  return upper_bound<Graph> ;
}

template <class Graph, class Tree, class Suite, class Strings>
void run(Suite& suite, Strings const & constructions, Strings const & improvements, bool scratch) {
  #pragma omp parallel
  {
    auto id = omp_get_thread_num();
    double elapsed_c, elapsed_i;
    timing timer;
    #pragma omp for schedule(dynamic) nowait
    for(uint i = 0; i < suite.size(); ++i) {
      std::stringstream buffer;
      auto trial = suite.get(i);
      auto G = std::get<0>(trial);
      if(!is_connected(G)) continue;

      for(auto cname : constructions) {
        auto construct = make_construction<Graph, Tree>(cname);
        auto upper = make_upper<Graph>(cname);
        timer.start();
        auto T = construct(G);
        elapsed_c = timer.stop();

        assert(num_edges(T) == num_vertices(T)-1);

        const auto tree(T);

        for(auto iname : improvements) {
          if(scratch) T = tree;

          auto improve = make_improvement<Graph, Tree>(iname);
          timer.start();
          auto rules = improve(G, T);
          elapsed_i = timer.stop();

//  1    2       3      4       5      6         7      8      9             10           11        12     13     14     15
//  run  thread  model  degree  param  vertices  edges  upper  construction  improvement  internal  ctime  itime  steps  rules
          buffer
            << i << '\t'
            << id << '\t'
            << suite.type() << '\t'
            << std::get<1>(trial) << '\t'
            << std::get<2>(trial) << '\t'
            << num_vertices(G) << '\t'
            << num_edges(G) << '\t'
            << upper(G) << '\t'
            << cname << '\t'
            << iname << '\t'
            << num_internal(T) << '\t'
            << elapsed_c << '\t'
            << elapsed_i << '\t'
            << sum(rules) << '\t'
            << join(rules, "-") << '\t'
            << std::endl;
            ;
          //show("graph" + std::to_string(i) + ".dot", G, T);

          if(!scratch) elapsed_c += elapsed_i;
        }
      }
      #pragma omp critical
      std::cout << buffer.str() << std::flush;
    }
  }
}

template <class Graph, class Tree, class Sizes, class Params, class Strings>
void run(std::string t, unsigned z, Sizes sizes, Params params,
         Strings const & constructions, Strings const & improvements, bool scratch) {
  if (t.find(".xml") != std::string::npos) {
    //real_suite<Graph> suite(t, z);
    //run<Graph, Tree>(suite, constructions, improvements, scratch);
  } else if (t.find('.') != std::string::npos) {
    //file_suite<Graph> suite(t);
    //run<Graph, Tree>(suite, constructions, improvements, scratch);
  } else {
    for (auto n : sizes) {
      for (auto p : params) {
        test_suite<Graph> suite(t, z, n, p);
        run<Graph, Tree>(suite, constructions, improvements, scratch);
      }
    }
  }
}

int main(int argc, char** argv){
  using std::string;
  using std::vector;

  std::ios_base::sync_with_stdio(0);

  options opt(argc, argv);
  auto z = opt.get<int>("-z", 1);
  auto sizes = opt.getList<int>("-n", {100});
  auto tests = opt.getList<string>("-t", {"gnp+mst"});
  auto degrees = opt.getList<float>("-d", { 3. });
  auto constructions = opt.getList<string>("-c", {"bfs", "dfs", "rdfs", "fifo", "rdfs50", "ilst", "random"});
  auto improvements = opt.getList<string>("-i", {"none", "prieto", "lost-light", "lost", "lost-ex"});
  auto scratch = opt.has("--scratch");

  for(auto t : tests)
    run<alist, alist>(t, z, sizes, degrees, constructions, improvements, scratch);

  return 0;
}
<commit_msg>add other graph representations<commit_after>// (C) 2014 Arek Olek

#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/adjacency_matrix.hpp>

#include <omp.h>

#include "bfs.hpp"
#include "dfs.hpp"
#include "fifodfs.hpp"
#include "fivethree.hpp"
#include "lost.hpp"
#include "rdfs.hpp"
#include "random.hpp"
#include "ilst.hpp"
#include "greedy.hpp"

#include "test_suite.hpp"

#include "debug.hpp"
#include "graph.hpp"
#include "options.hpp"
#include "range.hpp"
#include "timing.hpp"

boost::adjacency_matrix<boost::undirectedS> typedef amatrix;
boost::adjacency_list<boost::hash_setS, boost::vecS, boost::undirectedS> typedef ahash;
boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS> typedef alist;
boost::adjacency_list<boost::setS, boost::vecS, boost::undirectedS> typedef aset;
boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> typedef avec;

template<class Graph, class Tree>
std::function<Tree(Graph&)> make_construction(std::string name) {
  if (name == "bfs")
    return bfs_tree<Graph, Tree> ;
  if (name == "dfs")
    return dfs_tree<Graph, Tree> ;
  if (name == "rdfs")
    return rdfs_tree<Graph, Tree> ;
  if (name == "rdfs50")
    return rdfs_best_tree<Graph, Tree> ;
  if (name == "fifo")
    return fifo_dfs_tree<Graph, Tree> ;
  if (name == "random")
    return random_tree<Graph, Tree> ;
  if (name == "wilson")
    return wilson_tree<Graph, Tree> ;
  if (name == "greedy")
    return greedy_tree<Graph, Tree> ;
  if (name == "ilst")
    return ilst<Graph, Tree> ;
  if (name == "5/3")
    return five_three_tree<Graph, Tree> ;
  throw std::invalid_argument("Unknown construction method: " + name);
}

template<class Graph>
std::function<unsigned(Graph&)> make_upper(std::string name) {
  if (name == "5/3") {
    return [](const Graph& G) {
      return 5*(num_vertices(G)-3)/6;
    };
  }
  return upper_bound<Graph> ;
}

template <class Graph, class Tree, class Suite, class Strings>
void run(Suite& suite, Strings const & constructions, Strings const & improvements, bool scratch) {
  #pragma omp parallel
  {
    auto id = omp_get_thread_num();
    double elapsed_c, elapsed_i;
    timing timer;
    #pragma omp for schedule(dynamic) nowait
    for(uint i = 0; i < suite.size(); ++i) {
      std::stringstream buffer;
      auto trial = suite.get(i);
      auto G = std::get<0>(trial);
      if(!is_connected(G)) continue;

      for(auto cname : constructions) {
        auto construct = make_construction<Graph, Tree>(cname);
        auto upper = make_upper<Graph>(cname);
        timer.start();
        auto T = construct(G);
        elapsed_c = timer.stop();

        assert(num_edges(T) == num_vertices(T)-1);

        const auto tree(T);

        for(auto iname : improvements) {
          if(scratch) T = tree;

          auto improve = make_improvement<Graph, Tree>(iname);
          timer.start();
          auto rules = improve(G, T);
          elapsed_i = timer.stop();

//  1    2       3      4       5      6         7      8      9             10           11        12     13     14     15
//  run  thread  model  degree  param  vertices  edges  upper  construction  improvement  internal  ctime  itime  steps  rules
          buffer
            << i << '\t'
            << id << '\t'
            << suite.type() << '\t'
            << std::get<1>(trial) << '\t'
            << std::get<2>(trial) << '\t'
            << num_vertices(G) << '\t'
            << num_edges(G) << '\t'
            << upper(G) << '\t'
            << cname << '\t'
            << iname << '\t'
            << num_internal(T) << '\t'
            << elapsed_c << '\t'
            << elapsed_i << '\t'
            << sum(rules) << '\t'
            << join(rules, "-") << '\t'
            << std::endl;
            ;
          //show("graph" + std::to_string(i) + ".dot", G, T);

          if(!scratch) elapsed_c += elapsed_i;
        }
      }
      #pragma omp critical
      std::cout << buffer.str() << std::flush;
    }
  }
}

template <class Graph, class Tree, class Sizes, class Params, class Strings>
void run(std::string t, unsigned z, Sizes sizes, Params params,
         Strings const & constructions, Strings const & improvements, bool scratch) {
  if (t.find(".xml") != std::string::npos) {
    //real_suite<Graph> suite(t, z);
    //run<Graph, Tree>(suite, constructions, improvements, scratch);
  } else if (t.find('.') != std::string::npos) {
    //file_suite<Graph> suite(t);
    //run<Graph, Tree>(suite, constructions, improvements, scratch);
  } else {
    for (auto n : sizes) {
      for (auto p : params) {
        test_suite<Graph> suite(t, z, n, p);
        run<Graph, Tree>(suite, constructions, improvements, scratch);
      }
    }
  }
}

int main(int argc, char** argv){
  using std::string;
  using std::vector;

  std::ios_base::sync_with_stdio(0);

  options opt(argc, argv);
  auto z = opt.get<int>("-z", 1);
  auto sizes = opt.getList<int>("-n", {100});
  auto tests = opt.getList<string>("-t", {"gnp+mst"});
  auto degrees = opt.getList<float>("-d", { 3. });
  auto constructions = opt.getList<string>("-c", {"bfs", "dfs", "rdfs", "fifo", "rdfs50", "ilst", "random"});
  auto improvements = opt.getList<string>("-i", {"none", "prieto", "lost-light", "lost", "lost-ex"});
  auto scratch = opt.has("--scratch");

  for(auto t : tests)
    run<alist, alist>(t, z, sizes, degrees, constructions, improvements, scratch);

  return 0;
}
<|endoftext|>


<commit_before>// (C) 2014 Arek Olek

#include <functional>
#include <iostream>
#include <vector>

#include <boost/graph/adjacency_list.hpp>

#include "bfs.hpp"
#include "dfs.hpp"
#include "rdfs.hpp"
#include "lost.hpp"

#include "debug.hpp"
#include "options.hpp"
#include "timing.hpp"
#include "range.hpp"

#include "test_suite.hpp"

using namespace std;

boost::property<boost::edge_color_t,
  boost::default_color_type>            typedef color;
boost::adjacency_list<
  boost::hash_setS, boost::vecS, boost::undirectedS,
  boost::no_property, color>            typedef graph;

template <class Graph>
double eval(Graph const & T) {
  int n = num_vertices(T) - 2;
  int internal = 0;
  for(auto v : range(vertices(T)))
    internal += degree(v, T) > 1;
  return 100 * internal / (double)n;
}

template <class Graph>
float average_degree(Graph const & G) {
  float sum = 0;
  for(auto v : range(vertices(G)))
    sum += degree(v, G);
  return sum / num_vertices(G);
}

function<graph(graph&)> typedef solution;

class dummy {
public:
  template<class Graph>
  int operator()(Graph& G, Graph& T) {
    return 0;
  }
};

template <class Improvement>
void run(int z, int n, vector<float> ps, vector<string> name,
  vector<solution> algo, Improvement improve, string iname) {
  timing timer;

  cout << endl << iname << endl;

  cout << "\t\t";
  for(auto n : name)
    cout << n << "\t\t\t\t\t";
  cout << "\np\tE[deg]";
  for(auto n : name)
    cout << "\tmin\tE[|I|]\tmax\ttime\tsteps";
  cout << endl;

  for(auto p : ps) {
    test_suite<graph> suite(z, n, p);

    double degree = 0;
    vector<double>
      steps(algo.size(), 0),
      quality(algo.size(), 0),
      time(algo.size(), 0);
    vector<int>
      minimum(algo.size(), n),
      maximum(algo.size(), 0);

    for(auto G : suite) {
      degree += average_degree(G);

      for(unsigned i = 0; i < algo.size(); ++i) {
        timer.start();
        auto T = algo[i](G);
        steps[i] += improve(G, T);
        time[i] += timer.stop();
        auto q = eval(T);
        quality[i] += q;
        minimum[i] = min(minimum[i], q);
        maximum[i] = max(maximum[i], q);
        //show("graph" + to_string(i) + ".dot", G, T);
      }
    }

    int count = suite.size();
    cout << p << '\t' << degree / count;

    for(unsigned i = 0; i < algo.size(); ++i)
      cout
        << '\t' << minimum[i]
        << '\t' << quality[i] / count
        << '\t' << maximum[i]
        << '\t' << time[i] / count
        << '\t' << steps[i] / count
        ;

    cout << endl;
  }
}

int main(int argc, char** argv){
  ios_base::sync_with_stdio(0);

  options opt(argc, argv);
  int z = opt.get<int>("-z", 1);
  int n = opt.get<int>("-n", 5);
  float p = opt.get<float>("-p", -1);
  string a = opt.get<string>("-a");

  vector<float> ps {0.0001, 0.0005, 0.001, 0.003, 0.005, 0.008,
    0.01, 0.03, 0.05, 0.08,
    0.1, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45,
    0.5, 0.55, 0.6, 0.7, 0.8, 0.9, 0.95, 0.99};
  //~ vector<float> ps {0.0002, 0.0105, 0.021, 0.0312, 0.0415, 0.0518, 0.062, 0.0725, 0.0827};
  if(p >= 0 && p <= 1) {
    ps.clear();
    ps.push_back(p);
  }

  vector<string> name {/*"bfs", */"dfs", "rdfs"};
  vector<solution> algo {/*bfs_tree<graph>, */dfs_tree<graph>, rdfs_tree<graph>};

  run(z, n, ps, name, algo, dummy(), "no improvement");

  run(z, n, ps, name, algo, prieto(), "prieto");

  run(z, n, ps, name, algo, lost_light(), "lost-light");

  return 0;
}
<commit_msg>diable prieto measurement<commit_after>// (C) 2014 Arek Olek

#include <functional>
#include <iostream>
#include <vector>

#include <boost/graph/adjacency_list.hpp>

#include "bfs.hpp"
#include "dfs.hpp"
#include "rdfs.hpp"
#include "lost.hpp"

#include "debug.hpp"
#include "options.hpp"
#include "timing.hpp"
#include "range.hpp"

#include "test_suite.hpp"

using namespace std;

boost::property<boost::edge_color_t,
  boost::default_color_type>            typedef color;
boost::adjacency_list<
  boost::hash_setS, boost::vecS, boost::undirectedS,
  boost::no_property, color>            typedef graph;

template <class Graph>
double eval(Graph const & T) {
  int n = num_vertices(T) - 2;
  int internal = 0;
  for(auto v : range(vertices(T)))
    internal += degree(v, T) > 1;
  return 100 * internal / (double)n;
}

template <class Graph>
float average_degree(Graph const & G) {
  float sum = 0;
  for(auto v : range(vertices(G)))
    sum += degree(v, G);
  return sum / num_vertices(G);
}

function<graph(graph&)> typedef solution;

class dummy {
public:
  template<class Graph>
  int operator()(Graph& G, Graph& T) {
    return 0;
  }
};

template <class Improvement>
void run(int z, int n, vector<float> ps, vector<string> name,
  vector<solution> algo, Improvement improve, string iname) {
  timing timer;

  cout << endl << iname << endl;

  cout << "\t\t";
  for(auto n : name)
    cout << n << "\t\t\t\t\t";
  cout << "\np\tE[deg]";
  for(auto n : name)
    cout << "\tmin\tE[|I|]\tmax\ttime\tsteps";
  cout << endl;

  for(auto p : ps) {
    test_suite<graph> suite(z, n, p);

    double degree = 0;
    vector<double>
      steps(algo.size(), 0),
      quality(algo.size(), 0),
      time(algo.size(), 0);
    vector<int>
      minimum(algo.size(), n),
      maximum(algo.size(), 0);

    for(auto G : suite) {
      degree += average_degree(G);

      for(unsigned i = 0; i < algo.size(); ++i) {
        timer.start();
        auto T = algo[i](G);
        steps[i] += improve(G, T);
        time[i] += timer.stop();
        auto q = eval(T);
        quality[i] += q;
        minimum[i] = min(minimum[i], q);
        maximum[i] = max(maximum[i], q);
        //show("graph" + to_string(i) + ".dot", G, T);
      }
    }

    int count = suite.size();
    cout << p << '\t' << degree / count;

    for(unsigned i = 0; i < algo.size(); ++i)
      cout
        << '\t' << minimum[i]
        << '\t' << quality[i] / count
        << '\t' << maximum[i]
        << '\t' << time[i] / count
        << '\t' << steps[i] / count
        ;

    cout << endl;
  }
}

int main(int argc, char** argv){
  ios_base::sync_with_stdio(0);

  options opt(argc, argv);
  int z = opt.get<int>("-z", 1);
  int n = opt.get<int>("-n", 5);
  float p = opt.get<float>("-p", -1);
  string a = opt.get<string>("-a");

  vector<float> ps {0.0001, 0.0005, 0.001, 0.003, 0.005, 0.008,
    0.01, 0.03, 0.05, 0.08,
    0.1, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45,
    0.5, 0.55, 0.6, 0.7, 0.8, 0.9, 0.95, 0.99};
  //~ vector<float> ps {0.0002, 0.0105, 0.021, 0.0312, 0.0415, 0.0518, 0.062, 0.0725, 0.0827};
  if(p >= 0 && p <= 1) {
    ps.clear();
    ps.push_back(p);
  }

  vector<string> name {/*"bfs", */"dfs", "rdfs"};
  vector<solution> algo {/*bfs_tree<graph>, */dfs_tree<graph>, rdfs_tree<graph>};

  run(z, n, ps, name, algo, dummy(), "no improvement");

  //~ run(z, n, ps, name, algo, prieto(), "prieto");

  run(z, n, ps, name, algo, lost_light(), "lost-light");

  return 0;
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: apiaccessobj.cxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-16 14:53:45 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_configmgr.hxx"
#include <stdio.h>
#include "apiaccessobj.hxx"

#include "apiserviceinfo.hxx"
#include "confsvccomponent.hxx"

namespace configmgr
{
//-----------------------------------------------------------------------------
    namespace configapi
    {
//========================================================================
//= service infos
//========================================================================
/*
const AsciiServiceName c_aUserContainerServices[] =
{
    "com.sun.star.configuration.UserAdministration",
    "com.sun.star.configuration.ConfigurationContainer",
    "com.sun.star.configuration.ConfigurationUpdateAccess",
    "com.sun.star.configuration.ConfigurationAccess",
    NULL
};
const AsciiServiceName c_aContainerServices[] =
{
    "com.sun.star.configuration.ConfigurationContainer",
    "com.sun.star.configuration.ConfigurationUpdateAccess",
    "com.sun.star.configuration.ConfigurationAccess",
    NULL
};
const AsciiServiceName c_aUpdateServices[] =
{
    "com.sun.star.configuration.ConfigurationUpdateAccess",
    "com.sun.star.configuration.ConfigurationAccess",
    NULL
};

const AsciiServiceName c_aAccessServices[] =
{
    "com.sun.star.configuration.ConfigurationAccess",
    NULL
};

const AsciiServiceName c_aNoServices[] =
{
    NULL
};
//-----------------------------------------------------------------------------

ServiceInfo const aInnerGroupInfoSI =
{
    "com.sun.star.configuration.configmgr.OInnerGroupInfoAccess",
    c_aNoServices
};
ServiceInfo const aInnerGroupUpdateSI =
{
    "com.sun.star.configuration.configmgr.OInnerGroupUpdateAccess",
    c_aNoServices
};
ServiceInfo const aInnerSetInfoSI =
{
    "com.sun.star.configuration.configmgr.OInnerSetInfoAccess",
    c_aNoServices
};
ServiceInfo const aInnerTreeSetSI =
{
    "com.sun.star.configuration.configmgr.OInnerTreeSetUpdateAccess",
    c_aNoServices
};
ServiceInfo const aInnerValueSetSI =
{
    "com.sun.star.configuration.configmgr.OInnerValueSetUpdateAccess",
    c_aNoServices
};
//-----------------------------------------------------------------------------

ServiceInfo const aSetElementGroupInfoSI =
{
    "com.sun.star.configuration.configmgr.OSetElementGroupInfoAccess",
    c_aAccessServices
};
ServiceInfo const aSetElementGroupUpdateSI =
{
    "com.sun.star.configuration.configmgr.OSetElementGroupUpdateAccess",
    c_aUpdateServices
};
ServiceInfo const aSetElementSetInfoSI =
{
    "com.sun.star.configuration.configmgr.OSetElementSetInfoAccess",
    c_aAccessServices
};
ServiceInfo const aSetElementTreeSetSI =
{
    "com.sun.star.configuration.configmgr.OSetElementTreeSetUpdateAccess",
    c_aContainerServices
};
ServiceInfo const aSetElementValueSetSI =
{
    "com.sun.star.configuration.configmgr.OSetElementValueSetUpdateAccess",
    c_aContainerServices
};
//-----------------------------------------------------------------------------

ServiceInfo const aRootElementGroupInfoSI =
{
    "com.sun.star.configuration.configmgr.ORootElementGroupInfoAccess",
    c_aAccessServices
};
ServiceInfo const aRootElementGroupUpdateSI =
{
    "com.sun.star.configuration.configmgr.ORootElementGroupUpdateAccess",
    c_aUpdateServices
};
ServiceInfo const aRootElementSetInfoSI =
{
    "com.sun.star.configuration.configmgr.ORootElementSetInfoAccess",
    c_aAccessServices
};
ServiceInfo const aRootElementTreeSetUpdateSI =
{
    "com.sun.star.configuration.configmgr.ORootElementTreeSetUpdateAccess",
    c_aContainerServices
};
ServiceInfo const aRootElementValueSetUpdateSI =
{
    "com.sun.star.configuration.configmgr.ORootElementValueSetUpdateAccess",
    c_aContainerServices
};
//-----------------------------------------------------------------------------

ServiceInfo const aRootElementReadAccessSI =
{
    "com.sun.star.configuration.configmgr.ORootElementReadAccess",
    c_aAccessServices
};
ServiceInfo const aRootElementUpdateAccessSI =
{
    "com.sun.star.configuration.configmgr.ORootElementUpdateAccess",
    c_aUpdateServices
};
ServiceInfo const aRootElementAdminAccessSI =
{
    "com.sun.star.configuration.configmgr.ORootElementUserAdminAccess",
    c_aUserContainerServices
};*/

//========================================================================
//= service info static members
//========================================================================

//-----------------------------------------------------------------------------
// Inner Elements
//-----------------------------------------------------------------------------

template <>
ServiceImplementationInfo const *
const OInnerElement<NodeGroupInfoAccess>::s_pServiceInfo = &aInnerGroupInfoSI;

template <>
ServiceImplementationInfo const *
const OInnerElement<NodeGroupAccess>::s_pServiceInfo = &aInnerGroupUpdateSI;

template <>
ServiceImplementationInfo const *
const OInnerElement<NodeSetInfoAccess>::s_pServiceInfo = &aInnerSetInfoSI;

template <>
ServiceImplementationInfo const *
const OInnerElement<NodeTreeSetAccess>::s_pServiceInfo = &aInnerTreeSetSI;

template <>
ServiceImplementationInfo const *
const OInnerElement<NodeValueSetAccess>::s_pServiceInfo = &aInnerValueSetSI;

//-----------------------------------------------------------------------------
// Set Elements
//-----------------------------------------------------------------------------

template <>
ServiceImplementationInfo const *
const OSetElement<NodeGroupInfoAccess>::s_pServiceInfo = &aSetElementGroupInfoSI;

template <>
ServiceImplementationInfo const *
const OSetElement<NodeGroupAccess>::s_pServiceInfo = &aSetElementGroupUpdateSI;

template <>
ServiceImplementationInfo const *
const OSetElement<NodeSetInfoAccess>::s_pServiceInfo = &aSetElementSetInfoSI;

template <>
ServiceImplementationInfo const *
const OSetElement<NodeTreeSetAccess>::s_pServiceInfo = &aSetElementTreeSetSI;

template <>
ServiceImplementationInfo const *
const OSetElement<NodeValueSetAccess>::s_pServiceInfo = &aSetElementValueSetSI;

//-----------------------------------------------------------------------------
// Root Elements
//-----------------------------------------------------------------------------

template <>
ServiceImplementationInfo const *
const OReadRootElement<NodeGroupInfoAccess>::s_pServiceInfo = &aRootElementGroupInfoSI;

template <>
ServiceImplementationInfo const *
const OUpdateRootElement<NodeGroupAccess>::s_pServiceInfo = &aRootElementGroupUpdateSI;

template <>
ServiceImplementationInfo const *
const OReadRootElement<NodeSetInfoAccess>::s_pServiceInfo = &aRootElementSetInfoSI;

template <>
ServiceImplementationInfo const *
const OUpdateRootElement<NodeTreeSetAccess>::s_pServiceInfo = &aRootElementTreeSetUpdateSI;

template <>
ServiceImplementationInfo const *
const OUpdateRootElement<NodeValueSetAccess>::s_pServiceInfo = &aRootElementValueSetUpdateSI;

//========================================================================
//= Instantiations
//========================================================================
/*
//-----------------------------------------------------------------------------
// Inner Elements
//-----------------------------------------------------------------------------

template class OInnerElement<NodeGroupInfoAccess>;  // OInnerGroupInfoAccess
template class OInnerElement<NodeGroupAccess>;      // OInnerGroupUpdateAccess
template class OInnerElement<NodeSetInfoAccess>;    // OInnerSetInfoAccess
template class OInnerElement<NodeTreeSetAccess>;    // OInnerTreeSetUpdateAccess
template class OInnerElement<NodeValueSetAccess>;   // OInnerValueSetUpdateAccess

//-----------------------------------------------------------------------------
// Set Elements
//-----------------------------------------------------------------------------
template class OSetElement<NodeGroupInfoAccess>;    // OSetElementGroupInfoAccess
template class OSetElement<NodeGroupAccess>;        // OSetElementGroupUpdateAccess
template class OSetElement<NodeSetInfoAccess>;      // OSetElementSetInfoAccess
template class OSetElement<NodeTreeSetAccess>;      // OSetElementTreeSetUpdateAccess
template class OSetElement<NodeValueSetAccess>;     // OSetElementValueSetUpdateAccess

//-----------------------------------------------------------------------------
// Root Elements
//-----------------------------------------------------------------------------

template class OReadRootElement<NodeGroupInfoAccess>;   // ORootElementGroupInfoAccess
template class OUpdateRootElement<NodeGroupAccess>;     // ORootElementGroupUpdateAccess
template class OReadRootElement<NodeSetInfoAccess>;     // ORootElementSetInfoAccess
template class OUpdateRootElement<NodeTreeSetAccess>;   // ORootElementTreeSetUpdateAccess
template class OUpdateRootElement<NodeValueSetAccess>;  // ORootElementValueSetUpdateAccess
*/
//-----------------------------------------------------------------------------
    }
}
<commit_msg>INTEGRATION: CWS changefileheader (1.6.72); FILE MERGED 2008/03/31 12:22:35 rt 1.6.72.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: apiaccessobj.cxx,v $
 * $Revision: 1.7 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_configmgr.hxx"
#include <stdio.h>
#include "apiaccessobj.hxx"

#include "apiserviceinfo.hxx"
#include "confsvccomponent.hxx"

namespace configmgr
{
//-----------------------------------------------------------------------------
    namespace configapi
    {
//========================================================================
//= service infos
//========================================================================
/*
const AsciiServiceName c_aUserContainerServices[] =
{
    "com.sun.star.configuration.UserAdministration",
    "com.sun.star.configuration.ConfigurationContainer",
    "com.sun.star.configuration.ConfigurationUpdateAccess",
    "com.sun.star.configuration.ConfigurationAccess",
    NULL
};
const AsciiServiceName c_aContainerServices[] =
{
    "com.sun.star.configuration.ConfigurationContainer",
    "com.sun.star.configuration.ConfigurationUpdateAccess",
    "com.sun.star.configuration.ConfigurationAccess",
    NULL
};
const AsciiServiceName c_aUpdateServices[] =
{
    "com.sun.star.configuration.ConfigurationUpdateAccess",
    "com.sun.star.configuration.ConfigurationAccess",
    NULL
};

const AsciiServiceName c_aAccessServices[] =
{
    "com.sun.star.configuration.ConfigurationAccess",
    NULL
};

const AsciiServiceName c_aNoServices[] =
{
    NULL
};
//-----------------------------------------------------------------------------

ServiceInfo const aInnerGroupInfoSI =
{
    "com.sun.star.configuration.configmgr.OInnerGroupInfoAccess",
    c_aNoServices
};
ServiceInfo const aInnerGroupUpdateSI =
{
    "com.sun.star.configuration.configmgr.OInnerGroupUpdateAccess",
    c_aNoServices
};
ServiceInfo const aInnerSetInfoSI =
{
    "com.sun.star.configuration.configmgr.OInnerSetInfoAccess",
    c_aNoServices
};
ServiceInfo const aInnerTreeSetSI =
{
    "com.sun.star.configuration.configmgr.OInnerTreeSetUpdateAccess",
    c_aNoServices
};
ServiceInfo const aInnerValueSetSI =
{
    "com.sun.star.configuration.configmgr.OInnerValueSetUpdateAccess",
    c_aNoServices
};
//-----------------------------------------------------------------------------

ServiceInfo const aSetElementGroupInfoSI =
{
    "com.sun.star.configuration.configmgr.OSetElementGroupInfoAccess",
    c_aAccessServices
};
ServiceInfo const aSetElementGroupUpdateSI =
{
    "com.sun.star.configuration.configmgr.OSetElementGroupUpdateAccess",
    c_aUpdateServices
};
ServiceInfo const aSetElementSetInfoSI =
{
    "com.sun.star.configuration.configmgr.OSetElementSetInfoAccess",
    c_aAccessServices
};
ServiceInfo const aSetElementTreeSetSI =
{
    "com.sun.star.configuration.configmgr.OSetElementTreeSetUpdateAccess",
    c_aContainerServices
};
ServiceInfo const aSetElementValueSetSI =
{
    "com.sun.star.configuration.configmgr.OSetElementValueSetUpdateAccess",
    c_aContainerServices
};
//-----------------------------------------------------------------------------

ServiceInfo const aRootElementGroupInfoSI =
{
    "com.sun.star.configuration.configmgr.ORootElementGroupInfoAccess",
    c_aAccessServices
};
ServiceInfo const aRootElementGroupUpdateSI =
{
    "com.sun.star.configuration.configmgr.ORootElementGroupUpdateAccess",
    c_aUpdateServices
};
ServiceInfo const aRootElementSetInfoSI =
{
    "com.sun.star.configuration.configmgr.ORootElementSetInfoAccess",
    c_aAccessServices
};
ServiceInfo const aRootElementTreeSetUpdateSI =
{
    "com.sun.star.configuration.configmgr.ORootElementTreeSetUpdateAccess",
    c_aContainerServices
};
ServiceInfo const aRootElementValueSetUpdateSI =
{
    "com.sun.star.configuration.configmgr.ORootElementValueSetUpdateAccess",
    c_aContainerServices
};
//-----------------------------------------------------------------------------

ServiceInfo const aRootElementReadAccessSI =
{
    "com.sun.star.configuration.configmgr.ORootElementReadAccess",
    c_aAccessServices
};
ServiceInfo const aRootElementUpdateAccessSI =
{
    "com.sun.star.configuration.configmgr.ORootElementUpdateAccess",
    c_aUpdateServices
};
ServiceInfo const aRootElementAdminAccessSI =
{
    "com.sun.star.configuration.configmgr.ORootElementUserAdminAccess",
    c_aUserContainerServices
};*/

//========================================================================
//= service info static members
//========================================================================

//-----------------------------------------------------------------------------
// Inner Elements
//-----------------------------------------------------------------------------

template <>
ServiceImplementationInfo const *
const OInnerElement<NodeGroupInfoAccess>::s_pServiceInfo = &aInnerGroupInfoSI;

template <>
ServiceImplementationInfo const *
const OInnerElement<NodeGroupAccess>::s_pServiceInfo = &aInnerGroupUpdateSI;

template <>
ServiceImplementationInfo const *
const OInnerElement<NodeSetInfoAccess>::s_pServiceInfo = &aInnerSetInfoSI;

template <>
ServiceImplementationInfo const *
const OInnerElement<NodeTreeSetAccess>::s_pServiceInfo = &aInnerTreeSetSI;

template <>
ServiceImplementationInfo const *
const OInnerElement<NodeValueSetAccess>::s_pServiceInfo = &aInnerValueSetSI;

//-----------------------------------------------------------------------------
// Set Elements
//-----------------------------------------------------------------------------

template <>
ServiceImplementationInfo const *
const OSetElement<NodeGroupInfoAccess>::s_pServiceInfo = &aSetElementGroupInfoSI;

template <>
ServiceImplementationInfo const *
const OSetElement<NodeGroupAccess>::s_pServiceInfo = &aSetElementGroupUpdateSI;

template <>
ServiceImplementationInfo const *
const OSetElement<NodeSetInfoAccess>::s_pServiceInfo = &aSetElementSetInfoSI;

template <>
ServiceImplementationInfo const *
const OSetElement<NodeTreeSetAccess>::s_pServiceInfo = &aSetElementTreeSetSI;

template <>
ServiceImplementationInfo const *
const OSetElement<NodeValueSetAccess>::s_pServiceInfo = &aSetElementValueSetSI;

//-----------------------------------------------------------------------------
// Root Elements
//-----------------------------------------------------------------------------

template <>
ServiceImplementationInfo const *
const OReadRootElement<NodeGroupInfoAccess>::s_pServiceInfo = &aRootElementGroupInfoSI;

template <>
ServiceImplementationInfo const *
const OUpdateRootElement<NodeGroupAccess>::s_pServiceInfo = &aRootElementGroupUpdateSI;

template <>
ServiceImplementationInfo const *
const OReadRootElement<NodeSetInfoAccess>::s_pServiceInfo = &aRootElementSetInfoSI;

template <>
ServiceImplementationInfo const *
const OUpdateRootElement<NodeTreeSetAccess>::s_pServiceInfo = &aRootElementTreeSetUpdateSI;

template <>
ServiceImplementationInfo const *
const OUpdateRootElement<NodeValueSetAccess>::s_pServiceInfo = &aRootElementValueSetUpdateSI;

//========================================================================
//= Instantiations
//========================================================================
/*
//-----------------------------------------------------------------------------
// Inner Elements
//-----------------------------------------------------------------------------

template class OInnerElement<NodeGroupInfoAccess>;  // OInnerGroupInfoAccess
template class OInnerElement<NodeGroupAccess>;      // OInnerGroupUpdateAccess
template class OInnerElement<NodeSetInfoAccess>;    // OInnerSetInfoAccess
template class OInnerElement<NodeTreeSetAccess>;    // OInnerTreeSetUpdateAccess
template class OInnerElement<NodeValueSetAccess>;   // OInnerValueSetUpdateAccess

//-----------------------------------------------------------------------------
// Set Elements
//-----------------------------------------------------------------------------
template class OSetElement<NodeGroupInfoAccess>;    // OSetElementGroupInfoAccess
template class OSetElement<NodeGroupAccess>;        // OSetElementGroupUpdateAccess
template class OSetElement<NodeSetInfoAccess>;      // OSetElementSetInfoAccess
template class OSetElement<NodeTreeSetAccess>;      // OSetElementTreeSetUpdateAccess
template class OSetElement<NodeValueSetAccess>;     // OSetElementValueSetUpdateAccess

//-----------------------------------------------------------------------------
// Root Elements
//-----------------------------------------------------------------------------

template class OReadRootElement<NodeGroupInfoAccess>;   // ORootElementGroupInfoAccess
template class OUpdateRootElement<NodeGroupAccess>;     // ORootElementGroupUpdateAccess
template class OReadRootElement<NodeSetInfoAccess>;     // ORootElementSetInfoAccess
template class OUpdateRootElement<NodeTreeSetAccess>;   // ORootElementTreeSetUpdateAccess
template class OUpdateRootElement<NodeValueSetAccess>;  // ORootElementValueSetUpdateAccess
*/
//-----------------------------------------------------------------------------
    }
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: typeconverter.cxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: babak.mahbod $ $Date: 2000-09-21 20:17:23 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#include "typeconverter.hxx"

#ifndef _COM_SUN_STAR_SCRIPT_XTYPECONVERTER_HPP_
#include <com/sun/star/script/XTypeConverter.hpp>
#endif
#ifndef _COM_SUN_STAR_SCRIPT_FAILREASON_HPP_
#include <com/sun/star/script/FailReason.hpp>
#endif
#ifndef _COM_SUN_STAR_UNO_TYPE_HXX_
#include <com/sun/star/uno/Type.hxx>
#endif

#ifndef _TYPELIB_TYPEDESCRIPTION_HXX_
#include <typelib/typedescription.hxx>
#endif

#ifndef _RTL_USTRING_HXX_
#include <rtl/ustring.hxx>
#endif

//#include <stdio.h>

#ifndef _OSL_DIAGNOSE_H_
#include <osl/diagnose.h>
#endif

namespace staruno = ::com::sun::star::uno;
namespace starscript = ::com::sun::star::script;
namespace starlang = ::com::sun::star::lang;

namespace configmgr
{

//--------------------------------------------------------------------------------------------------
    rtl::OUString toString(const staruno::Reference< starscript::XTypeConverter >& xTypeConverter, const staruno::Any& rValue) throw( starscript::CannotConvertException )
    {
        rtl::OUString aRes;
        ::staruno::TypeClass aDestinationClass = rValue.getValueType().getTypeClass();

        switch (aDestinationClass)
        {
        case ::staruno::TypeClass_BOOLEAN:
        case ::staruno::TypeClass_CHAR:
        case ::staruno::TypeClass_BYTE:
        case ::staruno::TypeClass_SHORT:
        case ::staruno::TypeClass_LONG:
        case ::staruno::TypeClass_FLOAT:
        case ::staruno::TypeClass_DOUBLE:
            if (!xTypeConverter.is())
            {
                throw( starscript::CannotConvertException( ::rtl::OUString::createFromAscii("stardiv.script.Converter!"), ::staruno::Reference< ::staruno::XInterface > (),
                                                           aDestinationClass, starscript::FailReason::UNKNOWN, 0 ) );
            }
            xTypeConverter->convertToSimpleType(rValue, ::staruno::TypeClass_STRING) >>= aRes;
            break;
        case ::staruno::TypeClass_STRING:
            rValue >>= aRes;
            break;
        default:
            throw( starscript::CannotConvertException( ::rtl::OUString::createFromAscii("TYPE is not supported!"), staruno::Reference< ::staruno::XInterface > (),
                                                       aDestinationClass, starscript::FailReason::TYPE_NOT_SUPPORTED, 0 ) );

        }
        return aRes;
    }

    staruno::Any toAny(const staruno::Reference< starscript::XTypeConverter >& xTypeConverter, const ::rtl::OUString& _rValue,const staruno::TypeClass& _rTypeClass) throw( starscript::CannotConvertException )
    {
        staruno::Any aRes;
        try
        {
            xTypeConverter->convertToSimpleType(staruno::makeAny(_rValue), _rTypeClass) >>= aRes;
        }
        catch (starscript::CannotConvertException&)
        {
            OSL_ENSHURE(sal_False, "toAny : could not convert !");
        }
        catch (starlang::IllegalArgumentException&)
        {
            OSL_ENSHURE(sal_False, "toAny : could not convert !");
        }
        return aRes;
    }

    ::rtl::OUString toTypeName(const staruno::TypeClass& _rTypeClass)
    {
        ::rtl::OUString aRet;
        switch(_rTypeClass)
        {
        case staruno::TypeClass_BOOLEAN:  aRet = ::rtl::OUString::createFromAscii("boolean"); break;
        case staruno::TypeClass_SHORT:    aRet = ::rtl::OUString::createFromAscii("short"); break;
        case staruno::TypeClass_LONG:     aRet = ::rtl::OUString::createFromAscii("integer"); break;
        case staruno::TypeClass_HYPER:    aRet = ::rtl::OUString::createFromAscii("long"); break;
        case staruno::TypeClass_DOUBLE:   aRet = ::rtl::OUString::createFromAscii("double"); break;
        case staruno::TypeClass_STRING:   aRet = ::rtl::OUString::createFromAscii("string"); break;
        case staruno::TypeClass_SEQUENCE: aRet = ::rtl::OUString::createFromAscii("binary"); break;
        default:
        {
            ::rtl::OString aStr("Wrong typeclass! ");
            aStr += ::rtl::OString::valueOf((sal_Int32)_rTypeClass);
            OSL_ENSHURE(0,aStr.getStr());
        }
        }
        return aRet;
    }

    staruno::TypeClass toTypeClass(const ::rtl::OUString& _rType)
    {
        staruno::TypeClass aRet = staruno::TypeClass_VOID;

        if     (_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("boolean")))  aRet = staruno::TypeClass_BOOLEAN;
        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("short")))    aRet = staruno::TypeClass_SHORT;
        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("int")))      aRet = staruno::TypeClass_LONG;
        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("integer")))  aRet = staruno::TypeClass_LONG;
        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("long")))     aRet = staruno::TypeClass_HYPER;
        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("double")))   aRet = staruno::TypeClass_DOUBLE;
        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("string")))   aRet = staruno::TypeClass_STRING;
        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("binary")))   aRet = staruno::TypeClass_SEQUENCE;
        else
        {
            ::rtl::OString aStr("Wrong typeclass! ");
            aStr += rtl::OUStringToOString(_rType,RTL_TEXTENCODING_ASCII_US);
            OSL_ENSHURE(0,aStr.getStr());
        }

        return aRet;
    }

// *************************************************************************

    namespace
    {

        inline staruno::Type getBooleanType() { return ::getBooleanCppuType(); }

        inline staruno::Type getShortType()     { return ::getCppuType(static_cast<sal_Int16 const*>(0)); }
        inline staruno::Type getIntType()       { return ::getCppuType(static_cast<sal_Int32 const*>(0)); }
        inline staruno::Type getLongType()      { return ::getCppuType(static_cast<sal_Int64 const*>(0)); }

        inline staruno::Type getDoubleType()    { return ::getCppuType(static_cast<double const*>(0)); }

        inline staruno::Type getStringType()    { return ::getCppuType(static_cast<rtl::OUString const*>(0)); }

// *************************************************************************
/*
  ::rtl::OUString findXMLTypeName(const staruno::Type& _rType)
  {
  ::rtl::OUString aRet;
  switch(_rType.getTypeClass())
  {
  case staruno::TypeClass_BOOLEAN:
  OSL_ASSERT( _rType == getBooleanType() );
  aRet = ::rtl::OUString::createFromAscii("boolean");
  break;

  case staruno::TypeClass_SHORT:
  OSL_ASSERT( _rType == getShortType() );
  aRet = ::rtl::OUString::createFromAscii("short");
  break;

  case staruno::TypeClass_LONG:
  OSL_ASSERT( _rType == getIntType() );
  aRet = ::rtl::OUString::createFromAscii("int");
  break;

  case staruno::TypeClass_HYPER:
  OSL_ASSERT( _rType == getLongType() );
  Ret = ::rtl::OUString::createFromAscii("long");
  break;

  case staruno::TypeClass_DOUBLE:
  OSL_ASSERT( _rType == getDoubleType() );
  aRet = ::rtl::OUString::createFromAscii("double");
  break;

  case staruno::TypeClass_STRING:
  OSL_ASSERT( _rType == getStringType() );
  aRet = ::rtl::OUString::createFromAscii("string");
  break;

  case staruno::TypeClass_SEQUENCE:
  if ( _rType == getStringType() );
  aRet = ::rtl::OUString::createFromAscii("sequence");
  break;

  default:
  {
  ::rtl::OString aStr("Wrong typeclass! ");
  aStr += ::rtl::OString::valueOf((sal_Int32)_rTypeClass);
  OSL_ENSHURE(0,aStr.getStr());
  }
  }
  return aRet;
  }
 */
    } // unamed namespace
// *************************************************************************

    staruno::Type toType(const ::rtl::OUString& _rType)
    {
        staruno::Type aRet;

        if     (_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("boolean")))  aRet = getBooleanType();

        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("short")))    aRet = getShortType();
        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("int")))      aRet = getIntType();
        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("integer")))  aRet = getIntType();
        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("long")))     aRet = getLongType();

        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("double")))   aRet = getDoubleType();

        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("string")))   aRet = getStringType();
        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("binary")))   aRet = getBinaryType();
//  else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("sequence"))) aRet = staruno::TypeClass_SEQUENCE;
        else
        {
            ::rtl::OString aStr("Unknown type! ");
            aStr += rtl::OUStringToOString(_rType,RTL_TEXTENCODING_ASCII_US);
            OSL_ENSHURE(0,aStr.getStr());
        }

        return aRet;
    }
    staruno::Type toListType(const ::rtl::OUString& _rsElementType)
    {
        staruno::Type aRet;

        if     (_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("boolean")))
            aRet = ::getCppuType(static_cast<staruno::Sequence<sal_Bool> const*>(0));

        else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("short")))
            aRet = ::getCppuType(static_cast<staruno::Sequence<sal_Int16> const*>(0));

        else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("int")))
            aRet = ::getCppuType(static_cast<staruno::Sequence<sal_Int32> const*>(0));
        else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("integer")))
            aRet = ::getCppuType(static_cast<staruno::Sequence<sal_Int32> const*>(0));

        else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("long")))
            aRet = ::getCppuType(static_cast<staruno::Sequence<sal_Int64> const*>(0));

        else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("double")))
            aRet = ::getCppuType(static_cast<staruno::Sequence<double> const*>(0));

        else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("string")))
            aRet = ::getCppuType(static_cast<staruno::Sequence<rtl::OUString> const*>(0));

        else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("binary")))
            aRet = ::getCppuType(static_cast<staruno::Sequence<staruno::Sequence<sal_Int8> > const*>(0));

//  else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("sequence"))) aRet = staruno::TypeClass_SEQUENCE;
        else
        {
            ::rtl::OString aStr("Unknown type! ");
            aStr += rtl::OUStringToOString(_rsElementType,RTL_TEXTENCODING_ASCII_US);
            OSL_ENSHURE(0,aStr.getStr());
        }

        return aRet;
    }

    staruno::Type getSequenceElementType(staruno::Type const& rSequenceType)
    {
        OSL_ENSHURE(rSequenceType.getTypeClass() == staruno::TypeClass_SEQUENCE,
                    "getSequenceElementType() must be called with a  sequence type");

        if (!(rSequenceType.getTypeClass() == staruno::TypeClass_SEQUENCE))
            return staruno::Type();

        staruno::TypeDescription aTD(rSequenceType);
        typelib_IndirectTypeDescription* pSequenceTD =
            reinterpret_cast< typelib_IndirectTypeDescription* >(aTD.get());

        OSL_ASSERT(pSequenceTD);
        OSL_ASSERT(pSequenceTD->pType);

        if ( pSequenceTD && pSequenceTD->pType )
            {
                // SUPD expects a decimal constant, hence,
                // build version comparison is made using
                // a decimal number

                #if ( SUPD >= 601 )
                    return staruno::Type(pSequenceTD->pType);
                #else
                    OSL_ASSERT(pSequenceTD->pType);
                    return staruno::Type(pSequenceTD->pType->pWeakRef);
                #endif
            } //if

        return staruno::Type();
    }
    staruno::Type getBasicType(staruno::Type const& rType, bool& bSequence)
    {
        bSequence = rType.getTypeClass() == staruno::TypeClass_SEQUENCE &&
                    rType != getBinaryType();

        if (!bSequence)
            return rType;

        return getSequenceElementType(rType);
    }

} // namespace configmgr
<commit_msg>#78928# the method convertToSimpleType create an exception when someone try to create an Any with an type and not the right data but we put now a void type in this any if this is happend.<commit_after>/*************************************************************************
 *
 *  $RCSfile: typeconverter.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: lla $ $Date: 2000-09-22 14:29:49 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#include "typeconverter.hxx"

#ifndef _COM_SUN_STAR_SCRIPT_XTYPECONVERTER_HPP_
#include <com/sun/star/script/XTypeConverter.hpp>
#endif
#ifndef _COM_SUN_STAR_SCRIPT_FAILREASON_HPP_
#include <com/sun/star/script/FailReason.hpp>
#endif
#ifndef _COM_SUN_STAR_UNO_TYPE_HXX_
#include <com/sun/star/uno/Type.hxx>
#endif

#ifndef _TYPELIB_TYPEDESCRIPTION_HXX_
#include <typelib/typedescription.hxx>
#endif

#ifndef _RTL_USTRING_HXX_
#include <rtl/ustring.hxx>
#endif

//#include <stdio.h>

#ifndef _OSL_DIAGNOSE_H_
#include <osl/diagnose.h>
#endif

namespace staruno = ::com::sun::star::uno;
namespace starscript = ::com::sun::star::script;
namespace starlang = ::com::sun::star::lang;

namespace configmgr
{

//--------------------------------------------------------------------------------------------------
    rtl::OUString toString(const staruno::Reference< starscript::XTypeConverter >& xTypeConverter, const staruno::Any& rValue) throw( starscript::CannotConvertException )
    {
        rtl::OUString aRes;
        ::staruno::TypeClass aDestinationClass = rValue.getValueType().getTypeClass();

        switch (aDestinationClass)
        {
        case ::staruno::TypeClass_BOOLEAN:
        case ::staruno::TypeClass_CHAR:
        case ::staruno::TypeClass_BYTE:
        case ::staruno::TypeClass_SHORT:
        case ::staruno::TypeClass_LONG:
        case ::staruno::TypeClass_FLOAT:
        case ::staruno::TypeClass_DOUBLE:
            if (!xTypeConverter.is())
            {
                throw( starscript::CannotConvertException( ::rtl::OUString::createFromAscii("stardiv.script.Converter!"), ::staruno::Reference< ::staruno::XInterface > (),
                                                           aDestinationClass, starscript::FailReason::UNKNOWN, 0 ) );
            }
            xTypeConverter->convertToSimpleType(rValue, ::staruno::TypeClass_STRING) >>= aRes;
            break;
        case ::staruno::TypeClass_STRING:
            rValue >>= aRes;
            break;
        default:
            throw( starscript::CannotConvertException( ::rtl::OUString::createFromAscii("TYPE is not supported!"), staruno::Reference< ::staruno::XInterface > (),
                                                       aDestinationClass, starscript::FailReason::TYPE_NOT_SUPPORTED, 0 ) );

        }
        return aRes;
    }

    staruno::Any toAny(const staruno::Reference< starscript::XTypeConverter >& xTypeConverter, const ::rtl::OUString& _rValue,const staruno::TypeClass& _rTypeClass) throw( starscript::CannotConvertException )
    {
        staruno::Any aRes;
        try
        {
            aRes = xTypeConverter->convertToSimpleType(staruno::makeAny(_rValue), _rTypeClass);
        }
        catch (starscript::CannotConvertException&)
        {
            if (_rValue.getLength() != 0)
                OSL_ENSHURE(sal_False, "toAny : could not convert !");
        }
        catch (starlang::IllegalArgumentException&)
        {
            OSL_ENSHURE(sal_False, "toAny : could not convert !");
        }
        return aRes;
    }

    ::rtl::OUString toTypeName(const staruno::TypeClass& _rTypeClass)
    {
        ::rtl::OUString aRet;
        switch(_rTypeClass)
        {
        case staruno::TypeClass_BOOLEAN:  aRet = ::rtl::OUString::createFromAscii("boolean"); break;
        case staruno::TypeClass_SHORT:    aRet = ::rtl::OUString::createFromAscii("short"); break;
        case staruno::TypeClass_LONG:     aRet = ::rtl::OUString::createFromAscii("integer"); break;
        case staruno::TypeClass_HYPER:    aRet = ::rtl::OUString::createFromAscii("long"); break;
        case staruno::TypeClass_DOUBLE:   aRet = ::rtl::OUString::createFromAscii("double"); break;
        case staruno::TypeClass_STRING:   aRet = ::rtl::OUString::createFromAscii("string"); break;
        case staruno::TypeClass_SEQUENCE: aRet = ::rtl::OUString::createFromAscii("binary"); break;
        default:
        {
            ::rtl::OString aStr("Wrong typeclass! ");
            aStr += ::rtl::OString::valueOf((sal_Int32)_rTypeClass);
            OSL_ENSHURE(0,aStr.getStr());
        }
        }
        return aRet;
    }

    staruno::TypeClass toTypeClass(const ::rtl::OUString& _rType)
    {
        staruno::TypeClass aRet = staruno::TypeClass_VOID;

        if     (_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("boolean")))  aRet = staruno::TypeClass_BOOLEAN;
        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("short")))    aRet = staruno::TypeClass_SHORT;
        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("int")))      aRet = staruno::TypeClass_LONG;
        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("integer")))  aRet = staruno::TypeClass_LONG;
        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("long")))     aRet = staruno::TypeClass_HYPER;
        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("double")))   aRet = staruno::TypeClass_DOUBLE;
        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("string")))   aRet = staruno::TypeClass_STRING;
        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("binary")))   aRet = staruno::TypeClass_SEQUENCE;
        else
        {
            ::rtl::OString aStr("Wrong typeclass! ");
            aStr += rtl::OUStringToOString(_rType,RTL_TEXTENCODING_ASCII_US);
            OSL_ENSHURE(0,aStr.getStr());
        }

        return aRet;
    }

// *************************************************************************

    namespace
    {

        inline staruno::Type getBooleanType() { return ::getBooleanCppuType(); }

        inline staruno::Type getShortType()     { return ::getCppuType(static_cast<sal_Int16 const*>(0)); }
        inline staruno::Type getIntType()       { return ::getCppuType(static_cast<sal_Int32 const*>(0)); }
        inline staruno::Type getLongType()      { return ::getCppuType(static_cast<sal_Int64 const*>(0)); }

        inline staruno::Type getDoubleType()    { return ::getCppuType(static_cast<double const*>(0)); }

        inline staruno::Type getStringType()    { return ::getCppuType(static_cast<rtl::OUString const*>(0)); }

// *************************************************************************
/*
  ::rtl::OUString findXMLTypeName(const staruno::Type& _rType)
  {
  ::rtl::OUString aRet;
  switch(_rType.getTypeClass())
  {
  case staruno::TypeClass_BOOLEAN:
  OSL_ASSERT( _rType == getBooleanType() );
  aRet = ::rtl::OUString::createFromAscii("boolean");
  break;

  case staruno::TypeClass_SHORT:
  OSL_ASSERT( _rType == getShortType() );
  aRet = ::rtl::OUString::createFromAscii("short");
  break;

  case staruno::TypeClass_LONG:
  OSL_ASSERT( _rType == getIntType() );
  aRet = ::rtl::OUString::createFromAscii("int");
  break;

  case staruno::TypeClass_HYPER:
  OSL_ASSERT( _rType == getLongType() );
  Ret = ::rtl::OUString::createFromAscii("long");
  break;

  case staruno::TypeClass_DOUBLE:
  OSL_ASSERT( _rType == getDoubleType() );
  aRet = ::rtl::OUString::createFromAscii("double");
  break;

  case staruno::TypeClass_STRING:
  OSL_ASSERT( _rType == getStringType() );
  aRet = ::rtl::OUString::createFromAscii("string");
  break;

  case staruno::TypeClass_SEQUENCE:
  if ( _rType == getStringType() );
  aRet = ::rtl::OUString::createFromAscii("sequence");
  break;

  default:
  {
  ::rtl::OString aStr("Wrong typeclass! ");
  aStr += ::rtl::OString::valueOf((sal_Int32)_rTypeClass);
  OSL_ENSHURE(0,aStr.getStr());
  }
  }
  return aRet;
  }
 */
    } // unamed namespace
// *************************************************************************

    staruno::Type toType(const ::rtl::OUString& _rType)
    {
        staruno::Type aRet;

        if     (_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("boolean")))  aRet = getBooleanType();

        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("short")))    aRet = getShortType();
        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("int")))      aRet = getIntType();
        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("integer")))  aRet = getIntType();
        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("long")))     aRet = getLongType();

        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("double")))   aRet = getDoubleType();

        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("string")))   aRet = getStringType();
        else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("binary")))   aRet = getBinaryType();
//  else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("sequence"))) aRet = staruno::TypeClass_SEQUENCE;
        else
        {
            ::rtl::OString aStr("Unknown type! ");
            aStr += rtl::OUStringToOString(_rType,RTL_TEXTENCODING_ASCII_US);
            OSL_ENSHURE(0,aStr.getStr());
        }

        return aRet;
    }
    staruno::Type toListType(const ::rtl::OUString& _rsElementType)
    {
        staruno::Type aRet;

        if     (_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("boolean")))
            aRet = ::getCppuType(static_cast<staruno::Sequence<sal_Bool> const*>(0));

        else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("short")))
            aRet = ::getCppuType(static_cast<staruno::Sequence<sal_Int16> const*>(0));

        else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("int")))
            aRet = ::getCppuType(static_cast<staruno::Sequence<sal_Int32> const*>(0));
        else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("integer")))
            aRet = ::getCppuType(static_cast<staruno::Sequence<sal_Int32> const*>(0));

        else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("long")))
            aRet = ::getCppuType(static_cast<staruno::Sequence<sal_Int64> const*>(0));

        else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("double")))
            aRet = ::getCppuType(static_cast<staruno::Sequence<double> const*>(0));

        else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("string")))
            aRet = ::getCppuType(static_cast<staruno::Sequence<rtl::OUString> const*>(0));

        else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("binary")))
            aRet = ::getCppuType(static_cast<staruno::Sequence<staruno::Sequence<sal_Int8> > const*>(0));

//  else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("sequence"))) aRet = staruno::TypeClass_SEQUENCE;
        else
        {
            ::rtl::OString aStr("Unknown type! ");
            aStr += rtl::OUStringToOString(_rsElementType,RTL_TEXTENCODING_ASCII_US);
            OSL_ENSHURE(0,aStr.getStr());
        }

        return aRet;
    }

    staruno::Type getSequenceElementType(staruno::Type const& rSequenceType)
    {
        OSL_ENSHURE(rSequenceType.getTypeClass() == staruno::TypeClass_SEQUENCE,
                    "getSequenceElementType() must be called with a  sequence type");

        if (!(rSequenceType.getTypeClass() == staruno::TypeClass_SEQUENCE))
            return staruno::Type();

        staruno::TypeDescription aTD(rSequenceType);
        typelib_IndirectTypeDescription* pSequenceTD =
            reinterpret_cast< typelib_IndirectTypeDescription* >(aTD.get());

        OSL_ASSERT(pSequenceTD);
        OSL_ASSERT(pSequenceTD->pType);

        if ( pSequenceTD && pSequenceTD->pType )
        {
            // SUPD expects a decimal constant, hence,
            // build version comparison is made using
            // a decimal number

#if ( SUPD >= 601 )
            return staruno::Type(pSequenceTD->pType);
#else
            OSL_ASSERT(pSequenceTD->pType);
            return staruno::Type(pSequenceTD->pType->pWeakRef);
#endif
        } //if

        return staruno::Type();
    }
    staruno::Type getBasicType(staruno::Type const& rType, bool& bSequence)
    {
        bSequence = rType.getTypeClass() == staruno::TypeClass_SEQUENCE &&
                    rType != getBinaryType();

        if (!bSequence)
            return rType;

        return getSequenceElementType(rType);
    }

} // namespace configmgr
<|endoftext|>


<commit_before>#include "AssetLoader.h"
#include <iostream>

namespace fse
{
	AssetLoader::AssetLoader() {

	}

	AssetLoader::~AssetLoader()
	{
	}

	sf::Texture& AssetLoader::getSFTexture(std::string path)
	{
		if (textureMap.count(path)) //Texture is already loaded
		{
			textureCounter[path]++;
		}
		else
		{
			loadTexture(path);
		}
		return textureMap[path];
	}

	AssetLoader::Texture AssetLoader::getTexture(std::string path)
	{
		return Texture(this, path, &getSFTexture(path));
	}

	void AssetLoader::releaseSFTexture(std::string path)
	{
		if (textureCounter.size() == 0)
			return;
		if (!textureCounter.count(path)) //Texture is not in memory
			return;
		if (textureCounter[path] == 1)
		{
			textureCounter.erase(path);
			textureMap.erase(path);

			std::cout << "erasing texture: " << path << "\n";

			return;
		}

		textureCounter[path]--;
	}

	void AssetLoader::loadTexture(std::string path)
	{
		std::string realPath = "data/" + path;
		textureMap[path].loadFromFile(realPath.c_str());
		textureCounter[path] = 1;
	}

	AssetLoader::Texture::Texture() : loader_(nullptr), tex_(nullptr)
	{
	}

	AssetLoader::Texture::Texture(const Texture& texture) : loader_(texture.loader_), path_(texture.path_), tex_(texture.tex_)
	{
		loader_->textureCounter[path_]++;
	}

	AssetLoader::Texture::Texture(AssetLoader* loader, std::string path, sf::Texture* tex) : loader_(loader), path_(path), tex_(tex)
	{
	}

	AssetLoader::Texture::~Texture()
	{
		if (path_ != "")
			loader_->releaseSFTexture(path_);
	}

	sf::Texture& AssetLoader::Texture::get() const
	{
		return *tex_;
	}

	AssetLoader::Texture& AssetLoader::Texture::operator=(const Texture& texture)
	{
		if (&texture == this)
			return *this;

		Texture tmp(texture);
		std::swap(loader_, tmp.loader_);
		std::swap(path_, tmp.path_);
		std::swap(tex_, tmp.tex_);

		loader_->textureCounter[path_]++;

		return *this;
	}

	sf::Texture* AssetLoader::Texture::operator->() const
	{
		return tex_;
	}
}
<commit_msg>AssetLoader: Fix wrapped textures leaking<commit_after>#include "AssetLoader.h"
#include <iostream>

namespace fse
{
	AssetLoader::AssetLoader() {

	}

	AssetLoader::~AssetLoader()
	{
	}

	sf::Texture& AssetLoader::getSFTexture(std::string path)
	{
		if (textureMap.count(path)) //Texture is already loaded
		{
			textureCounter[path]++;
		}
		else
		{
			loadTexture(path);
		}
		return textureMap[path];
	}

	AssetLoader::Texture AssetLoader::getTexture(std::string path)
	{
		return Texture(this, path, &getSFTexture(path));
	}

	void AssetLoader::releaseSFTexture(std::string path)
	{
		if (textureCounter.size() == 0)
			return;
		if (!textureCounter.count(path)) //Texture is not in memory
			return;
		if (textureCounter[path] == 1)
		{
			textureCounter.erase(path);
			textureMap.erase(path);

			std::cout << "erasing texture: " << path << "\n";

			return;
		}

		textureCounter[path]--;
	}

	void AssetLoader::loadTexture(std::string path)
	{
		std::string realPath = "data/" + path;
		textureMap[path].loadFromFile(realPath.c_str());
		textureCounter[path] = 1;
	}

	AssetLoader::Texture::Texture() : loader_(nullptr), tex_(nullptr)
	{
	}

	AssetLoader::Texture::Texture(const Texture& texture) : loader_(texture.loader_), path_(texture.path_), tex_(texture.tex_)
	{
		loader_->textureCounter[path_]++;
	}

	AssetLoader::Texture::Texture(AssetLoader* loader, std::string path, sf::Texture* tex) : loader_(loader), path_(path), tex_(tex)
	{
	}

	AssetLoader::Texture::~Texture()
	{
		if (path_ != "")
			loader_->releaseSFTexture(path_);
	}

	sf::Texture& AssetLoader::Texture::get() const
	{
		return *tex_;
	}

	AssetLoader::Texture& AssetLoader::Texture::operator=(const Texture& texture)
	{
		if (&texture == this)
			return *this;

		Texture tmp(texture);
		std::swap(loader_, tmp.loader_);
		std::swap(path_, tmp.path_);
		std::swap(tex_, tmp.tex_);

		return *this;
	}

	sf::Texture* AssetLoader::Texture::operator->() const
	{
		return tex_;
	}
}
<|endoftext|>


<commit_before>#include "../src/meshoptimizer.h"

#include <string>
#include <vector>

#define CGLTF_IMPLEMENTATION
#include "cgltf.h"

struct Attr
{
	float f[4];
};

struct Stream
{
	cgltf_attribute_type type;
	std::vector<Attr> data;
};

struct Mesh
{
	std::vector<Stream> streams;
	std::vector<unsigned int> indices;
};

struct Scene
{
	cgltf_data* data;
	std::vector<Mesh> meshes;

	~Scene()
	{
		cgltf_free(data);
	}
};

const char* getError(cgltf_result result)
{
	switch (result)
	{
	case cgltf_result_file_not_found:
		return "file not found";

	case cgltf_result_io_error:
		return "I/O error";

	case cgltf_result_invalid_json:
		return "invalid JSON";

	case cgltf_result_invalid_gltf:
		return "invalid GLTF";

	case cgltf_result_out_of_memory:
		return "out of memory";

	default:
		return "unknown error";
	}
}

bool process(Scene& scene, std::string& json, std::string& bin)
{
	(void)scene;
	(void)json;
	(void)bin;
	return true;
}

void writeU32(FILE* out, uint32_t data)
{
	fwrite(&data, 4, 1, out);
}

int main(int argc, char** argv)
{
	if (argc < 3)
	{
		fprintf(stderr, "Usage: gltfpack [options] input output\n");
		return 1;
	}

	const char* input = argv[argc - 2];
	const char* output = argv[argc - 1];

	Scene scene = {};

	cgltf_options options = {};
	cgltf_result result = cgltf_parse_file(&options, input, &scene.data);
	result = (result == cgltf_result_success) ? cgltf_validate(scene.data) : result;
	result = (result == cgltf_result_success) ? cgltf_load_buffers(&options, scene.data, input) : result;

	if (result != cgltf_result_success)
	{
		fprintf(stderr, "Error loading %s: %s\n", input, getError(result));
		return 2;
	}

	std::string json, bin;
	if (!process(scene, json, bin))
	{
		fprintf(stderr, "Error processing %s\n", input);
		return 3;
	}

	const char* ext = strrchr(output, '.');

	if (ext && (strcmp(ext, ".gltf") == 0 || strcmp(ext, ".GLTF") == 0))
	{
		std::string binpath = output;
		binpath.replace(binpath.size() - 5, 5, ".bin");

		std::string binname = binpath;
		std::string::size_type slash = binname.find_last_of("/\\");
		if (slash != std::string::npos)
			binname.erase(0, slash);

		FILE* outjson = fopen(output, "wb");
		FILE* outbin = fopen(binpath.c_str(), "wb");
		if (!outjson || !outbin)
		{
			fprintf(stderr, "Error saving %s\n", output);
			return 4;
		}

		fprintf(outjson, "{buffers:[{uri:\"%s\",byteLength:%zu}],", binname.c_str(), bin.size());
		fwrite(json.c_str(), json.size(), 1, outjson);
		fprintf(outjson, "}");

		fwrite(bin.c_str(), bin.size(), 1, outbin);

		fclose(outjson);
		fclose(outbin);
	}
	else if (ext && (strcmp(ext, ".glb") == 0 || strcmp(ext, ".GLB") == 0))
	{
		FILE* out = fopen(output, "wb");
		if (!out)
		{
			fprintf(stderr, "Error saving %s\n", output);
			return 4;
		}

		char bufferspec[32];
		sprintf(bufferspec, "{buffers:[{byteLength:%zu}],", bin.size());

		json.insert(0, bufferspec);
		json.push_back('}');

		while (json.size() % 4)
			json.push_back(' ');

		while (bin.size() % 4)
			bin.push_back('\0');

		writeU32(out, 0x46546C67);
		writeU32(out, 2);
		writeU32(out, 12 + 8 + json.size() + 8 + bin.size());

		writeU32(out, 0x4E4F534A);
		writeU32(out, json.size());
		fwrite(json.c_str(), json.size(), 1, out);

		writeU32(out, 0x004E4942);
		writeU32(out, bin.size());
		fwrite(bin.c_str(), bin.size(), 1, out);

		fclose(out);
	}
	else
	{
		fprintf(stderr, "Error saving %s: unknown extension (expected .gltf or .glb)\n", output);
		return 4;
	}

	return 0;
}
<commit_msg>gltfpack: Implement mesh parsing<commit_after>#include "../src/meshoptimizer.h"

#include <string>
#include <vector>

#include <math.h>

#define CGLTF_IMPLEMENTATION
#include "cgltf.h"

struct Attr
{
	float f[4];
};

struct Stream
{
	cgltf_attribute_type type;
	int index;

	std::vector<Attr> data;
};

struct Mesh
{
	std::vector<Stream> streams;
	std::vector<unsigned int> indices;
};

struct Scene
{
	cgltf_data* data;
	std::vector<Mesh> meshes;

	~Scene()
	{
		cgltf_free(data);
	}
};

const char* getError(cgltf_result result)
{
	switch (result)
	{
	case cgltf_result_file_not_found:
		return "file not found";

	case cgltf_result_io_error:
		return "I/O error";

	case cgltf_result_invalid_json:
		return "invalid JSON";

	case cgltf_result_invalid_gltf:
		return "invalid GLTF";

	case cgltf_result_out_of_memory:
		return "out of memory";

	default:
		return "unknown error";
	}
}

cgltf_accessor* getAccessor(const cgltf_attribute* attributes, size_t attribute_count, cgltf_attribute_type type, int index = 0)
{
	for (size_t i = 0; i < attribute_count; ++i)
		if (attributes[i].type == type && attributes[i].index == index)
			return attributes[i].data;

	return 0;
}

void transformPosition(float* ptr, const float* transform)
{
	float x = ptr[0] * transform[0] + ptr[1] * transform[4] + ptr[2] * transform[8] + transform[12];
	float y = ptr[0] * transform[1] + ptr[1] * transform[5] + ptr[2] * transform[9] + transform[13];
	float z = ptr[0] * transform[2] + ptr[1] * transform[6] + ptr[2] * transform[10] + transform[14];

	ptr[0] = x;
	ptr[1] = y;
	ptr[2] = z;
}

void transformNormal(float* ptr, const float* transform)
{
	float x = ptr[0] * transform[0] + ptr[1] * transform[4] + ptr[2] * transform[8];
	float y = ptr[0] * transform[1] + ptr[1] * transform[5] + ptr[2] * transform[9];
	float z = ptr[0] * transform[2] + ptr[1] * transform[6] + ptr[2] * transform[10];

	float l = sqrtf(x * x + y * y + z * z);
	float s = (l == 0.f) ? 0.f : 1 / l;

	ptr[0] = x * s;
	ptr[1] = y * s;
	ptr[2] = z * s;
}

void parseMeshes(cgltf_data* data, std::vector<Mesh>& meshes)
{
	for (size_t ni = 0; ni < data->nodes_count; ++ni)
	{
		if (!data->nodes[ni].mesh)
			continue;

		float transform[16];
		cgltf_node_transform_world(&data->nodes[ni], transform);

		const cgltf_mesh& mesh = *data->nodes[ni].mesh;

		for (size_t pi = 0; pi < mesh.primitives_count; ++pi)
		{
			const cgltf_primitive& primitive = mesh.primitives[pi];

			Mesh result;

			if (cgltf_accessor* a = primitive.indices)
			{
				result.indices.resize(a->count);
				for (size_t i = 0; i < a->count; ++i)
					result.indices[i] = cgltf_accessor_read_index(a, i);
			}

			for (size_t ai = 0; ai < primitive.attributes_count; ++ai)
			{
				const cgltf_attribute& attr = primitive.attributes[ai];

				if (attr.type == cgltf_attribute_type_invalid)
					continue;

				Stream s = { attr.type, attr.index };
				s.data.resize(attr.data->count);

				for (size_t i = 0; i < attr.data->count; ++i)
					cgltf_accessor_read_float(attr.data, i, s.data[i].f, 4);

				if (attr.type == cgltf_attribute_type_position)
				{
					for (size_t i = 0; i < attr.data->count; ++i)
						transformPosition(s.data[i].f, transform);
				}
				else if (attr.type == cgltf_attribute_type_normal || attr.type == cgltf_attribute_type_tangent)
				{
					for (size_t i = 0; i < attr.data->count; ++i)
						transformNormal(s.data[i].f, transform);
				}

				result.streams.push_back(s);
			}

			if (result.indices.size() && result.streams.size())
				meshes.push_back(result);
		}
	}
}

bool process(Scene& scene, std::string& json, std::string& bin)
{
	cgltf_data* data = scene.data;

	parseMeshes(data, scene.meshes);

	(void)json;
	(void)bin;
	return true;
}

void writeU32(FILE* out, uint32_t data)
{
	fwrite(&data, 4, 1, out);
}

int main(int argc, char** argv)
{
	if (argc < 3)
	{
		fprintf(stderr, "Usage: gltfpack [options] input output\n");
		return 1;
	}

	const char* input = argv[argc - 2];
	const char* output = argv[argc - 1];

	Scene scene = {};

	cgltf_options options = {};
	cgltf_result result = cgltf_parse_file(&options, input, &scene.data);
	result = (result == cgltf_result_success) ? cgltf_validate(scene.data) : result;
	result = (result == cgltf_result_success) ? cgltf_load_buffers(&options, scene.data, input) : result;

	if (result != cgltf_result_success)
	{
		fprintf(stderr, "Error loading %s: %s\n", input, getError(result));
		return 2;
	}

	std::string json, bin;
	if (!process(scene, json, bin))
	{
		fprintf(stderr, "Error processing %s\n", input);
		return 3;
	}

	const char* ext = strrchr(output, '.');

	if (ext && (strcmp(ext, ".gltf") == 0 || strcmp(ext, ".GLTF") == 0))
	{
		std::string binpath = output;
		binpath.replace(binpath.size() - 5, 5, ".bin");

		std::string binname = binpath;
		std::string::size_type slash = binname.find_last_of("/\\");
		if (slash != std::string::npos)
			binname.erase(0, slash);

		FILE* outjson = fopen(output, "wb");
		FILE* outbin = fopen(binpath.c_str(), "wb");
		if (!outjson || !outbin)
		{
			fprintf(stderr, "Error saving %s\n", output);
			return 4;
		}

		fprintf(outjson, "{buffers:[{uri:\"%s\",byteLength:%zu}],", binname.c_str(), bin.size());
		fwrite(json.c_str(), json.size(), 1, outjson);
		fprintf(outjson, "}");

		fwrite(bin.c_str(), bin.size(), 1, outbin);

		fclose(outjson);
		fclose(outbin);
	}
	else if (ext && (strcmp(ext, ".glb") == 0 || strcmp(ext, ".GLB") == 0))
	{
		FILE* out = fopen(output, "wb");
		if (!out)
		{
			fprintf(stderr, "Error saving %s\n", output);
			return 4;
		}

		char bufferspec[32];
		sprintf(bufferspec, "{buffers:[{byteLength:%zu}],", bin.size());

		json.insert(0, bufferspec);
		json.push_back('}');

		while (json.size() % 4)
			json.push_back(' ');

		while (bin.size() % 4)
			bin.push_back('\0');

		writeU32(out, 0x46546C67);
		writeU32(out, 2);
		writeU32(out, 12 + 8 + json.size() + 8 + bin.size());

		writeU32(out, 0x4E4F534A);
		writeU32(out, json.size());
		fwrite(json.c_str(), json.size(), 1, out);

		writeU32(out, 0x004E4942);
		writeU32(out, bin.size());
		fwrite(bin.c_str(), bin.size(), 1, out);

		fclose(out);
	}
	else
	{
		fprintf(stderr, "Error saving %s: unknown extension (expected .gltf or .glb)\n", output);
		return 4;
	}

	return 0;
}
<|endoftext|>