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 
XmlElement * createElement()
Creates a new element node.
Definition: BaseXML.cxx:43
unsigned int i
FunctionBase * getFunction() const
Returns the actual function, a FunctionBase derived class.
void setAttributes(const XmlElement *element, FunctionBase *function)
Set the values for the function from the XML element.
virtual bool attribute(const std::string &name, bool &value) const =0
Sets value to the attribute name&#39;s value.
FunctionProjectorXML(const FunctionProjectorXML &)
A private copy constructor in order to avoid copying.
FunctionProjectorXML class interface.
static FunctionController * instance()
Returns the pointer to the singleton instance.
std::string getFunctionName(const XmlElement *element)
Get the function name from the XML element.
XmlController class interface.
hippodraw::FunctionController class interface
A singleton class is the interface between an application and the list of FunctionRep objects contain...
A pure virtual base class of XML element wrapper.
Definition: XmlElement.h:30
A derived class of DataRep which is a base class for displaying a function.
Definition: FunctionRep.h:34
return rep
Definition: Inspector.cxx:3843
The namespace for conversion to string.
hippodraw::DataRep * createFunctionRep(const XmlElement *element, hippodraw::DataRep *target)
Creates a FunctionRep from element with target DataRep.
void setId(XmlElement &tag, int id)
Sets the unique identification of the object.
Definition: BaseXML.cxx:64
hippodraw::FunctionRep class interface
bool ok
Definition: CanvasView.cxx:163
The base class for data representations.
Definition: DataRep.h:68
void saveParameters()
Saves the function parameters in a cache so that they can be restored.
FunctionRep * createFunctionRep(const std::string &name, DataRep *rep)
Returns a newly created FunctionRep object with function of type name and target rep.
intp size(numeric::array arr)
Definition: num_util.cpp:296
string convert(int i)
Converts an integer to a string.
XmlController * m_controller
The singleton XML controller object.
Definition: BaseXML.h:60
XmlElement class interface.
A function that can be added to a DataRep and used in a fitter.
Definition: FunctionBase.h:90
hippodraw::FunctionProjector class interface
FunctionBase * function() const
Returns a pointer to the contained function.
A base class of XML element controllers.
Definition: BaseXML.h:35
hippodraw::FunctionBase class interface
A base class that is the interface between GUI and the XML serialization and deserialization.
Definition: XmlController.h:53
virtual void setAttribute(const std::string &name, bool value)=0
Sets attribute named name to the int value value.
A projector that plots one function.

Generated for HippoDraw Class Library by doxygen