00001
00012
00013 #ifdef _MSC_VER
00014 #include "msdevstudio/MSconfig.h"
00015 #endif
00016
00017 #include "BinnerAxisXML.h"
00018
00019 #include "XmlElement.h"
00020
00021 #include "binners/BinnerAxis.h"
00022 #include "binners/BinnerAxisFactory.h"
00023
00024 #include <cassert>
00025
00026 using std::string;
00027
00028 namespace hippodraw {
00029
00030 BinnerAxisXML::BinnerAxisXML ( XmlController * controller )
00031 : BaseXML ( "BinnerBase", controller ),
00032 m_width ( "width" ),
00033 m_high ( "high" ),
00034 m_low ( "low" )
00035 {
00036 }
00037
00038 XmlElement *
00039 BinnerAxisXML::
00040 createElement ( const BinnerAxis & binner )
00041 {
00042 XmlElement * tag = BaseXML::createElement ();
00043 setAttributes ( tag, binner );
00044
00045 return tag;
00046 }
00047
00048 void
00049 BinnerAxisXML::
00050 setAttributes ( XmlElement * tag, const BinnerAxis & binner )
00051 {
00052 const string & type = binner.name();
00053 tag->setAttribute ( m_type, type );
00054
00055 const Range & range = binner.getRange ();
00056 double high = range.high();
00057 double low = range.low ();
00058
00059 tag->setAttribute ( m_high, high );
00060 tag->setAttribute ( m_low, low );
00061
00062 double width = binner.getBinWidth ();
00063 tag->setAttribute ( m_width, width );
00064 }
00065
00066 BinnerAxis *
00067 BinnerAxisXML::
00068 createObject ( const XmlElement * element )
00069 {
00070 string type;
00071 bool ok = element->attribute ( m_type, type );
00072 assert ( ok );
00073
00074 BinnerAxisFactory * factory = BinnerAxisFactory::instance ();
00075 BinnerAxis * binner = factory->create ( type );
00076
00077 double high = 1.0;
00078 double low = 0.0;
00079 ok = element->attribute ( m_high, high );
00080 ok &= element->attribute ( m_low, low );
00081 assert ( ok );
00082 Range range ( low, high );
00083 binner->setRange ( range, false );
00084
00085 double width = -1.0;
00086 ok = element->attribute ( m_width, width );
00087 assert ( ok );
00088 binner->setBinWidth ( width );
00089
00090 return binner;
00091 }
00092
00093 }
00094