FunctionProjectorXML.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 "FunctionProjectorXML.h"
18 
19 #include "XmlController.h"
20 #include "XmlElement.h"
21 
23 #include "datareps/FunctionRep.h"
24 #include "functions/FunctionBase.h"
25 #include "pattern/string_convert.h"
27 
28 using std::string;
29 using std::vector;
30 
31 namespace hippodraw {
32 
34  : BaseXML ( "FunctionProjector", controller )
35 {
36 }
37 
38 XmlElement *
40 {
42 
43  const void * addr = reinterpret_cast < const void * > ( & projector );
44  int id = m_controller -> getId ( addr );
45  setId ( *tag, id );
46  FunctionBase * function = projector.function ();
47  tag->setAttribute ( "name", function->name() );
48 
49  const vector < double > & parms = function->getParameters ();
50  unsigned int size = parms.size();
51 
52  for ( unsigned int i = 0; i < size; i++ ) {
53  string parm ( "Parm" );
54  parm += String::convert ( i );
55  tag -> setAttribute ( parm, parms[i] );
56  }
57 
58  return tag;
59 }
60 
61 string
63 getFunctionName ( const XmlElement * element )
64 {
65  string fname;
66  bool ok = element->attribute ( "name", fname );
67  if ( ! ok ) return 0;
68 
69  return fname;
70 }
71 
72 void
74 setAttributes ( const XmlElement * element, FunctionBase * function )
75 {
76  int size = function->size();
77  vector < double > parms ( size );
78  for ( int i = 0; i < size; i++ ) {
79  string parm ( "Parm" );
80  parm += String::convert ( i );
81  element -> attribute ( parm, parms[i] );
82  }
83 
84  function->setParameters ( parms );
85 }
86 
87 DataRep *
89 createFunctionRep ( const XmlElement * fun_element,
90  DataRep * drep )
91 {
92  FunctionRep * rep = 0;
93 
94  std::string fname = getFunctionName ( fun_element );
96  if ( fc -> functionExists ( fname ) ) {
97  rep = fc->createFunctionRep ( fname, drep );
98  FunctionBase * function = rep->getFunction ();
99  setAttributes ( fun_element, function );
100  rep->saveParameters ();
101  }
102  return rep;
103 }
104 
105 } // namespace hippodraw
106 

Generated for HippoDraw Class Library by doxygen