FunctionProjectorXML.cxx

Go to the documentation of this file.
00001 
00012 // for truncation warning
00013 #ifdef _MSC_VER
00014 #include "msdevstudio/MSconfig.h"
00015 #endif
00016 
00017 #include "FunctionProjectorXML.h"
00018 
00019 #include "XmlController.h"
00020 #include "XmlElement.h"
00021 
00022 #include "controllers/FunctionController.h"
00023 #include "datareps/FunctionRep.h"
00024 #include "functions/FunctionBase.h"
00025 #include "pattern/string_convert.h"
00026 #include "projectors/FunctionProjector.h"
00027 
00028 using std::string;
00029 using std::vector;
00030 
00031 namespace hippodraw {
00032 
00033 FunctionProjectorXML::FunctionProjectorXML ( XmlController * controller )
00034   : BaseXML ( "FunctionProjector", controller )
00035 {
00036 }
00037 
00038 XmlElement * 
00039 FunctionProjectorXML::createElement ( const FunctionProjector & projector )
00040 {
00041   XmlElement * tag = BaseXML::createElement ();
00042 
00043   const void * addr = reinterpret_cast < const void * > ( & projector );
00044   int id = m_controller -> getId ( addr );
00045   setId ( *tag, id );
00046   FunctionBase * function = projector.function ();
00047   tag->setAttribute ( "name", function->name() );
00048 
00049   const vector < double > & parms = function->getParameters ();
00050   unsigned int size = parms.size();
00051 
00052   for ( unsigned int i = 0; i < size; i++ ) {
00053     string parm ( "Parm" );
00054     parm += String::convert ( i );
00055     tag -> setAttribute ( parm, parms[i] );
00056   }
00057 
00058   return tag;
00059 }
00060 
00061 string 
00062 FunctionProjectorXML::
00063 getFunctionName ( const XmlElement * element )
00064 {
00065   string fname;
00066   bool ok = element->attribute ( "name", fname );
00067   if ( ! ok ) return 0;
00068 
00069   return fname;
00070 }
00071 
00072 void 
00073 FunctionProjectorXML::
00074 setAttributes ( const XmlElement * element, FunctionBase * function )
00075 {
00076   int size = function->size();
00077   vector < double > parms ( size );
00078   for ( int i = 0; i < size; i++ ) {
00079     string parm ( "Parm" );
00080     parm += String::convert ( i );
00081     element -> attribute ( parm, parms[i] );
00082   }
00083 
00084   function->setParameters ( parms );
00085 }
00086 
00087 DataRep *
00088 FunctionProjectorXML::
00089 createFunctionRep ( const XmlElement * fun_element,
00090                     DataRep * drep )
00091 {
00092   FunctionRep * rep = 0;
00093 
00094   std::string fname = getFunctionName ( fun_element );
00095   FunctionController * fc = FunctionController::instance();
00096   if ( fc -> functionExists ( fname ) ) {
00097     rep = fc->createFunctionRep ( fname, drep );
00098     FunctionBase * function = rep->getFunction ();
00099     setAttributes ( fun_element, function );
00100     rep->saveParameters ();
00101   }
00102   return rep;
00103 }
00104 
00105 } // namespace hippodraw
00106 

Generated for HippoDraw Class Library by doxygen