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