Jpp  19.1.0
the software that should make you happy
Public Member Functions | Private Member Functions | Private Attributes | List of all members
JROOT::JRootWriter Class Reference

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

#include <JRootStreamer.hh>

Inheritance diagram for JROOT::JRootWriter:
JLANG::JStreamState JAANET::JHeadWriter

Public Member Functions

 JRootWriter (std::ostream &out, const JEquationParameters &parameters, const JRootDictionary_t &dictionary)
 Constructor. More...
 
const JRootDictionary_tgetDictionary () const
 Get dictictionary. More...
 
template<class T >
JRootWriterput (const T &object)
 Write object according equation format. More...
 
template<class T >
JRootWriterput (const std::string &key, const T &value)
 Write given key and value according equation format. More...
 
JRootWriterput (const JRootWritableClass &cls)
 Write ROOT class according equation format. More...
 
JRootWriterput (JRootWritableClass &cls)
 Write ROOT class according equation format. More...
 
JRootWriterput (const std::string &prefix, const JRootWritableClass &cls, bool eol)
 Write ROOT class according equation format. More...
 
virtual JRootWriterput (const JEquation &equation)
 Write equation. More...
 
template<class T >
JRootWriterputObject (const T &object)
 Write object. More...
 
JRootWriterputObject (const JRootWritableClass &cls)
 Write ROOT class. More...
 

Private Member Functions

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

Private Attributes

const JRootDictionary_tdictionary
 
std::ios & __from
 
std::ios & __to
 

Detailed Description

Implementation for ASCII output of objects with ROOT dictionary.

The method JRootWriter::put is compatible with equation formatting, i.e:

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

In this, the key corresponds to the name of a data member which can be recursively parsed via a division character.

The method JRootWriter::putObject relates to simple formatting, i.e:

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

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

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

Definition at line 292 of file JRootStreamer.hh.

Constructor & Destructor Documentation

◆ JRootWriter()

JROOT::JRootWriter::JRootWriter ( std::ostream &  out,
const JEquationParameters parameters,
const JRootDictionary_t dictionary 
)
inline

Constructor.

Parameters
outoutput stream
parametersequation parameters
dictionarydictionary

Definition at line 304 of file JRootStreamer.hh.

306  :
307  std::ostream(out.rdbuf()),
308  JStreamState(out, static_cast<std::ostream&>(*this)),
310  {
311  imbue(std::locale(out.getloc(), new JLANG::JEquationFacet(parameters)));
312 
313  flags (out.flags());
314  width (out.width());
315  precision(out.precision());
316  }
Facet class to specify parsing of equations in currect locale (see class JLANG::JEquation).
JStreamState(std::ostream &from, std::ostream &to)
Constructor.
Definition: JStreamState.hh:32
const JRootDictionary_t & dictionary

Member Function Documentation

◆ getDictionary()

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

Get dictictionary.

Returns
dictionary

Definition at line 324 of file JRootStreamer.hh.

325  {
326  return dictionary;
327  }

◆ put() [1/6]

template<class T >
JRootWriter& JROOT::JRootWriter::put ( const T &  object)
inline

Write object according equation format.

Parameters
objectobject
Returns
this ROOT writer

Definition at line 337 of file JRootStreamer.hh.

338  {
339  return this->put(JRootWritableClass(object));
340  }
JRootWriter & put(const T &object)
Write object according equation format.
ROOT class for writing object.
Definition: JRootClass.hh:604

◆ put() [2/6]

template<class T >
JRootWriter& JROOT::JRootWriter::put ( const std::string &  key,
const T &  value 
)
inline

Write given key and value according equation format.

Parameters
keykey
valuevalue
Returns
this ROOT writer

Definition at line 351 of file JRootStreamer.hh.

352  {
353  using namespace std;
354  using namespace JPP;
355 
356  ostringstream os;
357 
358  {
359  JRedirectStream redirect(*this, os);
360 
361  this->putObject(value);
362  }
363 
364  return this->put(JEquation(key, os.str()));
365  }
General purpose equation class.
Definition: JEquation.hh:47
This class can be used to temporarily redirect one output (input) stream to another output (input) st...
JRootWriter & putObject(const T &object)
Write object.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JSTDTypes.hh:14

◆ put() [3/6]

JRootWriter& JROOT::JRootWriter::put ( const JRootWritableClass cls)
inline

Write ROOT class according equation format.

Parameters
clsROOT class
Returns
this ROOT writer

Definition at line 374 of file JRootStreamer.hh.

375  {
376  return this->put("", cls, false);
377  }

◆ put() [4/6]

JRootWriter& JROOT::JRootWriter::put ( JRootWritableClass cls)
inline

Write ROOT class according equation format.

Parameters
clsROOT class
Returns
this ROOT writer

Definition at line 386 of file JRootStreamer.hh.

387  {
388  return this->put(const_cast<const JRootWritableClass&>(cls));
389  }

◆ put() [5/6]

JRootWriter& JROOT::JRootWriter::put ( const std::string &  prefix,
const JRootWritableClass cls,
bool  eol 
)
inline

Write ROOT class according equation format.

Parameters
prefixprefix
clsROOT class
eolend-of-line
Returns
object output

Definition at line 400 of file JRootStreamer.hh.

401  {
402  using namespace std;
403  using namespace JPP;
404 
405  if (cls.is_valid()) {
406 
407  const JEquationFacet& facet = use_facet<JEquationFacet>(this->getloc());
408 
409  JRootDictionary_t::const_iterator i = this->getDictionary().find(cls.getTypename());
410 
411  if (i != this->getDictionary().end()) {
412 
413  i->second->put(*this, prefix, cls.getAddress());
414 
415  } else if (eol) {
416 
417  ostringstream os;
418 
419  {
420  JRedirectStream redirect(*this, os);
421 
422  this->putObject(cls);
423  }
424 
425  this->put(JEquation(prefix, os.str()));
426 
427  } else if (cls.getClass() != NULL) {
428 
429  if (cls.getClass()->GetListOfBases() != NULL) {
430 
431  std::unique_ptr<TIterator> i(cls.getClass()->GetListOfBases()->MakeIterator());
432 
433  for (const TBaseClass* p; (p = (const TBaseClass*) i->Next()) != NULL; ) {
434  this->put(prefix, cls.get(*p), false);
435  }
436  }
437 
438  if (cls.getClass()->GetListOfDataMembers() != NULL) {
439 
440  std::unique_ptr<TIterator> i(cls.getClass()->GetListOfDataMembers()->MakeIterator());
441 
442  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
443  if (!JRootClass::is_static(*p)) {
444  this->put(facet.getPrefix(prefix,p->GetName()), cls.get(*p), false);
445  }
446  }
447  }
448  }
449  }
450 
451  return *this;
452  }
const std::string getPrefix(const std::string &prefix, const std::string &name) const
Get combined prefix for output.
const JRootDictionary_t & getDictionary() const
Get dictictionary.
bool is_valid() const
Check validity of this addressable class.
Definition: JRootClass.hh:471
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
static bool is_static(const TDataMember &data_member)
Check if data member is static.
Definition: JRootClass.hh:128
TClass * getClass() const
Get class.
Definition: JRootClass.hh:194
const char * getTypename() const
Get type name.
Definition: JRootClass.hh:205

◆ put() [6/6]

virtual JRootWriter& JROOT::JRootWriter::put ( const JEquation equation)
inlinevirtual

Write equation.

Parameters
equationequation
Returns
this ROOT writer

Reimplemented in JAANET::JHeadWriter.

Definition at line 461 of file JRootStreamer.hh.

462  {
463  *this << equation;
464 
465  return *this;
466  }

◆ putObject() [1/5]

template<class T >
JRootWriter& JROOT::JRootWriter::putObject ( const T &  object)
inline

Write object.

Parameters
objectobject
Returns
this ROOT writer

Definition at line 476 of file JRootStreamer.hh.

477  {
478  return this->putObject(object, JBool<JStreamAvailable<T>::has_ostream>());
479  }
Test availability of stream operators.
Auxiliary template class for type bool.
Definition: JBool.hh:21

◆ putObject() [2/5]

JRootWriter& JROOT::JRootWriter::putObject ( const JRootWritableClass cls)
inline

Write ROOT class.

Parameters
clsROOT class
Returns
object output

Definition at line 488 of file JRootStreamer.hh.

489  {
490  using namespace std;
491 
492  if (cls.is_valid()) {
493 
494  JRootDictionary_t::const_iterator i = this->getDictionary().find(cls.getTypename());
495 
496  if (i != this->getDictionary().end()) {
497 
498  i->second->putObject(*this, cls.getAddress());
499 
500  } else if (cls.getClass() != NULL) {
501 
502  if (cls.getClass()->GetListOfBases() != NULL) {
503 
504  std::unique_ptr<TIterator> i(cls.getClass()->GetListOfBases()->MakeIterator());
505 
506  for (const TBaseClass* p; (p = (const TBaseClass*) i->Next()) != NULL; ) {
507  this->putObject(cls.get(*p));
508  }
509  }
510 
511  if (cls.getClass()->GetListOfDataMembers() != NULL) {
512 
513  std::unique_ptr<TIterator> i(cls.getClass()->GetListOfDataMembers()->MakeIterator());
514 
515  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
516  if (!JRootClass::is_static(*p)) {
517  this->putObject(cls.get(*p));
518  }
519  }
520  }
521  }
522  }
523 
524  return *this;
525  }

◆ putObject() [3/5]

template<class T >
JRootWriter& JROOT::JRootWriter::putObject ( const T &  object,
const JBool< true > &  option 
)
inlineprivate

Write object.

Parameters
objectobject
optiontrue
Returns
this ROOT writer

Definition at line 536 of file JRootStreamer.hh.

537  {
538  using namespace JPP;
539 
540  *this << white_space;
541  *this << object;
542 
543  return *this;
544  }
std::ostream & white_space(std::ostream &out)
Print white space.

◆ putObject() [4/5]

template<class T >
JRootWriter& JROOT::JRootWriter::putObject ( const T &  object,
const JBool< false > &  option 
)
inlineprivate

Write object.

Parameters
objectobject
optionfalse
Returns
this ROOT writer

Definition at line 555 of file JRootStreamer.hh.

556  {
557  return this->putObject(JRootWritableClass(object));
558  }

◆ putObject() [5/5]

template<class JElement_t , class JAllocator_t >
JRootWriter& JROOT::JRootWriter::putObject ( const std::vector< JElement_t, JAllocator_t > &  object,
const JBool< false >  option 
)
inlineprivate

Write object.

Parameters
objectobject
optionfalse
Returns
this ROOT writer

Definition at line 569 of file JRootStreamer.hh.

570  {
571  this->putObject(object.size());
572 
573  for (typename std::vector<JElement_t, JAllocator_t>::const_iterator i = object.begin(); i != object.end(); ++i) {
574  this->putObject(*i);
575  }
576 
577  return *this;
578  }

Member Data Documentation

◆ dictionary

const JRootDictionary_t& JROOT::JRootWriter::dictionary
private

Definition at line 581 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: