Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Member Functions | Static Public Member Functions | Public 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...
 
struct  JHelper< vector< JAANET::physics > >
 Specialisation of std::vector<JAANET::physics> for writing only first element. 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...
 
template<class T >
JRootWriterputObject (const T &object)
 Write object. More...
 
JRootWriterput (const std::string &prefix, const JRootClassWriter &cls, bool eol)
 ROOT class output. More...
 
JRootWriterputObject (const JRootClassWriter &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...
 
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...
 

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

Public Attributes

const JRootDictionary_tdictionary
 

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

Constructor & Destructor Documentation

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

Constructor.

Parameters
outoutput stream
parametersequation parameters
dictionarydictionary

Definition at line 387 of file JRootStreamer.hh.

389  :
390  std::ostream(out.rdbuf()),
391  JStreamState(out, static_cast<std::ostream&>(*this)),
392  dictionary(dictionary)
393  {
394  imbue(std::locale(out.getloc(), new JLANG::JEquationFacet(parameters)));
395  }
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

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

Get dictictionary.

Returns
dictionary

Definition at line 403 of file JRootStreamer.hh.

404  {
405  return dictionary;
406  }
const JRootDictionary_t & dictionary
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 420 of file JRootStreamer.hh.

421  {
422  return JRootWriter::JHelper<T>::putObject(writer, object);
423  }
static JRootWriter & putObject(JRootWriter &writer, const T &object)
Write object.
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 435 of file JRootStreamer.hh.

436  {
437  return JRootWriter::JHelper<T>::put(writer, key, value);
438  }
static JRootWriter & put(JRootWriter &writer, const std::string &key, const T &value)
Write given key and value according equation format.
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 448 of file JRootStreamer.hh.

449  {
450  return this->put("", JRootClassWriter(object), false);
451  }
ROOT class for writing object.
Definition: JRootClass.hh:568
static JRootWriter & put(JRootWriter &writer, const std::string &key, const T &value)
Write given key and value according equation format.
template<class T >
JRootWriter& JROOT::JRootWriter::putObject ( const T &  object)
inline

Write object.

Parameters
objectobject
Returns
this ROOT writer

Definition at line 461 of file JRootStreamer.hh.

462  {
463  return this->putObject(object, JBool<JRedirectAvailable<T>::has_ostream>());
464  }
Auxiliary template class for type bool.
Definition: JBool.hh:20
static JRootWriter & putObject(JRootWriter &writer, const T &object)
Write object.
Test availability of redirect operators.
JRootWriter& JROOT::JRootWriter::put ( const std::string &  prefix,
const JRootClassWriter cls,
bool  eol 
)
inline

ROOT class output.

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

Definition at line 475 of file JRootStreamer.hh.

476  {
477  using namespace std;
478  using namespace JLANG;
479 
480  if (cls.is_valid()) {
481 
482  const JEquationFacet& facet = use_facet<JEquationFacet>(this->getloc());
483 
484  JRootDictionary_t::const_iterator i = this->getDictionary().find(cls.getTypename());
485 
486  if (i != this->getDictionary().end()) {
487 
488  i->second->put(*this, prefix, cls.getAddress());
489 
490  } else if (eol) {
491 
492  *this << prefix;
493  *this << separator;
494 
495  this->putObject(cls);
496 
497  *this << end_of_line;
498 
499  } else if (cls.getClass() != NULL) {
500 
501  if (cls.getClass()->GetListOfBases() != NULL) {
502 
503  TIterator* i = cls.getClass()->GetListOfBases()->MakeIterator();
504 
505  for (const TBaseClass* p; (p = (const TBaseClass*) i->Next()) != NULL; ) {
506  this->put(prefix, cls.get(*p), false);
507  }
508  }
509 
510  if (cls.getClass()->GetListOfDataMembers() != NULL) {
511 
512  TIterator* i = cls.getClass()->GetListOfDataMembers()->MakeIterator();
513 
514  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
515  if (!JRootClass::is_static(*p)) {
516  this->put(facet.getPrefix(prefix,p->GetName()), cls.get(*p), false);
517  }
518  }
519  }
520  }
521  }
522 
523  return *this;
524  }
const JRootDictionary_t & getDictionary() const
Get dictictionary.
Facet class to specify parsing of equations in currect locale (see class JLANG::JEquation).
const char * getTypename() const
Get type name.
Definition: JRootClass.hh:178
const std::string getPrefix(const std::string &prefix, const std::string &name) const
Get combined prefix for output.
pointer_type getAddress() const
Get address.
Definition: JRootClass.hh:411
bool is_valid() const
Check validity of this addressable class.
Definition: JRootClass.hh:422
std::ostream & separator(std::ostream &out)
Print separator.
static JRootWriter & put(JRootWriter &writer, const std::string &key, const T &value)
Write given key and value according equation format.
JRootAddressableClass get(const TDataMember &data_member) const
Get addressable class of given data member.
Definition: JRootClass.hh:444
TClass * getClass() const
Get class.
Definition: JRootClass.hh:167
static const JLANG::JEndOfLine end_of_line
Print end of line.
static JRootWriter & putObject(JRootWriter &writer, const T &object)
Write object.
static bool is_static(const TDataMember &data_member)
Check if data member is static.
Definition: JRootClass.hh:122
JRootWriter& JROOT::JRootWriter::putObject ( const JRootClassWriter cls)
inline

ROOT class output.

Parameters
clsROOT class
Returns
object output

Definition at line 533 of file JRootStreamer.hh.

534  {
535  using namespace std;
536 
537  if (cls.is_valid()) {
538 
539  JRootDictionary_t::const_iterator i = this->getDictionary().find(cls.getTypename());
540 
541  if (i != this->getDictionary().end()) {
542 
543  i->second->putObject(*this, cls.getAddress());
544 
545  } else if (cls.getClass() != NULL) {
546 
547  if (cls.getClass()->GetListOfBases() != NULL) {
548 
549  TIterator* i = cls.getClass()->GetListOfBases()->MakeIterator();
550 
551  for (const TBaseClass* p; (p = (const TBaseClass*) i->Next()) != NULL; ) {
552  this->putObject(cls.get(*p));
553  }
554  }
555 
556  if (cls.getClass()->GetListOfDataMembers() != NULL) {
557 
558  TIterator* i = cls.getClass()->GetListOfDataMembers()->MakeIterator();
559 
560  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
561  if (!JRootClass::is_static(*p)) {
562  this->putObject(cls.get(*p));
563  }
564  }
565  }
566  }
567  }
568 
569  return *this;
570  }
const JRootDictionary_t & getDictionary() const
Get dictictionary.
const char * getTypename() const
Get type name.
Definition: JRootClass.hh:178
pointer_type getAddress() const
Get address.
Definition: JRootClass.hh:411
bool is_valid() const
Check validity of this addressable class.
Definition: JRootClass.hh:422
JRootAddressableClass get(const TDataMember &data_member) const
Get addressable class of given data member.
Definition: JRootClass.hh:444
TClass * getClass() const
Get class.
Definition: JRootClass.hh:167
static JRootWriter & putObject(JRootWriter &writer, const T &object)
Write object.
static bool is_static(const TDataMember &data_member)
Check if data member is static.
Definition: JRootClass.hh:122
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 581 of file JRootStreamer.hh.

582  {
583  return this->put(key, value, JLANG::JBool<JRedirectAvailable<T>::has_ostream>());
584  }
Auxiliary template class for type bool.
Definition: JBool.hh:20
static JRootWriter & put(JRootWriter &writer, const std::string &key, const T &value)
Write given key and value according equation format.
Test availability of redirect operators.
template<class T >
JRootWriter& JROOT::JRootWriter::put ( const std::string &  key,
const T &  value,
const JBool< true >  option 
)
inline

Write given key and value according equation format.

Parameters
keykey
valuevalue
optiontrue
Returns
this ROOT writer

Definition at line 596 of file JRootStreamer.hh.

597  {
598  using namespace JLANG;
599 
600  *this << key;
601  *this << separator;
602  *this << white_space;
603  *this << value;
604  *this << end_of_line;
605 
606  return *this;
607  }
std::ostream & white_space(std::ostream &out)
Print white space.
std::ostream & separator(std::ostream &out)
Print separator.
static const JLANG::JEndOfLine end_of_line
Print end of line.
template<class T >
JRootWriter& JROOT::JRootWriter::put ( const std::string &  key,
const T &  value,
const JBool< false >  option 
)
inline

Write given key and value according equation format.

Parameters
keykey
valuevalue
optionfalse
Returns
this ROOT writer

Definition at line 619 of file JRootStreamer.hh.

620  {
621  using namespace JLANG;
622 
623  *this << key;
624  *this << separator;
625 
626  this->putObject(value);
627 
628  *this << end_of_line;
629 
630  return *this;
631  }
std::ostream & separator(std::ostream &out)
Print separator.
static const JLANG::JEndOfLine end_of_line
Print end of line.
static JRootWriter & putObject(JRootWriter &writer, const T &object)
Write object.
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 
)
inline

Write given key and value according equation format.

Parameters
keykey
valuevalue
optionfalse
Returns
this ROOT writer

Definition at line 643 of file JRootStreamer.hh.

644  {
645  for (typename std::vector<JElement_t, JAllocator_t>::const_iterator i = value.begin(); i != value.end(); ++i) {
646  this->put(key, *i);
647  }
648 
649  return *this;
650  }
static JRootWriter & put(JRootWriter &writer, const std::string &key, const T &value)
Write given key and value according equation format.
template<class T >
JRootWriter& JROOT::JRootWriter::putObject ( const T &  object,
const JBool< true > &  option 
)
inline

Write object.

Parameters
objectobject
optiontrue
Returns
this ROOT writer

Definition at line 661 of file JRootStreamer.hh.

662  {
663  using namespace JLANG;
664 
665  *this << white_space;
666  *this << object;
667 
668  return *this;
669  }
std::ostream & white_space(std::ostream &out)
Print white space.
template<class T >
JRootWriter& JROOT::JRootWriter::putObject ( const T &  object,
const JBool< false > &  option 
)
inline

Write object.

Parameters
objectobject
optionfalse
Returns
this ROOT writer

Definition at line 680 of file JRootStreamer.hh.

681  {
682  return this->putObject(JRootClassWriter(object));
683  }
ROOT class for writing object.
Definition: JRootClass.hh:568
static JRootWriter & putObject(JRootWriter &writer, const T &object)
Write object.
template<class JElement_t , class JAllocator_t >
JRootWriter& JROOT::JRootWriter::putObject ( const std::vector< JElement_t, JAllocator_t > &  object,
const JBool< false >  option 
)
inline

Write object.

Parameters
objectobject
optionfalse
Returns
this ROOT writer

Definition at line 694 of file JRootStreamer.hh.

695  {
696  this->putObject(object.size());
697 
698  for (typename std::vector<JElement_t, JAllocator_t>::const_iterator i = object.begin(); i != object.end(); ++i) {
699  this->putObject(*i);
700  }
701 
702  return *this;
703  }
static JRootWriter & putObject(JRootWriter &writer, const T &object)
Write object.

Member Data Documentation

const JRootDictionary_t& JROOT::JRootWriter::dictionary

Definition at line 706 of file JRootStreamer.hh.


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