link to homepage

Institute for Neuroscience and Medicine

Navigation and service


API documentation

Prototype.h

Go to the documentation of this file.
00001 
00005 /*
00006  *  JEMRIS Copyright (C) 2007-2010  Tony Stöcker, Kaveh Vahedipour
00007  *                                  Forschungszentrum Jülich, Germany
00008  *
00009  *  This program is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  This program is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with this program; if not, write to the Free Software
00021  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00022  */
00023 
00024 #ifndef PROTOTYPE_H_
00025 #define PROTOTYPE_H_
00026 
00027 #include     "StrX.h"
00028 #include     "Attribute.h"
00029 #include     "TPOI.h"
00030 #include     "Debug.h"
00031 #include     "World.h"
00032 
00033 #include     <stdexcept>
00034 #include     <map>
00035 #include     <vector>
00036 #include     <typeinfo>
00037 #include     <cmath>
00038 #include     <sstream>
00039 #include     <fstream>
00040 
00041 #include     <ginac/ginac.h>
00042 #include     <xercesc/dom/DOM.hpp>
00043 XERCES_CPP_NAMESPACE_USE
00044 
00045 
00046 enum PrepareMode{       PREP_INIT,      PREP_VERBOSE,   PREP_UPDATE                                     };
00047 enum Type               {       MOD_PULSE,              MOD_ATOM,       MOD_CONCAT,     MOD_VOID,       COIL};
00048 
00049 //parameter class declaration
00050 class Parameters;
00051 
00052 //Macros for attribute creation in Prototype::Prepare()
00053 #define ATTRIBUTE(KEY,VAL)              if (mode!=PREP_UPDATE && m_attributes.find(KEY)==m_attributes.end() ) \
00054                                                                                 m_attributes.insert(pair<string,Attribute*>(KEY,new Attribute(KEY,this, true, true,VAL)));
00055 #define HIDDEN_ATTRIBUTE(KEY,VAL)   if (mode!=PREP_UPDATE && m_attributes.find(KEY)==m_attributes.end() ) \
00056                                                                                 m_attributes.insert(pair<string,Attribute*>(KEY,new Attribute(KEY,this,false, true,VAL)));
00057 #define UNOBSERVABLE_ATTRIBUTE(KEY) if (mode!=PREP_UPDATE && m_attributes.find(KEY)==m_attributes.end() ) \
00058                                                                                 m_attributes.insert(pair<string,Attribute*>(KEY,new Attribute(KEY,this,false,false)));
00059 
00060 
00061 using std::ofstream;
00062 using std::string;
00063 using std::map;
00064 
00068 class Prototype {
00069 
00070  public:
00071 
00077     Prototype () { m_prepared=false; };
00078 
00084     virtual ~Prototype () {};
00085 
00091     Prototype (const Prototype&) {};
00092 
00098     virtual Prototype* GetParent   () {return NULL;};
00099 
00105     virtual Prototype* Clone      () const           = 0;
00106 
00116     virtual bool       Prepare    (PrepareMode mode) = 0;
00117 
00123     inline bool IsPrepared () {return m_prepared;};
00124 
00125 
00131     virtual void       Initialize (DOMNode* conf)    = 0;
00132 
00138     void               SetName    (string name);
00139 
00145     inline DOMNode* GetNode () {return m_node;};
00146 
00152     void SetNode (DOMNode* node) {m_node=node;};
00153 
00162     static bool ReplaceString (string& str, const string& s1, const string& s2);
00163 
00171     static vector<string>  Tokenize (const string& str, const string& delimiters = ",");
00172 
00178     inline string GetClassType () {return XMLString::transcode(GetNode()->getNodeName());};
00179 
00185     inline Type GetType () {return m_type;};
00186 
00187 
00194     string GetDOMattribute    (const string attribute){ return StrX(((DOMElement*) m_node)->getAttribute (StrX(attribute).XMLchar())).std_str() ;  }
00195 
00202     bool HasDOMattribute    (const string attribute) {  if (GetDOMattribute(attribute).empty()) return false; else return true;  }
00203 
00204 
00211     Attribute*  GetAttribute(string name);
00212 
00219     inline bool HasAttribute (string name) {if (GetAttribute(name)==NULL) return false; else return true;};
00220 
00232       void  HideAttribute (string attrib, bool observable = true);
00233 
00241         inline virtual Prototype* GetPrototypeByAttributeValue (string name, string attrib) {return this;};
00242 
00248     inline string GetName () { return m_name; };
00249 
00263     bool Observe (Attribute* attrib, string prot_name, string attrib_name, bool verbose);
00264 
00271     template <typename T> bool Notify (const T& val) {
00272 
00273         map<string,Attribute*>::iterator iter;
00274         for(iter = m_attributes.begin(); iter != m_attributes.end(); iter++)
00275             if (iter->second->GetAddress() == ((void*) &val) ) return iter->second->Notify(val);
00276 
00277         return false;
00278     };
00279 
00286     template <typename T> bool NewState (const T& val) {
00287 
00288         map<string,Attribute*>::iterator iter;
00289         for(iter = m_attributes.begin(); iter != m_attributes.end(); iter++)
00290             if (iter->second->GetAddress() == ((void*) &val) ) return iter->second->NewState(val);
00291 
00292         return false;
00293     };
00294     
00301     vector<double>*             GetVector()              {return &m_vector;  };
00302 
00303 
00304  protected:
00305 
00306     bool                        m_aux;         
00307     bool                        m_prepared;    
00308     string                      m_name;        
00309     DOMNode*                    m_node;        
00310     Type                        m_type;        
00311     vector<double>              m_vector;      
00312     map<string,Attribute*>              m_attributes;  
00313     vector<Attribute*>                  m_obs_attribs; 
00315 };
00316 
00317 #endif /*_PROTOTYPE_H_*/

Servicemeu

institutes

Scientific Technical Facilities