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

FunctionProjectorXML.cxx

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

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3