BinnerAxisXML.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 "BinnerAxisXML.h"
18 
19 #include "XmlElement.h"
20 
21 #include "binners/BinnerAxis.h"
23 
24 #include <cassert>
25 
26 using std::string;
27 
28 namespace hippodraw {
29 
31  : BaseXML ( "BinnerBase", controller ),
32  m_width ( "width" ),
33  m_high ( "high" ),
34  m_low ( "low" )
35 {
36 }
37 
38 XmlElement *
40 createElement ( const BinnerAxis & binner )
41 {
43  setAttributes ( tag, binner );
44 
45  return tag;
46 }
47 
48 void
50 setAttributes ( XmlElement * tag, const BinnerAxis & binner )
51 {
52  const string & type = binner.name();
53  tag->setAttribute ( m_type, type );
54 
55  const Range & range = binner.getRange ();
56  double high = range.high();
57  double low = range.low ();
58 
59  tag->setAttribute ( m_high, high );
60  tag->setAttribute ( m_low, low );
61 
62  double width = binner.getBinWidth ();
63  tag->setAttribute ( m_width, width );
64 }
65 
66 BinnerAxis *
68 createObject ( const XmlElement * element )
69 {
70  string type;
71  bool ok = element->attribute ( m_type, type );
72  assert ( ok );
73 
75  BinnerAxis * binner = factory->create ( type );
76 
77  double high = 1.0;
78  double low = 0.0;
79  ok = element->attribute ( m_high, high );
80  ok &= element->attribute ( m_low, low );
81  assert ( ok );
82  Range range ( low, high );
83  binner->setRange ( range, false );
84 
85  double width = -1.0;
86  ok = element->attribute ( m_width, width );
87  assert ( ok );
88  binner->setBinWidth ( width );
89 
90  return binner;
91 }
92 
93 } // namespace hippodraw
94 
XmlElement * createElement()
Creates a new element node.
Definition: BaseXML.cxx:43
std::string m_width
The attribute name for the width parameter of the binner.
Definition: BinnerAxisXML.h:37
void setAttributes(XmlElement *tag, const BinnerAxis &binner)
Sets the attributes of the elment.
BinnerAxisXML class interface.
Type * create(const std::string &name)
Creates a new object from a prototype named name.
Definition: Factory.h:160
double high() const
Returns the maximum of the range object.
Definition: Range.cxx:100
virtual bool attribute(const std::string &name, bool &value) const =0
Sets value to the attribute name&#39;s value.
const Range & getRange() const
Returns the range.
Definition: BinnerAxis.cxx:78
A Factory singleton class for creating objects whose class derives from BinnerAxis.
A pure virtual base class of XML element wrapper.
Definition: XmlElement.h:30
virtual const Range & setBinWidth(double width)=0
Sets the bin width and adjusts the range and number of bins accordingly.
virtual const Range & setRange(const Range &, bool hold_width=true)=0
Sets the range.
BinnerAxisXML(const BinnerAxisXML &)
A private copy constructor in order to avoid copying.
bool ok
Definition: CanvasView.cxx:163
PyArray_TYPES type(numeric::array arr)
Definition: num_util.cpp:249
The base class for the BinnerAxis hierarchy.
Definition: BinnerAxis.h:35
XmlElement class interface.
const std::string m_type
The attribute name for the type of object.
Definition: BaseXML.h:54
static BinnerAxisFactory * instance()
Returns a pointer to the singleton instance.
A base class of XML element controllers.
Definition: BaseXML.h:35
double low() const
Returns the minimum of the range object.
Definition: Range.cxx:87
virtual double getBinWidth() const =0
Returns the bin width parameter.
std::string m_low
The attribute name for the low end of the binner&#39;s Range.
Definition: BinnerAxisXML.h:43
Expresses a range of values.
Definition: Range.h:33
A base class that is the interface between GUI and the XML serialization and deserialization.
Definition: XmlController.h:53
hippodraw::BinnerAxis class interface
virtual BinnerAxis * createObject(const XmlElement *element)
Creates an object derived from BinnerAxis.
const std::string & name() const
Returns the name of this binner.
Definition: BinnerAxis.cxx:53
virtual void setAttribute(const std::string &name, bool value)=0
Sets attribute named name to the int value value.
std::string m_high
The attribute name for the high end of the binner&#39;s Range.
Definition: BinnerAxisXML.h:40

Generated for HippoDraw Class Library by doxygen