Swarm-NG  1.1
query.hpp
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) 2011 by Saleh Dindar and the Swarm-NG Development Team *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 3 of the License. *
7  * *
8  * This program is distributed in the hope that it will be useful, *
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11  * GNU General Public License for more details. *
12  * *
13  * You should have received a copy of the GNU General Public License *
14  * along with this program; if not, write to the *
15  * Free Software Foundation, Inc., *
16  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
17  ************************************************************************/
18 
25 #pragma once
26 
27 #include "common.hpp"
28 #include "log/io.hpp"
29 #include <boost/regex.hpp>
30 #include <boost/program_options.hpp>
31 
32 namespace swarm { namespace query {
33 
35 template<typename T>
36 T arg_parse(const std::string &s)
37 {
38  if(s == "MIN") { return MIN; }
39  if(s == "MAX") { return MAX; }
40  return boost::lexical_cast<T>(s);
41 }
42 
53 template<typename T>
54 void validate(boost::any& v,
55  const std::vector<std::string>& values,
56  range<T>* target_type, int)
57 {
58  using namespace boost::program_options;
59  typedef range<T> rangeT;
60 
61  // Make sure no previous assignment to 'a' was made.
62  validators::check_first_occurrence(v);
63 
64  // Extract the first string from 'values'. If there is more than
65  // one string, it's an error, and exception will be thrown.
66  const std::string& s = validators::get_single_string(values);
67 
68  if(s == "ALL")
69  {
70  v = boost::any(rangeT(ALL));
71  return;
72  }
73 
74  static boost::regex r("(.+?)(?:\\.\\.(.+))?");
75  boost::smatch match;
76  if (boost::regex_match(s, match, r)) {
77  //for(int i=0; i != match.size(); i++) { std::cerr << match[i] << "\n"; }
78  if(match[2] == "")
79  {
80  v = boost::any(rangeT(arg_parse<T>(match[1])));
81  }
82  else
83  {
84  v = boost::any(rangeT(arg_parse<T>(match[1]), arg_parse<T>(match[2])));
85  }
86  } else {
87 #if BOOST_VERSION < 104200
88  throw validation_error("invalid value");
89 #else
90  throw validation_error(validation_error::invalid_option_value);
91 #endif
92  }
93 }
94 
99 template<typename T>
100 std::ostream &operator<<(std::ostream &out, const range<T> &r)
101 {
102  if(r.first == T(MIN) && r.last == T(MAX)) { return out << "ALL"; }
103  if(r.first == r.last) { return out << r.first; }
104 
105  if(r.first == T(MIN)) { out << "MIN"; } else { out << r.first; }
106  out << "..";
107  if(r.last == T(MAX)) { out << "MAX"; } else { out << r.last; }
108 
109  return out;
110 }
111 
112 void execute(const std::string &dbfile, time_range_t T, sys_range_t sys, body_range_t bod = body_range_t() );
113 
118 std::ostream &output_record(std::ostream &out, gpulog::logrecord &lr, const body_range_t &bod = body_range_t() );
119 
130  astrocentric, barycentric, jacobi, origin
131 };
132 
134 void set_cartesian_output(const planets_coordinate_system_t& coordinate_system = origin) ;
136 void set_keplerian_output(const planets_coordinate_system_t& coordinate_system = jacobi) ;
141 void set_coordinate_system(const planets_coordinate_system_t& coordinate_system);
142 
143 } } // namespace swarm query
144 
145