Jpp
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
JROOT::JRootReader Class Reference

Implementation for ASCII input of objects with ROOT dictionary. More...

#include <JRootStreamer.hh>

Inheritance diagram for JROOT::JRootReader:
JLANG::JStreamState

Classes

struct  JDefaultHelper
 Default helper class for formatting. More...
 
struct  JHelper
 Helper class for user formatting. More...
 

Public Member Functions

 JRootReader (std::istream &in, const JEquationParameters &parameters, const JRootDictionary_t &dictionary)
 Constructor. More...
 
const JRootDictionary_tgetDictionary () const
 Get dictionary. More...
 
template<class T >
JRootReaderget (T &object)
 Read object according equation format. More...
 
template<class T >
JRootReadergetObject (T &object)
 Read object. More...
 
JRootReaderget (const JRootReadableClass &cls)
 Read ROOT class according equation format. More...
 
JRootReadergetObject (const JRootReadableClass &cls)
 Read ROOT class. More...
 
JRootReadergetObject (JRootReadableClass &cls)
 Read ROOT class according equation format. More...
 

Static Public Member Functions

template<class T >
static JRootReadergetObject (JRootReader &reader, T &object)
 Read object. More...
 

Protected 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...
 

Protected Attributes

const JRootDictionary_tdictionary
 

Private Attributes

std::ios & __from
 
std::ios & __to
 

Detailed Description

Implementation for ASCII input of objects with ROOT dictionary.

The method JRootReader::get is compatible with equation formatting, i.e:

<key><separator><value>[<white space><value>]*<end of line>

and method JRootReader::getObject with simple formatting, i.e:

<value>[<white space><value>]*

The default format for input of std::vector<T> is

<number of elements>[<white space><value>]*

Definition at line 52 of file JRootStreamer.hh.

Constructor & Destructor Documentation

◆ JRootReader()

JROOT::JRootReader::JRootReader ( std::istream &  in,
const JEquationParameters parameters,
const JRootDictionary_t dictionary 
)
inline

Constructor.

Parameters
ininput stream
parametersequation parameters
dictionarydictionary

Definition at line 96 of file JRootStreamer.hh.

98  :
99  std::istream(in.rdbuf()),
100  JStreamState(in, static_cast<std::istream&>(*this)),
102  {
103  imbue(std::locale(in.getloc(), new JLANG::JEquationFacet(parameters)));
104  }

Member Function Documentation

◆ getDictionary()

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

Get dictionary.

Returns
dictionary

Definition at line 112 of file JRootStreamer.hh.

113  {
114  return dictionary;
115  }

◆ getObject() [1/7]

template<class T >
static JRootReader& JROOT::JRootReader::getObject ( JRootReader reader,
T &  object 
)
inlinestatic

Read object.

This method transfers the reading of the given object to the template JHelper class so that the default format can be changed through specialisation of this class.

Parameters
readerROOT reader
objectobject
Returns
ROOT reader

Definition at line 129 of file JRootStreamer.hh.

130  {
131  return JRootReader::JHelper<T>::getObject(reader, object);
132  }

◆ get() [1/2]

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

Read object according equation format.

Parameters
objectobject
Returns
this ROOT reader

Definition at line 142 of file JRootStreamer.hh.

143  {
144  return this->get(JRootReadableClass(object));
145  }

◆ getObject() [2/7]

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

Read object.

Parameters
objectobject
Returns
this ROOT reader

Definition at line 155 of file JRootStreamer.hh.

156  {
157  return this->getObject(object, JBool<JStreamAvailable<T>::has_istream>());
158  }

◆ get() [2/2]

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

Read ROOT class according equation format.

Parameters
clsROOT class
Returns
this ROOT reader

Definition at line 167 of file JRootStreamer.hh.

168  {
169  using namespace std;
170  using namespace JLANG;
171 
172  if (cls.is_valid()) {
173 
174  const JEquationFacet& facet = use_facet<JEquationFacet>(this->getloc());
175 
176  for (JEquation equation; *this >> equation; ) {
177 
178  const JRootReadableClass abc = cls.find(equation.getKey().c_str());
179 
180  bool okay = abc.is_valid();
181 
182  if (okay) {
183 
184  JRedirectString redirect(*this, equation.getValue());
185 
186  if (facet.isDivision (equation.getSeparator()))
187  this->get(abc);
188  else if (facet.isSeparator(equation.getSeparator()))
189  this->getObject(abc);
190  else
191  okay = false;
192 
193  okay &= (!this->fail() || this->eof());
194  }
195 
196  if (!okay) {
197  throw JException("Error parsing: " + equation.toString());
198  }
199  }
200  }
201 
202  return *this;
203  }

◆ getObject() [3/7]

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

Read ROOT class.

Parameters
clsROOT class
Returns
this ROOT reader

Definition at line 212 of file JRootStreamer.hh.

213  {
214  if (cls.is_valid()) {
215 
216  JRootDictionary_t::const_iterator i = this->getDictionary().find(cls.getTypename());
217 
218  if (i != this->getDictionary().end()) {
219 
220  i->second->getObject(*this, cls.getAddress());
221 
222  } else if (cls.getClass() != NULL) {
223 
224  if (cls.getClass()->GetListOfBases() != NULL) {
225 
226  TIterator* i = cls.getClass()->GetListOfBases()->MakeIterator();
227 
228  for (const TBaseClass* p; (p = (const TBaseClass*) i->Next()) != NULL && (bool) (*this); ) {
229  this->getObject(cls.get(*p));
230  }
231  }
232 
233  if (cls.getClass()->GetListOfDataMembers() != NULL) {
234 
235  TIterator* i = cls.getClass()->GetListOfDataMembers()->MakeIterator();
236 
237  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL && (bool) (*this); ) {
238  this->getObject(cls.get(*p));
239  }
240  }
241  }
242  }
243 
244  return *this;
245  }

◆ getObject() [4/7]

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

Read ROOT class according equation format.

Parameters
clsROOT class
Returns
this ROOT reader

Definition at line 254 of file JRootStreamer.hh.

255  {
256  return getObject(const_cast<const JRootReadableClass&>(cls));
257  }

◆ getObject() [5/7]

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

Read object.

Parameters
objectobject
optiontrue
Returns
this ROOT reader

Definition at line 269 of file JRootStreamer.hh.

270  {
271  *this >> object;
272 
273  return *this;
274  }

◆ getObject() [6/7]

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

Read object.

Parameters
objectobject
optionfalse
Returns
this ROOT reader

Definition at line 285 of file JRootStreamer.hh.

286  {
287  return this->getObject(JRootReadableClass(object));
288  }

◆ getObject() [7/7]

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

Read object.

Parameters
objectobject
optionfalse
Returns
this ROOT reader

Definition at line 299 of file JRootStreamer.hh.

300  {
301  int n = 0;
302 
303  this->getObject(n);
304 
305  for (JElement_t element; n != 0 && this->getObject(element); --n) {
306  object.push_back(element);
307  }
308 
309  return *this;
310  }

Member Data Documentation

◆ dictionary

const JRootDictionary_t& JROOT::JRootReader::dictionary
protected

Definition at line 313 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 class was generated from the following file:
JROOT::JRootAddressableClass::is_valid
bool is_valid() const
Check validity of this addressable class.
Definition: JRootClass.hh:459
JROOT::JRootReader::get
JRootReader & get(T &object)
Read object according equation format.
Definition: JRootStreamer.hh:142
JROOT::JRootAddressableClass::getAddress
pointer_type getAddress() const
Get address.
Definition: JRootClass.hh:448
JROOT::JRootClass::getClass
TClass * getClass() const
Get class.
Definition: JRootClass.hh:181
JLANG::JEquationParameters::isSeparator
bool isSeparator(const char c) const
Test for separator character.
Definition: JEquationParameters.hh:369
JLANG::JEquationParameters::isDivision
bool isDivision(const char c) const
Test for division character.
Definition: JEquationParameters.hh:390
JROOT::JRootReader::JDefaultHelper::getObject
static JRootReader & getObject(JRootReader &reader, T &object)
Read object.
Definition: JRootStreamer.hh:71
JTOOLS::n
const int n
Definition: JPolint.hh:628
JROOT::JRootReader::dictionary
const JRootDictionary_t & dictionary
Definition: JRootStreamer.hh:313
JROOT::JRootReader::getObject
static JRootReader & getObject(JRootReader &reader, T &object)
Read object.
Definition: JRootStreamer.hh:129
JROOT::JRootAddressableClass::get
JRootAddressableClass get(const TDataMember &data_member) const
Get addressable class of given data member.
Definition: JRootClass.hh:481
JLANG::JEquation
General purpose equation class.
Definition: JEquation.hh:47
JLANG::JRedirectString
This class can be used to temporarily redirect an input stream to an input string.
Definition: JRedirectString.hh:26
JLANG::JEquationFacet
Facet class to specify parsing of equations in currect locale (see class JLANG::JEquation).
Definition: JEquationFacet.hh:32
JStreamAvailable
Test availability of stream operators.
Definition: JStreamAvailable.hh:46
JROOT::JRootReader::getDictionary
const JRootDictionary_t & getDictionary() const
Get dictionary.
Definition: JRootStreamer.hh:112
JLANG::JBool
Auxiliary template class for type bool.
Definition: JBool.hh:20
JPARSER::fail
bool fail(std::istream &in)
Check for stream state.
Definition: JParser.hh:93
JROOT::JRootClass::getTypename
const char * getTypename() const
Get type name.
Definition: JRootClass.hh:192
std
Definition: jaanetDictionary.h:36
JROOT::JRootReadableClass
ROOT class for reading object.
Definition: JRootClass.hh:526
JLANG
Auxiliary classes and methods for language specific functionality.
Definition: JAbstractClass.hh:10
JLANG::JException
General exception.
Definition: JException.hh:40
JROOT::JRootAddressableClass::find
JRootAddressableClass find(const char *name) const
Find addressable base class or data member with given name within current class.
Definition: JRootClass.hh:470
JLANG::JStreamState::JStreamState
JStreamState(std::ostream &from, std::ostream &to)
Constructor.
Definition: JStreamState.hh:32