Jpp
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | 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

Classes

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

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...
 
JRootWriterput (const JRootWritableClass &cls)
 Write object according equation format. More...
 
JRootWriterput (JRootWritableClass &cls)
 Write object according equation format. More...
 
template<class T >
JRootWriterputObject (const T &object)
 Write object. More...
 
JRootWriterput (const std::string &prefix, const JRootWritableClass &cls, bool eol)
 ROOT class output. More...
 
JRootWriterputObject (const JRootWritableClass &cls)
 ROOT class output. More...
 
template<class T >
JRootWriterput (const std::string &key, const T &value)
 Write given key and value according equation format. More...
 

Static Public Member Functions

template<class T >
static JRootWriterputObject (JRootWriter &writer, const T &object)
 Write object. More...
 
template<class T >
static JRootWriterput (JRootWriter &writer, const std::string &key, const T &value)
 Write given key and value according equation format. More...
 

Protected Member Functions

template<class T >
JRootWriterput (const std::string &key, const T &value, const JBool< true > option)
 Write given key and value according equation format. More...
 
template<class T >
JRootWriterput (const std::string &key, const T &value, const JBool< false > option)
 Write given key and value according equation format. More...
 
template<class JElement_t , class JAllocator_t >
JRootWriterput (const std::string &key, const std::vector< JElement_t, JAllocator_t > &value, const JBool< false > option)
 Write given key and value according equation format. More...
 
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...
 

Protected Attributes

const JRootDictionary_tdictionary
 

Private Attributes

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

Detailed Description

Implementation for ASCII output of objects with ROOT dictionary.

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

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

and method JRootReader::putObject 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 332 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 390 of file JRootStreamer.hh.

392  :
393  std::ostream(out.rdbuf()),
394  JStreamState(out, static_cast<std::ostream&>(*this)),
396  {
397  imbue(std::locale(out.getloc(), new JLANG::JEquationFacet(parameters)));
398 
399  flags (out.flags());
400  width (out.width());
401  precision(out.precision());
402  }

Member Function Documentation

◆ getDictionary()

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

Get dictictionary.

Returns
dictionary

Definition at line 410 of file JRootStreamer.hh.

411  {
412  return dictionary;
413  }

◆ putObject() [1/6]

template<class T >
static JRootWriter& JROOT::JRootWriter::putObject ( JRootWriter writer,
const T &  object 
)
inlinestatic

Write object.

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

Parameters
writerROOT writer
objectobject
Returns
ROOT writer

Definition at line 427 of file JRootStreamer.hh.

428  {
429  return JRootWriter::JHelper<T>::putObject(writer, object);
430  }

◆ put() [1/9]

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

Write given key and value according equation format.

Parameters
writerROOT writer
keykey
valuevalue
Returns
ROOT writer

Definition at line 442 of file JRootStreamer.hh.

443  {
444  return JRootWriter::JHelper<T>::put(writer, key, value);
445  }

◆ put() [2/9]

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 455 of file JRootStreamer.hh.

456  {
457  return this->put(JRootWritableClass(object));
458  }

◆ put() [3/9]

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

Write object according equation format.

Parameters
clsROOT class
Returns
this ROOT writer

Definition at line 467 of file JRootStreamer.hh.

468  {
469  return this->put("", cls, false);
470  }

◆ put() [4/9]

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

Write object according equation format.

Parameters
clsROOT class
Returns
this ROOT writer

Definition at line 479 of file JRootStreamer.hh.

480  {
481  return this->put(const_cast<const JRootWritableClass&>(cls));
482  }

◆ putObject() [2/6]

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

Write object.

Parameters
objectobject
Returns
this ROOT writer

Definition at line 492 of file JRootStreamer.hh.

493  {
494  return this->putObject(object, JBool<JStreamAvailable<T>::has_ostream>());
495  }

◆ put() [5/9]

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

ROOT class output.

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

Definition at line 506 of file JRootStreamer.hh.

507  {
508  using namespace std;
509  using namespace JLANG;
510 
511  if (cls.is_valid()) {
512 
513  const JEquationFacet& facet = use_facet<JEquationFacet>(this->getloc());
514 
515  JRootDictionary_t::const_iterator i = this->getDictionary().find(cls.getTypename());
516 
517  if (i != this->getDictionary().end()) {
518 
519  i->second->put(*this, prefix, cls.getAddress());
520 
521  } else if (eol) {
522 
523  *this << prefix;
524  *this << separator;
525 
526  this->putObject(cls);
527 
528  *this << end_of_line;
529 
530  } else if (cls.getClass() != NULL) {
531 
532  if (cls.getClass()->GetListOfBases() != NULL) {
533 
534  TIterator* i = cls.getClass()->GetListOfBases()->MakeIterator();
535 
536  for (const TBaseClass* p; (p = (const TBaseClass*) i->Next()) != NULL; ) {
537  this->put(prefix, cls.get(*p), false);
538  }
539  }
540 
541  if (cls.getClass()->GetListOfDataMembers() != NULL) {
542 
543  TIterator* i = cls.getClass()->GetListOfDataMembers()->MakeIterator();
544 
545  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
546  if (!JRootClass::is_static(*p)) {
547  this->put(facet.getPrefix(prefix,p->GetName()), cls.get(*p), false);
548  }
549  }
550  }
551  }
552  }
553 
554  return *this;
555  }

◆ putObject() [3/6]

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

ROOT class output.

Parameters
clsROOT class
Returns
object output

Definition at line 564 of file JRootStreamer.hh.

565  {
566  using namespace std;
567 
568  if (cls.is_valid()) {
569 
570  JRootDictionary_t::const_iterator i = this->getDictionary().find(cls.getTypename());
571 
572  if (i != this->getDictionary().end()) {
573 
574  i->second->putObject(*this, cls.getAddress());
575 
576  } else if (cls.getClass() != NULL) {
577 
578  if (cls.getClass()->GetListOfBases() != NULL) {
579 
580  TIterator* i = cls.getClass()->GetListOfBases()->MakeIterator();
581 
582  for (const TBaseClass* p; (p = (const TBaseClass*) i->Next()) != NULL; ) {
583  this->putObject(cls.get(*p));
584  }
585  }
586 
587  if (cls.getClass()->GetListOfDataMembers() != NULL) {
588 
589  TIterator* i = cls.getClass()->GetListOfDataMembers()->MakeIterator();
590 
591  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
592  if (!JRootClass::is_static(*p)) {
593  this->putObject(cls.get(*p));
594  }
595  }
596  }
597  }
598  }
599 
600  return *this;
601  }

◆ put() [6/9]

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 612 of file JRootStreamer.hh.

613  {
614  return this->put(key, value, JLANG::JBool<JStreamAvailable<T>::has_ostream>());
615  }

◆ put() [7/9]

template<class T >
JRootWriter& JROOT::JRootWriter::put ( const std::string &  key,
const T &  value,
const JBool< true >  option 
)
inlineprotected

Write given key and value according equation format.

Parameters
keykey
valuevalue
optiontrue
Returns
this ROOT writer

Definition at line 627 of file JRootStreamer.hh.

628  {
629  using namespace JLANG;
630 
631  *this << key;
632  *this << separator;
633  *this << white_space;
634  *this << value;
635  *this << end_of_line;
636 
637  return *this;
638  }

◆ put() [8/9]

template<class T >
JRootWriter& JROOT::JRootWriter::put ( const std::string &  key,
const T &  value,
const JBool< false >  option 
)
inlineprotected

Write given key and value according equation format.

Parameters
keykey
valuevalue
optionfalse
Returns
this ROOT writer

Definition at line 650 of file JRootStreamer.hh.

651  {
652  using namespace JLANG;
653 
654  *this << key;
655  *this << separator;
656 
657  this->putObject(value);
658 
659  *this << end_of_line;
660 
661  return *this;
662  }

◆ put() [9/9]

template<class JElement_t , class JAllocator_t >
JRootWriter& JROOT::JRootWriter::put ( const std::string &  key,
const std::vector< JElement_t, JAllocator_t > &  value,
const JBool< false >  option 
)
inlineprotected

Write given key and value according equation format.

Parameters
keykey
valuevalue
optionfalse
Returns
this ROOT writer

Definition at line 674 of file JRootStreamer.hh.

675  {
676  for (typename std::vector<JElement_t, JAllocator_t>::const_iterator i = value.begin(); i != value.end(); ++i) {
677  this->put(key, *i);
678  }
679 
680  return *this;
681  }

◆ putObject() [4/6]

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

Write object.

Parameters
objectobject
optiontrue
Returns
this ROOT writer

Definition at line 692 of file JRootStreamer.hh.

693  {
694  using namespace JLANG;
695 
696  *this << white_space;
697  *this << object;
698 
699  return *this;
700  }

◆ putObject() [5/6]

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

Write object.

Parameters
objectobject
optionfalse
Returns
this ROOT writer

Definition at line 711 of file JRootStreamer.hh.

712  {
713  return this->putObject(JRootWritableClass(object));
714  }

◆ putObject() [6/6]

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

Write object.

Parameters
objectobject
optionfalse
Returns
this ROOT writer

Definition at line 725 of file JRootStreamer.hh.

726  {
727  this->putObject(object.size());
728 
729  for (typename std::vector<JElement_t, JAllocator_t>::const_iterator i = object.begin(); i != object.end(); ++i) {
730  this->putObject(*i);
731  }
732 
733  return *this;
734  }

Member Data Documentation

◆ dictionary

const JRootDictionary_t& JROOT::JRootWriter::dictionary
protected

Definition at line 737 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::JRootWriter::dictionary
const JRootDictionary_t & dictionary
Definition: JRootStreamer.hh:737
JROOT::JRootAddressableClass::is_valid
bool is_valid() const
Check validity of this addressable class.
Definition: JRootClass.hh:459
JROOT::JRootWriter::getDictionary
const JRootDictionary_t & getDictionary() const
Get dictictionary.
Definition: JRootStreamer.hh:410
JROOT::JRootAddressableClass::getAddress
pointer_type getAddress() const
Get address.
Definition: JRootClass.hh:448
JROOT::JRootWritableClass
ROOT class for writing object.
Definition: JRootClass.hh:586
JROOT::JRootClass::getClass
TClass * getClass() const
Get class.
Definition: JRootClass.hh:181
JLANG::end_of_line
static const JLANG::JEndOfLine end_of_line
Print end of line.
Definition: JEquationFacet.hh:568
std::vector
Definition: JSTDTypes.hh:12
JROOT::JRootClass::is_static
static bool is_static(const TDataMember &data_member)
Check if data member is static.
Definition: JRootClass.hh:124
JLANG::white_space
std::ostream & white_space(std::ostream &out)
Print white space.
Definition: JEquationFacet.hh:511
JROOT::JRootAddressableClass::get
JRootAddressableClass get(const TDataMember &data_member) const
Get addressable class of given data member.
Definition: JRootClass.hh:481
JROOT::JRootWriter::JDefaultHelper::putObject
static JRootWriter & putObject(JRootWriter &writer, const T &object)
Write object.
Definition: JRootStreamer.hh:351
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
JLANG::JBool
Auxiliary template class for type bool.
Definition: JBool.hh:20
JROOT::JRootClass::getTypename
const char * getTypename() const
Get type name.
Definition: JRootClass.hh:192
JLANG::separator
std::ostream & separator(std::ostream &out)
Print separator.
Definition: JEquationFacet.hh:551
std
Definition: jaanetDictionary.h:36
JROOT::JRootWriter::JDefaultHelper::put
static JRootWriter & put(JRootWriter &writer, const std::string &key, const T &value)
Write given key and value according equation format.
Definition: JRootStreamer.hh:365
JLANG
Auxiliary classes and methods for language specific functionality.
Definition: JAbstractClass.hh:10
JROOT::JRootWriter::put
static JRootWriter & put(JRootWriter &writer, const std::string &key, const T &value)
Write given key and value according equation format.
Definition: JRootStreamer.hh:442
JROOT::JRootWriter::putObject
static JRootWriter & putObject(JRootWriter &writer, const T &object)
Write object.
Definition: JRootStreamer.hh:427
JLANG::JEquationFacet::getPrefix
const std::string getPrefix(const std::string &prefix, const std::string &name) const
Get combined prefix for output.
Definition: JEquationFacet.hh:118
JLANG::JStreamState::JStreamState
JStreamState(std::ostream &from, std::ostream &to)
Constructor.
Definition: JStreamState.hh:32