BinsBaseXML.cxx
Go to the documentation of this file.
1 
12 // for truncation warning
13 #ifdef _MSC_VER
14 #include "msdevstudio/MSconfig.h"
15 #endif
16 
17 #include "BinsBaseXML.h"
18 
19 #include "BinnerAxisXML.h"
20 #include "XmlElement.h"
21 
22 #include "binners/BinsBase.h"
23 #include "binners/BinsFactory.h"
24 
25 #include <cassert>
26 
27 using std::list;
28 using std::string;
29 
30 namespace hippodraw {
31 
33  : BaseXML ( "BinsBase", controller ),
34  m_axis ( "axis" )
35 {
36  m_binnerXML = new BinnerAxisXML ( controller );
37 }
38 
41 {
42  delete m_binnerXML;
43 }
44 
45 XmlElement *
47 createElement ( const BinsBase & bins )
48 {
50  const string & type = bins.name();
51  tag->setAttribute ( m_type, type );
52 
53  createChildren ( *tag, bins );
54 
55  return tag;
56 }
57 
58 
59 void
61 createChildren ( XmlElement & tag, const BinsBase & bins )
62 {
63  const BinnerAxis * binner = bins.getBinnerOn ( Axes::X );
64  XmlElement * element = m_binnerXML->createElement ( *binner );
65  string axis ( "X" );
66  element->setAttribute ( m_axis, axis );
67  tag.appendChild ( *element );
68  delete element;
69 
70  int number = bins.getNumberOfAxes ();
71  if ( number < 2 ) return;
72 
73  binner = bins.getBinnerOn ( Axes::Y );
74  element = m_binnerXML->createElement ( *binner );
75  axis = "Y";
76  element->setAttribute ( m_axis, axis );
77  tag.appendChild ( *element );
78  delete element;
79 }
80 
81 BinsBase *
83 createObject ( const XmlElement * binsbase )
84 {
85  string type;
86  bool ok = binsbase->attribute ( m_type, type );
87  assert ( ok );
88 
89  BinsFactory * factory = BinsFactory::instance ();
90  BinsBase * bins = factory->create ( type );
91 
92  list < XmlElement * > nodelist;
93  m_binnerXML->fillNodeList ( binsbase, nodelist );
94 
95  list < XmlElement * > :: const_iterator first = nodelist.begin();
96  while ( first != nodelist.end() ) {
97  XmlElement * element = *first++;
98  BinnerAxis * binner = m_binnerXML->createObject ( element );
99  string axis;
100  bool ok = element->attribute ( m_axis, axis );
101  assert ( ok );
102 
103  Axes::Type type = axis == "X" ? Axes::X : Axes::Y;
104  bins->setBinnerOn ( binner, type );
105  }
106 
107  return bins;
108 }
109 
110 } // namespace hippodraw
111 
XmlElement * createElement()
Creates a new element node.
Definition: BaseXML.cxx:43
const std::string & name() const
Returns the name of the Bins container object.
Definition: BinsBase.cxx:54
BinnerAxisXML class interface.
Type * create(const std::string &name)
Creates a new object from a prototype named name.
Definition: Factory.h:160
virtual bool attribute(const std::string &name, bool &value) const =0
Sets value to the attribute name&#39;s value.
A Factory singleton class for creating objects whose class derives from BinsBase. ...
Definition: BinsFactory.h:31
virtual const BinnerAxis * getBinnerOn(hippodraw::Axes::Type axis) const =0
Returns the BinnerAxis object used by this object.
A pure virtual base class of XML element wrapper.
Definition: XmlElement.h:30
void fillNodeList(const XmlElement *element, std::list< XmlElement * > &nodelist)
Fills the nodelist with immediate child nodes of element with nodes that can be handled by this objec...
Definition: BaseXML.cxx:58
XmlElement * createElement(const BinnerAxis &binner)
Returns a newly created XmlElement with attributes set for binner.
A class XML creation and parsing of XmlElement for BinnerAxis classes.
Definition: BinnerAxisXML.h:28
std::string m_axis
The attribute name for the axis of the BinnerAxisXML element.
Definition: BinsBaseXML.h:35
BinsBaseXML class interface.
hippodraw::BinsBase class interface
bool ok
Definition: CanvasView.cxx:163
PyArray_TYPES type(numeric::array arr)
Definition: num_util.cpp:249
BinnerAxisXML * m_binnerXML
The BinsBaseXML object used by this object.
Definition: BinsBaseXML.h:38
void createChildren(XmlElement &tag, const BinsBase &bins)
Creates the child XML elements of this element.
Definition: BinsBaseXML.cxx:61
virtual void appendChild(const XmlNode &child)=0
Appends a child element to the element.
The base class for the BinnerAxis hierarchy.
Definition: BinnerAxis.h:35
static BinsFactory * instance()
Returns a pointer to the singleton instance.
Definition: BinsFactory.cxx:33
XmlElement class interface.
~BinsBaseXML()
The destructor.
Definition: BinsBaseXML.cxx:40
BinsBaseXML(XmlController *)
A default constructor for avoiding creation except by itself or with derived classes.
Definition: BinsBaseXML.cxx:32
virtual void setBinnerOn(BinnerAxis *, hippodraw::Axes::Type axis)=0
Sets the bin calculator on specified axis.
const std::string m_type
The attribute name for the type of object.
Definition: BaseXML.h:54
virtual BinsBase * createObject(const XmlElement *element)
Creates an object derived from BinsBaseBase.
Definition: BinsBaseXML.cxx:83
A base class of XML element controllers.
Definition: BaseXML.h:35
virtual int getNumberOfAxes() const =0
Returns the number of axes handled by the BinsBase derived class.
A base class that is the interface between GUI and the XML serialization and deserialization.
Definition: XmlController.h:53
virtual BinnerAxis * createObject(const XmlElement *element)
Creates an object derived from BinnerAxis.
Type
Axes constants.
Definition: AxesType.h:31
The base class for the binner hierarchy.
Definition: BinsBase.h:33
virtual void setAttribute(const std::string &name, bool value)=0
Sets attribute named name to the int value value.

Generated for HippoDraw Class Library by doxygen