Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDB/JSelector.hh
Go to the documentation of this file.
1 #ifndef __JDB_JSELECTOR__
2 #define __JDB_JSELECTOR__
3 
4 #include <istream>
5 #include <ostream>
6 #include <string>
7 #include <vector>
8 
9 #include "JLang/JEquation.hh"
10 #include "JLang/JEquationFacet.hh"
12 
13 #include "KM3NeTDBClient.h"
14 
15 
16 /**
17  * \author mdejong
18  */
19 
20 namespace KM3NETDB {
21 
22  using KM3NeT::DB::Selector;
24 
25 
26  /**
27  * Auxiliary class for specifying selection of database data.
28  */
29  class JSelector :
30  public std::vector<Selector>,
31  public JEquationParameters
32  {
33  public:
34  /**
35  * Default constructor.
36  */
38  std::vector<Selector>(),
39  JEquationParameters("=", ";\n", "./", "#")
40  {}
41 
42 
43  /**
44  * Constructor.
45  *
46  * \param parameters equation parameters
47  */
48  JSelector(const JEquationParameters& parameters) :
49  std::vector<Selector>(),
50  JEquationParameters(parameters)
51  {}
52 
53 
54  /**
55  * Read selector from input stream.
56  *
57  * \param in input stream
58  * \param selector selector
59  * \return input stream
60  */
61  friend inline std::istream& operator>>(std::istream& in, JSelector& selector)
62  {
63  using namespace std;
64  using namespace JLANG;
65 
66  const JEquationFacet facet(selector.getEquationParameters());
67 
68  in.imbue(locale(in.getloc(), facet.clone()));
69 
70  for (JEquation equation; in >> equation; ) {
71  if (facet.isSeparator(equation.getSeparator())) {
72  selector.push_back(Selector(equation.getKey().c_str(), equation.getValue().c_str()));
73  }
74  }
75 
76  return in;
77  }
78 
79 
80  /**
81  * Write selector to output stream.
82  *
83  * \param out output stream
84  * \param selector selector
85  * \return output stream
86  */
87  friend inline std::ostream& operator<<(std::ostream& out, const JSelector& selector)
88  {
89  for (const_iterator i = selector.begin(); i != selector.end(); ++i) {
90  out << i->Name << selector.getDefaultSeparator() << i->Value << selector.getDefaultEndOfLine();
91  }
92 
93  return out;
94  }
95  };
96 }
97 
98 #endif
friend std::ostream & operator<<(std::ostream &out, const JSelector &selector)
Write selector to output stream.
Facet class to specify parsing of equations in currect locale (see class JLANG::JEquation).
const char getDefaultSeparator() const
Get default separator character.
Auxiliary class for specifying selection of database data.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
friend std::istream & operator>>(std::istream &in, JSelector &selector)
Read selector from input stream.
JSelector()
Default constructor.
General purpose equation class.
Definition: JEquation.hh:47
const JEquationParameters & getEquationParameters() const
Get equation parameters.
const char getDefaultEndOfLine() const
Get default end of line character.
JSelector(const JEquationParameters &parameters)
Constructor.