JEMRIS 2.9.2
open-source MRI simulations
Loading...
Searching...
No Matches
Prototype.h
Go to the documentation of this file.
1
5/*
6 * JEMRIS Copyright (C)
7 * 2006-2025 Tony Stoecker
8 * 2007-2018 Kaveh Vahedipour
9 * 2009-2019 Daniel Pflugfelder
10 *
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 */
26
27#ifndef PROTOTYPE_H_
28#define PROTOTYPE_H_
29
30#include "StrX.h"
31#include "Attribute.h"
32#include "TPOI.h"
33#include "Debug.h"
34#include "World.h"
35
36#include <stdexcept>
37#include <map>
38#include <vector>
39#include <typeinfo>
40#include <cmath>
41#include <sstream>
42#include <fstream>
43
44#include <ginac/ginac.h>
45#include <xercesc/dom/DOM.hpp>
46XERCES_CPP_NAMESPACE_USE
47
48
49enum PrepareMode{ PREP_INIT, PREP_VERBOSE, PREP_UPDATE };
50enum Type { MOD_PULSE, MOD_ATOM, MOD_CONCAT, MOD_CONTAINER, MOD_VOID, COIL};
51
52//parameter class declaration
53class Parameters;
54
55//Macros for attribute creation in Prototype::Prepare()
56#define ATTRIBUTE(KEY,VAL) if (mode!=PREP_UPDATE && m_attributes.find(KEY)==m_attributes.end() ) \
57 m_attributes.insert(pair<string,Attribute*>(KEY,new Attribute(KEY,this, true, true,VAL)));
58#define HIDDEN_ATTRIBUTE(KEY,VAL) if (mode!=PREP_UPDATE && m_attributes.find(KEY)==m_attributes.end() ) \
59 m_attributes.insert(pair<string,Attribute*>(KEY,new Attribute(KEY,this,false, true,VAL)));
60#define UNOBSERVABLE_ATTRIBUTE(KEY) if (mode!=PREP_UPDATE && m_attributes.find(KEY)==m_attributes.end() ) \
61 m_attributes.insert(pair<string,Attribute*>(KEY,new Attribute(KEY,this,false,false)));
62
63
64using std::ofstream;
65using std::string;
66using std::map;
67
71class Prototype {
72
73 public:
74
80 Prototype () { m_prepared=false; };
81
87 virtual ~Prototype () {
88 map<string,Attribute*>::iterator iter;
89 for (iter = m_attributes.begin(); iter != m_attributes.end(); iter++ )
90 delete iter->second;
91
92 };
93
99 Prototype (const Prototype&) {};
100
106 virtual Prototype* GetParent () {return NULL;};
107
113 virtual Prototype* Clone () const = 0;
114
124 virtual bool Prepare (PrepareMode mode) = 0;
125
131 inline bool IsPrepared () {return m_prepared;};
132
133
139 virtual void Initialize (DOMNode* conf) = 0;
140
146 void SetName (string name);
147
153 inline DOMNode* GetNode () {return m_node;};
154
160 void SetNode (DOMNode* node) {m_node=node;};
161
170 static bool ReplaceString (string& str, const string& s1, const string& s2);
171
172
176 static bool ReplaceSymbolString (string& str, const string& s1, const string& s2);
177
185 static vector<string> Tokenize (const string& str, const string& delimiters = ",");
186
192 inline string GetClassType () {return XMLString::transcode(GetNode()->getNodeName());};
193
199 inline Type GetType () {return m_type;};
200
201
208 string GetDOMattribute (const string attribute){ return StrX(((DOMElement*) m_node)->getAttribute (StrX(attribute).XMLchar())).std_str() ; }
209
216 bool HasDOMattribute (const string attribute) { if (GetDOMattribute(attribute).empty()) return false; else return true; }
217
218
225 Attribute* GetAttribute(string name);
226
233 void CopyObservers(Attribute* a1, Attribute* a2);
234
241 inline bool HasAttribute (string name) {if (GetAttribute(name)==NULL) return false; else return true;};
242
254 void HideAttribute (string attrib, bool observable = true);
255
263 inline virtual Prototype* GetPrototypeByAttributeValue (string name, string attrib) {return this;};
264
270 inline string GetName () { return m_name; };
271
285 bool Observe (Attribute* attrib, string prot_name, string attrib_name, bool verbose);
286 bool Observe (Attribute* attrib, string prot_name, string attrib_name, string attrib_keyword, bool verbose);
287
294 template <typename T> bool Notify (const T& val) {
295
296 map<string,Attribute*>::iterator iter;
297 for(iter = m_attributes.begin(); iter != m_attributes.end(); iter++)
298 if (iter->second->GetAddress() == ((void*) &val) ) return iter->second->Notify(val);
299
300 return false;
301 }
302
309 template <typename T> bool NewState (const T& val) {
310
311 map<string,Attribute*>::iterator iter;
312 for(iter = m_attributes.begin(); iter != m_attributes.end(); iter++)
313 if (iter->second->GetAddress() == ((void*) &val) ) return iter->second->NewState(val);
314
315 return false;
316 };
317
324 vector<double>* GetVector() {return &m_vector; };
325
326
327 protected:
328
329 bool m_aux;
331 string m_name;
332 DOMNode* m_node;
333 Type m_type;
334 vector<double> m_vector;
335 map<string,Attribute*> m_attributes;
336 vector<Attribute*> m_obs_attribs;
337 vector<string> m_obs_attrib_keyword;
339};
340
341#endif /*_PROTOTYPE_H_*/
Implementation of Attribute.
Implementation of JEMRIS Debug.
mode
Definition Declarations.h:112
Implementation of JEMRIS StrX.
Implementation of JEMRIS TPOI.
Implementation of JEMRIS World.
Attribute class. Attributes are private member variables of a Prototype which are accessible through ...
Definition Attribute.h:62
World parameters provide the parametric data of the sequence.
Definition Parameters.h:37
Prototype super class.
Definition Prototype.h:71
static vector< string > Tokenize(const string &str, const string &delimiters=",")
A global string tokenizer.
Definition Prototype.cpp:92
virtual Prototype * GetPrototypeByAttributeValue(string name, string attrib)
Get a Prototype by value of an attribute.
Definition Prototype.h:263
vector< Attribute * > m_obs_attribs
Vector of observed Attributes.
Definition Prototype.h:336
virtual ~Prototype()
Default destructor.
Definition Prototype.h:87
bool IsPrepared()
Check if the Prototype is prepared.
Definition Prototype.h:131
bool m_prepared
True, after the first call to Prepare.
Definition Prototype.h:330
virtual void Initialize(DOMNode *conf)=0
Initialise this prototype.
string m_name
Name of this Prototype.
Definition Prototype.h:331
bool HasDOMattribute(const string attribute)
Check, if attribute exists in DOM node of this module.
Definition Prototype.h:216
virtual Prototype * GetParent()
Get Parent.
Definition Prototype.h:106
DOMNode * GetNode()
Get the DOMNode of this module.
Definition Prototype.h:153
void SetName(string name)
Set the name of this module.
Definition Prototype.cpp:31
bool HasAttribute(string name)
Check if an attribute exist.
Definition Prototype.h:241
bool m_aux
auxiliary helper variable for debugging purposes
Definition Prototype.h:329
Type GetType()
Get the module type of this module.
Definition Prototype.h:199
void CopyObservers(Attribute *a1, Attribute *a2)
Copy observers from one attribute to another.
Definition Prototype.cpp:120
static bool ReplaceString(string &str, const string &s1, const string &s2)
A global sub-string replacer.
Definition Prototype.cpp:40
vector< double > m_vector
A vector which elements are accessible through loop counters.
Definition Prototype.h:334
Type m_type
The type of the module: one of MOD_PULSE, MOD_ATOM, MOD_CONCAT.
Definition Prototype.h:333
bool Observe(Attribute *attrib, string prot_name, string attrib_name, bool verbose)
Set up the list of observations.
Definition Prototype.cpp:143
vector< string > m_obs_attrib_keyword
Vector of user-defined Attribute names.
Definition Prototype.h:337
string GetDOMattribute(const string attribute)
Get attribute value from the DOMNode.
Definition Prototype.h:208
map< string, Attribute * > m_attributes
Map to connect a keyword with an Attribute.
Definition Prototype.h:335
bool Notify(const T &val)
Notify all observers of an attribute.
Definition Prototype.h:294
void SetNode(DOMNode *node)
Set the DOMNode of this module.
Definition Prototype.h:160
vector< double > * GetVector()
Each Prototype has a double vector as a private member, which values can be filled through XML and ac...
Definition Prototype.h:324
Prototype()
Constructor.
Definition Prototype.h:80
bool NewState(const T &val)
Check the state of an attribute.
Definition Prototype.h:309
Prototype(const Prototype &)
Default copy constructor.
Definition Prototype.h:99
string GetName()
Get the name of this module.
Definition Prototype.h:270
void HideAttribute(string attrib, bool observable=true)
Hide an attribute.
Definition Prototype.cpp:132
static bool ReplaceSymbolString(string &str, const string &s1, const string &s2)
A global sub-string replacer which replaces only complete symbol strings.
Definition Prototype.cpp:60
string GetClassType()
Get the class type of this prototype.
Definition Prototype.h:192
virtual Prototype * Clone() const =0
Clone a prototype.
DOMNode * m_node
The node configuring this Module.
Definition Prototype.h:332
Attribute * GetAttribute(string name)
Get an Attribute.
Definition Prototype.cpp:111
virtual bool Prepare(PrepareMode mode)=0
Prepare this pulse.
Definition Prototype.cpp:182
Simple class for transcoding sax errors to the machines locale.
Definition StrX.h:37
const std::string std_str() const
Transcode to string.
Definition StrX.cpp:77

-- last change 03.01.2025 | Tony Stoecker | Imprint | Data Protection --