Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

BinToColorXML.cxx

Go to the documentation of this file.
00001 
00012 // for dll interface warning
00013 #ifdef _MSC_VER
00014 #include "msdevstudio/MSconfig.h"
00015 #endif
00016 
00017 #include "BinToColorXML.h"
00018 
00019 #include "XmlController.h"
00020 #include "XmlDocument.h"
00021 #include "XmlElement.h"
00022 
00023 #include "reps/BinToColor.h"
00024 #include "reps/BinToColorFactory.h"
00025 
00026 #include <cassert>
00027 
00028 using std::list;
00029 using std::string;
00030 using std::vector;
00031 
00032 BinToColorXML::BinToColorXML ( XmlController * controller )
00033   : BaseXML ( "BinToColor", controller ),
00034     m_ctrlpt ( "CtrlPt" ),
00035     m_point ( "point" )
00036 {
00037 }
00038 
00039 XmlElement * BinToColorXML::createElement ( const BinToColor & btc )
00040 {
00041   XmlElement * tag = BaseXML::createElement ();
00042   tag -> setAttribute ( m_type, btc.name () );
00043   bool yes = btc.hasControlPoints ();
00044   if ( yes ) {
00045     const vector < double > & points = btc.getControlPoints ();
00046     unsigned int size = points.size ();
00047     for ( unsigned int i = 0; i < size; i++ ) {
00048       XmlElement * element 
00049         = XmlController::m_xml_doc -> createElement ( m_ctrlpt );
00050       element -> setAttribute ( m_point, points [ i ] );
00051       tag -> appendChild ( *element );
00052     }
00053   }
00054 
00055   return tag;
00056 }
00057 
00058 BinToColor * BinToColorXML::createObject ( const XmlElement * element )
00059 {
00060   string type;
00061   bool ok = element -> attribute ( m_type, type );
00062   assert ( ok );
00063   BinToColor * btc = 0;
00064   BinToColorFactory * factory = BinToColorFactory::instance ();
00065   try {
00066     btc = factory -> create ( type );
00067   }
00068   catch ( const FactoryException & ) {
00069     btc = factory -> create ( "Rainbow" ); // default
00070   }
00071 
00072   ok = btc -> hasControlPoints ();
00073   if ( ok ) {
00074     vector < double > points;
00075     list < XmlElement * > nodelist;
00076     element -> fillNodeList ( m_ctrlpt, nodelist );
00077     list < XmlElement * > :: const_iterator first = nodelist.begin();
00078       while ( first != nodelist.end() ) {
00079         XmlElement * pt_element = *first++;
00080         double point;
00081         ok = pt_element -> attribute ( m_point, point );
00082         points.push_back ( point );
00083       }
00084     btc -> setControlPoints ( points );
00085   }
00086 
00087   return btc;
00088 }

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3