rtree_test_generator.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Boost.Geometry Index
  2. // Rtree tests generator
  3. // Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland.
  4. // Use, modification and distribution is subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include <fstream>
  8. #include <vector>
  9. #include <string>
  10. #include <boost/foreach.hpp>
  11. #include <boost/assert.hpp>
  12. #include <boost/tuple/tuple.hpp>
  13. int main()
  14. {
  15. typedef boost::tuple<std::string, std::string> CT;
  16. std::vector<CT> coordinate_types;
  17. coordinate_types.push_back(boost::make_tuple("double", "d"));
  18. //coordinate_types.push_back(boost::make_tuple("int", "i"));
  19. //coordinate_types.push_back(boost::make_tuple("float", "f"));
  20. std::vector<std::string> dimensions;
  21. dimensions.push_back("2");
  22. dimensions.push_back("3");
  23. typedef boost::tuple<std::string, std::string> P;
  24. std::vector<P> parameters;
  25. parameters.push_back(boost::make_tuple("bgi::linear<5, 2>()", "lin"));
  26. parameters.push_back(boost::make_tuple("bgi::dynamic_linear(5, 2)", "dlin"));
  27. parameters.push_back(boost::make_tuple("bgi::quadratic<5, 2>()", "qua"));
  28. parameters.push_back(boost::make_tuple("bgi::dynamic_quadratic(5, 2)", "dqua"));
  29. parameters.push_back(boost::make_tuple("bgi::rstar<5, 2>()", "rst"));
  30. parameters.push_back(boost::make_tuple("bgi::dynamic_rstar(5, 2)","drst"));
  31. std::vector<std::string> indexables;
  32. indexables.push_back("p");
  33. indexables.push_back("b");
  34. indexables.push_back("s");
  35. typedef std::pair<std::string, std::string> TS;
  36. std::vector<TS> testsets;
  37. testsets.push_back(std::make_pair("testset::modifiers", "mod"));
  38. testsets.push_back(std::make_pair("testset::queries", "que"));
  39. testsets.push_back(std::make_pair("testset::additional", "add"));
  40. BOOST_FOREACH(P const& p, parameters)
  41. {
  42. BOOST_FOREACH(TS const& ts, testsets)
  43. {
  44. BOOST_FOREACH(std::string const& i, indexables)
  45. {
  46. BOOST_FOREACH(std::string const& d, dimensions)
  47. {
  48. // If the I is Segment, generate only for 2d
  49. if ( i == "s" && d != "2" )
  50. {
  51. continue;
  52. }
  53. BOOST_FOREACH(CT const& c, coordinate_types)
  54. {
  55. std::string filename = std::string() +
  56. "rtree_" + boost::get<1>(p) + '_' + ts.second + '_' + i + d + boost::get<1>(c) + ".cpp";
  57. std::ofstream f(filename.c_str(), std::ios::trunc);
  58. f <<
  59. "// Boost.Geometry Index\n" <<
  60. "// Unit Test\n" <<
  61. "\n" <<
  62. "// Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland.\n" <<
  63. "\n" <<
  64. "// Use, modification and distribution is subject to the Boost Software License,\n" <<
  65. "// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at\n" <<
  66. "// http://www.boost.org/LICENSE_1_0.txt)\n" <<
  67. "\n";
  68. f <<
  69. "#include <rtree/test_rtree.hpp>\n" <<
  70. "\n";
  71. std::string indexable_type;
  72. std::string point_type = std::string("bg::model::point<") + boost::get<0>(c) + ", " + d + ", bg::cs::cartesian>";
  73. if ( i == "p" )
  74. indexable_type = point_type;
  75. else if ( i == "b" )
  76. indexable_type = std::string("bg::model::box< ") + point_type + " >";
  77. else if ( i == "s" )
  78. indexable_type = std::string("bg::model::segment< ") + point_type + " >";
  79. else
  80. BOOST_ASSERT(false);
  81. f <<
  82. "int test_main(int, char* [])\n" <<
  83. "{\n" <<
  84. " typedef " << indexable_type << " Indexable;\n" <<
  85. " " << ts.first << "<Indexable>(" << boost::get<0>(p) << ", std::allocator<int>());\n" <<
  86. " return 0;\n" <<
  87. "}\n";
  88. }
  89. }
  90. }
  91. }
  92. }
  93. return 0;
  94. }