Jpp  master_rocky-37-gf0c5bc59d
the software that should make you happy
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
JDATABASE::JDBReader< T > Struct Template Reference

Auxiliary class to read object with ROOT dictionary from database. More...

#include <JDBReader.hh>

Inheritance diagram for JDATABASE::JDBReader< T >:
JROOT::JRootReader JLANG::JSingleton< T > JLANG::JStreamState

Public Types

typedef T data_type
 

Public Member Functions

 JDBReader ()
 Default constructor. More...
 
const T & operator() (ResultSet &rs)
 Read object with ROOT dictionary from result set. More...
 
const JRootDictionary_tgetDictionary () const
 Get dictionary. More...
 
template<class T >
JRootReaderget (T &object)
 Read object according equation format. More...
 
JRootReaderget (const JRootReadableClass &cls)
 Read ROOT class according equation format. More...
 
template<class T >
JRootReadergetObject (T &object)
 Read object. More...
 
JRootReadergetObject (const JRootReadableClass &cls)
 Read ROOT class. More...
 
JRootReadergetObject (JRootReadableClass &cls)
 Read ROOT class. More...
 

Static Public Member Functions

static void reset ()
 Reset internal lookup table and default value. More...
 
static void set (const std::vector< Selector > &selection)
 Set default value corresponding to given selection. More...
 
static data_typegetInstance ()
 Get unique instance of template class. More...
 

Private Member Functions

template<class T >
JRootReadergetObject (T &object, const JBool< true > &option)
 Read object. More...
 
template<class T >
JRootReadergetObject (T &object, const JBool< false > &option)
 Read object. More...
 
template<class JElement_t , class JAllocator_t >
JRootReadergetObject (std::vector< JElement_t, JAllocator_t > &object, const JBool< false > &option)
 Read object. More...
 

Private Attributes

object
 internal value More...
 
value
 default value More...
 
std::vector< JROOT::JRootReadableClasscolumns
 field count -> data member More...
 
const JRootDictionary_tdictionary
 
std::ios & __from
 
std::ios & __to
 

Detailed Description

template<class T>
struct JDATABASE::JDBReader< T >

Auxiliary class to read object with ROOT dictionary from database.

The names of the table columns are one-to-one mapped to the names of the data members of the corresponding data structure using the corresponding ROOT dictionary.
For this, all special characters (JDATABASE::SPECIAL_CHARACTERS) are removed from the column names.
The static method JDBReader::set can be used to a priori assign default values to those data members that are defined by the selector used in the query.
Note that the list of column names associated to the template parameter is considered to be permanent.
If not, the static method JDBReader::reset should be called before the next read operation.

Definition at line 94 of file JDBReader.hh.

Member Typedef Documentation

◆ data_type

template<class T >
typedef T JLANG::JSingleton< T >::data_type
inherited

Definition at line 20 of file JSingleton.hh.

Constructor & Destructor Documentation

◆ JDBReader()

template<class T >
JDATABASE::JDBReader< T >::JDBReader ( )
inline

Default constructor.

Definition at line 101 of file JDBReader.hh.

101  :
103  {}
Simple data structure to support I/O of equations (see class JLANG::JEquation).
JRootReader(std::istream &in, const JEquationParameters &parameters, const JRootDictionary_t &dictionary)
Constructor.
static JNullStream null
Null I/O stream.
Definition: JNullStream.hh:51
T & getInstance(const T &object)
Get static instance from temporary object.
Definition: JObject.hh:75

Member Function Documentation

◆ reset()

template<class T >
static void JDATABASE::JDBReader< T >::reset ( )
inlinestatic

Reset internal lookup table and default value.

Definition at line 109 of file JDBReader.hh.

110  {
111  JDBReader<T>::getInstance().columns.clear();
112 
113  JDBReader<T>::getInstance().value = T();
114  }
static data_type & getInstance()
Get unique instance of template class.
Definition: JSingleton.hh:27

◆ set()

template<class T >
static void JDATABASE::JDBReader< T >::set ( const std::vector< Selector > &  selection)
inlinestatic

Set default value corresponding to given selection.

Parameters
selectionselection

Definition at line 122 of file JDBReader.hh.

123  {
124  selection >> JDBReader<T>::getInstance().value;
125  }

◆ operator()()

template<class T >
const T& JDATABASE::JDBReader< T >::operator() ( ResultSet &  rs)
inline

Read object with ROOT dictionary from result set.

Parameters
rsresult set
Returns
object

Definition at line 134 of file JDBReader.hh.

135  {
136  using namespace std;
137  using namespace JPP;
138 
139  object = value;
140 
141  if (columns.empty()) {
142 
143  JRootReadableClass cls(object);
144 
145  for (size_t i = 0; i != rs.FieldCount(); ++i) {
146 
147  string parameter = rs.FieldName(i);
148 
149  for (string::const_iterator i = SPECIAL_CHARACTERS.begin(); i != SPECIAL_CHARACTERS.end(); ++i) {
150  for (string::size_type pos; (pos = parameter.find(*i)) != string::npos; ) {
151  parameter.erase(pos);
152  }
153  }
154 
155  columns.push_back(cls.find(parameter.c_str()));
156  }
157  }
158 
159  for (unsigned int i = 0; i != rs.FieldCount(); ++i) {
160 
161  if (columns[i].is_valid()) {
162 
163  JRedirectString redirect(*this, rs.GetString(i));
164 
165  this->getObject(columns[i]);
166  }
167  }
168 
169  return object;
170  }
This class can be used to temporarily redirect an input stream to an input string.
JRootReader & getObject(T &object)
Read object.
static const std::string SPECIAL_CHARACTERS
Special characters.
Definition: JDBReader.hh:38
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
bool is_valid(const json &js)
Check validity of JSon data.
Definition: JSTDTypes.hh:14
T object
internal value
Definition: JDBReader.hh:173
T value
default value
Definition: JDBReader.hh:174
std::vector< JROOT::JRootReadableClass > columns
field count -> data member
Definition: JDBReader.hh:176
ROOT class for reading object.
Definition: JRootClass.hh:544

◆ getDictionary()

const JRootDictionary_t& JROOT::JRootReader::getDictionary ( ) const
inlineinherited

Get dictionary.

Returns
dictionary

Definition at line 87 of file JRootStreamer.hh.

88  {
89  return dictionary;
90  }
const JRootDictionary_t & dictionary

◆ get() [1/2]

template<class T >
JRootReader& JROOT::JRootReader::get ( T &  object)
inlineinherited

Read object according equation format.

Parameters
objectobject
Returns
this ROOT reader

Definition at line 100 of file JRootStreamer.hh.

101  {
102  return this->get(JRootReadableClass(object));
103  }
JRootReader & get(T &object)
Read object according equation format.

◆ get() [2/2]

JRootReader& JROOT::JRootReader::get ( const JRootReadableClass cls)
inlineinherited

Read ROOT class according equation format.

Parameters
clsROOT class
Returns
this ROOT reader

Definition at line 112 of file JRootStreamer.hh.

113  {
114  using namespace std;
115  using namespace JPP;
116 
117  if (cls.is_valid()) {
118 
119  const JEquationFacet& facet = use_facet<JEquationFacet>(this->getloc());
120 
121  for (JEquation equation; *this >> equation; ) {
122 
123  const JRootReadableClass abc = cls.find(equation.getKey().c_str());
124 
125  bool status = abc.is_valid();
126 
127  if (status) {
128 
129  JRedirectString redirect(*this, equation.getValue());
130 
131  if (facet.isDivision (equation.getSeparator()))
132  this->get(abc);
133  else if (facet.isSeparator(equation.getSeparator()))
134  this->getObject(abc);
135  else
136  status = false;
137 
138  status &= (!this->fail() || this->eof());
139  }
140 
141  if (!status) {
142  THROW(JException, "Error parsing: " << equation);
143  }
144  }
145  }
146 
147  return *this;
148  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
Facet class to specify parsing of equations in currect locale (see class JLANG::JEquation).
bool isSeparator(const char c) const
Test for separator character.
bool isDivision(const char c) const
Test for division character.
General purpose equation class.
Definition: JEquation.hh:47
General exception.
Definition: JException.hh:24
bool fail(std::istream &in)
Check for stream state.
Definition: JParser.hh:98
bool is_valid() const
Check validity of this addressable class.
Definition: JRootClass.hh:471
JRootAddressableClass find(const char *const name) const
Find addressable base class or data member with given name within current class.
Definition: JRootClass.hh:483

◆ getObject() [1/6]

template<class T >
JRootReader& JROOT::JRootReader::getObject ( T &  object)
inlineinherited

Read object.

Parameters
objectobject
Returns
this ROOT reader

Definition at line 158 of file JRootStreamer.hh.

159  {
160  return this->getObject(object, JBool<JStreamAvailable<T>::has_istream>());
161  }
Test availability of stream operators.
Auxiliary template class for type bool.
Definition: JBool.hh:21

◆ getObject() [2/6]

JRootReader& JROOT::JRootReader::getObject ( const JRootReadableClass cls)
inlineinherited

Read ROOT class.

Parameters
clsROOT class
Returns
this ROOT reader

Definition at line 170 of file JRootStreamer.hh.

171  {
172  if (cls.is_valid()) {
173 
174  JRootDictionary_t::const_iterator i = this->getDictionary().find(cls.getTypename());
175 
176  if (i != this->getDictionary().end()) {
177 
178  i->second->getObject(*this, cls.getAddress());
179 
180  } else if (cls.getClass() != NULL) {
181 
182  if (cls.getClass()->GetListOfBases() != NULL) {
183 
184  std::unique_ptr<TIterator> i(cls.getClass()->GetListOfBases()->MakeIterator());
185 
186  for (const TBaseClass* p; (p = (const TBaseClass*) i->Next()) != NULL && (bool) (*this); ) {
187  this->getObject(cls.get(*p));
188  }
189  }
190 
191  if (cls.getClass()->GetListOfDataMembers() != NULL) {
192 
193  std::unique_ptr<TIterator> i(cls.getClass()->GetListOfDataMembers()->MakeIterator());
194 
195  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL && (bool) (*this); ) {
196  this->getObject(cls.get(*p));
197  }
198  }
199  }
200  }
201 
202  return *this;
203  }
const JRootDictionary_t & getDictionary() const
Get dictionary.
pointer_type getAddress() const
Get address.
Definition: JRootClass.hh:460
JRootAddressableClass get(const TDataMember &data_member) const
Get addressable class of given data member.
Definition: JRootClass.hh:495
TClass * getClass() const
Get class.
Definition: JRootClass.hh:194
const char * getTypename() const
Get type name.
Definition: JRootClass.hh:205

◆ getObject() [3/6]

JRootReader& JROOT::JRootReader::getObject ( JRootReadableClass cls)
inlineinherited

Read ROOT class.

Parameters
clsROOT class
Returns
this ROOT reader

Definition at line 212 of file JRootStreamer.hh.

213  {
214  return getObject(const_cast<const JRootReadableClass&>(cls));
215  }

◆ getObject() [4/6]

template<class T >
JRootReader& JROOT::JRootReader::getObject ( T &  object,
const JBool< true > &  option 
)
inlineprivateinherited

Read object.

Parameters
objectobject
optiontrue
Returns
this ROOT reader

Definition at line 226 of file JRootStreamer.hh.

227  {
228  *this >> object;
229 
230  return *this;
231  }

◆ getObject() [5/6]

template<class T >
JRootReader& JROOT::JRootReader::getObject ( T &  object,
const JBool< false > &  option 
)
inlineprivateinherited

Read object.

Parameters
objectobject
optionfalse
Returns
this ROOT reader

Definition at line 242 of file JRootStreamer.hh.

243  {
244  return this->getObject(JRootReadableClass(object));
245  }

◆ getObject() [6/6]

template<class JElement_t , class JAllocator_t >
JRootReader& JROOT::JRootReader::getObject ( std::vector< JElement_t, JAllocator_t > &  object,
const JBool< false > &  option 
)
inlineprivateinherited

Read object.

Parameters
objectobject
optionfalse
Returns
this ROOT reader

Definition at line 256 of file JRootStreamer.hh.

257  {
258  int n = 0;
259 
260  this->getObject(n);
261 
262  for (JElement_t element; n != 0 && this->getObject(element); --n) {
263  object.push_back(element);
264  }
265 
266  return *this;
267  }
const int n
Definition: JPolint.hh:786

◆ getInstance()

template<class T >
static data_type& JLANG::JSingleton< T >::getInstance ( )
inlinestaticinherited

Get unique instance of template class.

Returns
object

Definition at line 27 of file JSingleton.hh.

28  {
29  static data_type value;
30 
31  return value;
32  }

Member Data Documentation

◆ object

template<class T >
T JDATABASE::JDBReader< T >::object
private

internal value

Definition at line 173 of file JDBReader.hh.

◆ value

template<class T >
T JDATABASE::JDBReader< T >::value
private

default value

Definition at line 174 of file JDBReader.hh.

◆ columns

template<class T >
std::vector<JROOT::JRootReadableClass> JDATABASE::JDBReader< T >::columns
private

field count -> data member

Definition at line 176 of file JDBReader.hh.

◆ dictionary

const JRootDictionary_t& JROOT::JRootReader::dictionary
privateinherited

Definition at line 270 of file JRootStreamer.hh.

◆ __from

std::ios& JLANG::JStreamState::__from
privateinherited

Definition at line 67 of file JStreamState.hh.

◆ __to

std::ios& JLANG::JStreamState::__to
privateinherited

Definition at line 68 of file JStreamState.hh.


The documentation for this struct was generated from the following file: