Cat
Public Member Functions | Private Attributes | List of all members
Hierarchy Class Reference

#include <inc/Hierarchy.h>

Inheritance diagram for Hierarchy:
Object Attrib Element A3PE Computer Croc CU_v1 DCU ElementWrap FEB_v1 FePGA ICECALv3 ICPhaser Interface IOobject LSDelayChipV1 MSOxxxx NI6008 Phaser Proto40MHz_v1 SeqPGA SpecsMaster UsbMLI2cBus UsbMLSpiBus

Public Member Functions

 Hierarchy ()
 Standard constructor. More...
 
virtual ~Hierarchy ()
 Destructor. More...
 
void clear ()
 
void setParent (Hierarchy *parent)
 
Hierarchyparent ()
 
Hierarchyparent (std::string)
 
Hierarchyorigin ()
 
virtual void addChild (Hierarchy *element)
 
std::vector< Hierarchy * > children ()
 
Hierarchychild (std::string)
 
HierarchychildTyped (std::string)
 
unsigned long numberOfChildren ()
 
bool hasChildren ()
 
void delChild (Hierarchy *)
 
void delChild (std::string)
 
std::string path (std::string=std::string(""))
 
std::string pathTyped (std::string=std::string(""))
 
void tree (std::string indent=std::string(""))
 
void tree ()
 
- Public Member Functions inherited from Object
 Object ()
 Standard constructor. More...
 
virtual ~Object ()
 Destructor. More...
 
std::string name () const
 
std::string type ()
 
unsigned char id ()
 
std::string title ()
 
void msgSvc (int level, std::string msg, std::string name)
 
void msg (std::string mymsg)
 
void verbose (std::string mymsg)
 
void debug (std::string mymsg)
 
void info (std::string mymsg)
 
void warning (std::string mymsg)
 
void error (std::string mymsg)
 
void fatal (std::string mymsg)
 
void msg (std::string mymsg, std::string name)
 
void verbose (std::string mymsg, std::string name)
 
void debug (std::string mymsg, std::string name)
 
void info (std::string mymsg, std::string name)
 
void warning (std::string mymsg, std::string name)
 
void error (std::string mymsg, std::string name)
 
void fatal (std::string mymsg, std::string name)
 
void setName (std::string name)
 
void setType (std::string type)
 
void setId (unsigned char id)
 
void setTitle (std::string title)
 
void setDllName (std::string dllName)
 
std::string dllName ()
 
- Public Member Functions inherited from Attrib
 Attrib ()
 Standard constructor. More...
 
virtual ~Attrib ()
 Destructor. More...
 
bool is (int attribut)
 
void add (int attribut)
 
void remove (int attribut)
 
std::string attributs ()
 

Private Attributes

Hierarchym_parent
 
Hierarchym_origin
 
std::vector< Hierarchy * > m_children
 

Additional Inherited Members

- Public Types inherited from Attrib
enum  Attribut {
  UNDEFINED, PASSIVE, ACTIVE, INTERFACE,
  IO, IODATA, ELEMENT, HARDWARE,
  PROCESSUS, SOFTWARE
}
 
- Protected Attributes inherited from Attrib
std::string m_attribString [10]
 

Detailed Description

Class to define an Element Hierarchy

Author
Date
2006-10-26

Definition at line 19 of file Hierarchy.h.

Constructor & Destructor Documentation

◆ Hierarchy()

Hierarchy::Hierarchy ( )

Standard constructor.

Definition at line 16 of file Hierarchy.cpp.

References m_origin.

16  :
17  m_parent (0){
18  m_origin=this;
19 }
Hierarchy * m_origin
Definition: Hierarchy.h:52
Hierarchy * m_parent
Definition: Hierarchy.h:46

◆ ~Hierarchy()

Hierarchy::~Hierarchy ( )
virtual

Destructor.

Definition at line 24 of file Hierarchy.cpp.

References Object::debug(), delChild(), Object::name(), and parent().

24  {
25  if (0!=parent()){
26  parent()->delChild(this);
27  }
28  debug("deleting Hierarchy "+name(),"Hierarchy::~Hierarchy");
29 }
void delChild(Hierarchy *)
Definition: Hierarchy.cpp:92
Hierarchy * parent()
Definition: Hierarchy.h:28
void debug(std::string mymsg)
Definition: Object.h:37
std::string name() const
Definition: Object.h:28

Member Function Documentation

◆ addChild()

void Hierarchy::addChild ( Hierarchy element)
virtual

Definition at line 83 of file Hierarchy.cpp.

References Object::debug(), m_children, Object::name(), and setParent().

Referenced by A3PE::A3PE(), SpecsMezzanine::addBus(), SpecsSlave::addI2c(), Application::create(), CU_v1::CU_v1(), export_obj(), FEB_v1::FEB_v1(), FePGA::FePGA(), ICECALv3::ICECALv3(), ICPhaser::ICPhaser(), FePGA::MakeRAM(), FePGA::MakeRegister(), origin(), Phaser::Phaser(), Proto40MHz_v1::Proto40MHz_v1(), SeqPGA::SeqPGA(), SpecsMezzanine::SpecsMezzanine(), UsbI2cBus::UsbI2cBus(), and UsbSpiBus::UsbSpiBus().

83  {
84  element->setParent(this);
85  m_children.push_back(element);
86  debug(element->name()+" added to the child tree.","Hierarchy::addChild");
87 }
void setParent(Hierarchy *parent)
Definition: Hierarchy.cpp:67
std::vector< Hierarchy * > m_children
Definition: Hierarchy.h:53
void debug(std::string mymsg)
Definition: Object.h:37
std::string name() const
Definition: Object.h:28

◆ child()

Hierarchy * Hierarchy::child ( std::string  path)

Definition at line 133 of file Hierarchy.cpp.

References child(), children(), Object::name(), origin(), parent(), path(), and Object::warning().

Referenced by Application::cd(), child(), children(), and export_obj().

133  {
134  std::string newpath = path;
135  std::string up("..");
136  std::string separator(1,'/');
137 
138  Hierarchy * newcurrent = 0;
139 
140  // info("path="+path,"Hierarchy::child");
141 
142  if (path.compare("")==0 || path.compare("/")==0) {
143  // debug("return origin","Hierarchy::child");
144  return origin();
145  }
146 
147  if (path.compare(name())==0){
148  // debug("return itself","Hierarchy::child");
149  return this;
150  }
151 
152  if (path.compare("..")==0){
153  if (0!=this->parent()) return this->parent();
154  else return this;
155  }
156 
157  if (path.compare("../")==0){
158  if (0!=this->parent()) return this->parent();
159  else return this;
160  }
161 
162 
163  int npos=path.find(separator,0);
164 
165  // info("find separator in "+itos(npos)+" of "+path,"Hierarchy::child");
166 
167  // remove last separator
168  if ( npos == (int)(path.size()-1) ) {
169  newpath = std::string(path,0,npos);
170  path = newpath;
171  }
172 
173  if (npos==0){
174  // debug("Going back to origin and calling child","Hierarchy::child");
175  newpath=std::string(path,1,path.size()-1);
176  return origin()->child(newpath);
177  }
178  else{
179  if ( npos== (int)(std::string::npos) ){
180  // debug("Getting chid "+path+" of "+this->name(),"Hierarchy::child");
181  std::vector <Hierarchy*> list = children();
182  std::vector<Hierarchy*>::iterator iter;
183  for (iter=list.begin();iter!=list.end();iter++){
184  if ((*iter)->name().compare(path)==0){
185  return *iter;
186  }
187  }
188  warning(this->name()+std::string(" has no child '")+path+"'","Hierarchy::child");
189  return this;
190  }
191  else
192  {
193  int ipos=path.find(separator,0);
194  // info("default behaviour "+path+" with separator in "+itos(ipos),"Hierarchy::child");
195 
196  std::string newcurrentname=std::string(path,0,ipos);
197  newpath=std::string(path,ipos+1,path.size()-1);
198 
199  // info("looking now for "+newpath+" from "+newcurrentname,"Hierarchy::child");
200 
201  if (0==newcurrentname.compare(origin()->name())){
202  // info("current is computer. Looking for children"+newcurrentname,"Hierarchy::child");
203  return origin()->child(newpath);
204  }
205 
206  newcurrent = (Hierarchy*)0;
207 
208  std::vector <Hierarchy*> list = children();
209  std::vector<Hierarchy*>::iterator iter;
210  for (iter=list.begin();iter!=list.end();iter++){
211  if ((*iter)->name().compare(newcurrentname)==0){
212  newcurrent = (*iter);
213  }
214  }
215 
216 
217  if ((Hierarchy*)0==newcurrent){
218  if (newcurrentname.compare("..")==0 && 0!=parent()){
219  newcurrent=this->parent();
220  // debug("newcurrent was .. -> parent="+parent()->name());
221  }
222  else
223  {
224  warning(this->name()+" has no child '"+newcurrentname+"'",
225  "Hierarchy::child");
226  return this;
227  }
228  }
229  // debug("recurrence call for "+newpath+" on "+newcurrent->name(),"Hierarchy::child");
230  return newcurrent -> child ( newpath );
231  }
232  }
233 }
Hierarchy * child(std::string)
Definition: Hierarchy.cpp:133
std::vector< Hierarchy * > children()
Definition: Hierarchy.h:33
Hierarchy * parent()
Definition: Hierarchy.h:28
std::string name() const
Definition: Object.h:28
void warning(std::string mymsg)
Definition: Object.h:39
Hierarchy * origin()
Definition: Hierarchy.h:30
std::string path(std::string=std::string(""))
Definition: Hierarchy.cpp:344

◆ children()

std::vector<Hierarchy*> Hierarchy::children ( )
inline

◆ childTyped()

Hierarchy * Hierarchy::childTyped ( std::string  path)

Definition at line 239 of file Hierarchy.cpp.

References children(), m_origin, Object::name(), parent(), path(), and Object::warning().

Referenced by children(), and export_obj().

239  {
240 
241  std::string newpath = path;
242 
243  std::string up("..");
244  std::string separator(1,'/');
245  std::string typeopen(1,'[');
246  std::string typeclose(1,']');
247 
248  Hierarchy * newcurrent = 0;
249 
250  unsigned int npos=path.find(separator,0);
251  unsigned int opos=path.find(typeopen,0);
252  if ( npos==std::string::npos || npos == path.size()-1 ){
253  if ( path.compare("..")==0 ) {
254  return parent();
255  }
256 
257  if ( npos == path.size()-1 ) {
258  newpath = std::string(path,0,opos);
259  path = newpath;
260  }
261 
262  std::vector < Hierarchy* > list = children();
263  std::vector < Hierarchy* >::iterator iter;
264  for (iter=list.begin();iter!=list.end();iter++){
265  std::string notypepath = std::string(path,0,opos);
266  if ((*iter)->name().compare(notypepath)==0){
267  return *iter;
268  }
269  }
270  warning(this->name()+std::string(" has no child ") +path,"Hierarchy::child");
271  return 0;
272  }
273 
274  else {
275 
276  if (std::string(path,0,3).compare(std::string("../"))==0) {
277  newpath=std::string(path,3,path.size()-3);
278  newcurrent = parent();
279  }
280  if (std::string(path,0,1).compare(std::string("/"))==0) {
281  newpath=std::string(path,1,path.size()-1);
282  newcurrent = ( Hierarchy* ) m_origin;
283  }
284  if ((std::string(path,0,3).compare(std::string("../")) !=0 ) &&
285  std::string(path,0,1).compare(std::string("/"))!=0 ) {
286  opos = path.find(typeopen,0);
287  int cpos = path.find(typeclose,0);
288  std::string name = std::string (path,0,opos);
289  newcurrent = childTyped( name );
290  if (newcurrent ==0){
291  warning(path+": no child found with such a name","Hierarchy::child");
292  }
293  newpath = std::string (path,cpos+2,path.size()-cpos-1);
294  }
295  return newcurrent -> childTyped ( newpath );
296  }
297 }
Hierarchy * childTyped(std::string)
Definition: Hierarchy.cpp:239
Hierarchy * m_origin
Definition: Hierarchy.h:52
std::vector< Hierarchy * > children()
Definition: Hierarchy.h:33
Hierarchy * parent()
Definition: Hierarchy.h:28
std::string name() const
Definition: Object.h:28
void warning(std::string mymsg)
Definition: Object.h:39
std::string path(std::string=std::string(""))
Definition: Hierarchy.cpp:344

◆ clear()

void Hierarchy::clear ( )

Definition at line 35 of file Hierarchy.cpp.

References delChild(), Object::info(), m_children, and Object::name().

Referenced by export_obj().

35  {
36  std::vector<Hierarchy*> listlocale;
37  std::vector<Hierarchy*>::iterator iter;
38  info("loop on "+name()+" children.","Hierarchy::clear");
39  for (iter=m_children.begin();iter!=m_children.end();iter++){
40  info("processing "+(*iter)->name()+".","Hierarchy::clear");
41 /*
42  (*iter)->clear();
43 // this->delChild((*iter));
44  info("obj "+(*iter)->name()+" being cleared.","Hierarchy::clear");
45  delete (*iter);
46  info("Object deleted.","Hierarchy::clear");
47  m_children.erase(iter);
48  info("Object removed from the tree.","Hierarchy::clear");
49 */
50  (*iter)->clear();
51  info("Adding object "+(*iter)->name()+" from the Hierarchy to the list of deleted objects.","Hierarchy::clear");
52  listlocale.push_back((*iter));
53  }
54 
55  for (iter=listlocale.begin();iter!=listlocale.end();iter++){
56  info("Removing object "+(*iter)->name()+".","Hierarchy::clear");
57  this->delChild(*iter);
58 // m_children.erase(iter);
59  delete (*iter);
60  }
61  info("Getting out of "+name());
62 }
void info(std::string mymsg)
Definition: Object.h:38
void delChild(Hierarchy *)
Definition: Hierarchy.cpp:92
std::vector< Hierarchy * > m_children
Definition: Hierarchy.h:53
std::string name() const
Definition: Object.h:28

◆ delChild() [1/2]

void Hierarchy::delChild ( Hierarchy element)

Definition at line 92 of file Hierarchy.cpp.

References Object::debug(), and m_children.

Referenced by children(), clear(), export_obj(), and ~Hierarchy().

92  {
93  bool flag=false;
94  std::vector<Hierarchy*>::iterator iter,remove;
95  for (iter=m_children.begin();(iter!=m_children.end());iter++){
96  if (*iter==element){
97  remove=iter;
98  flag=true;
99  }
100  }
101  if (flag){
102  debug("removing "+(*remove)->name()+" from the tree.","Hierarchy::delChild");
103  m_children.erase(remove);
104  }
105 }
std::vector< Hierarchy * > m_children
Definition: Hierarchy.h:53
void debug(std::string mymsg)
Definition: Object.h:37

◆ delChild() [2/2]

void Hierarchy::delChild ( std::string  n)

Definition at line 110 of file Hierarchy.cpp.

References Object::debug(), and m_children.

110  {
111  bool flag=false;
112  std::vector<Hierarchy*>::iterator iter,remove;
113  for (iter=m_children.begin();iter!=m_children.end();iter++){
114  if ((*iter)->name()==n){ remove=iter; flag=true;}
115  }
116  if (flag){
117  debug("removing "+(*remove)->name()+" from the tree.","Hierarchy::delChild");
118  m_children.erase(remove);
119  }
120 }
std::vector< Hierarchy * > m_children
Definition: Hierarchy.h:53
void debug(std::string mymsg)
Definition: Object.h:37

◆ hasChildren()

bool Hierarchy::hasChildren ( )

Definition at line 303 of file Hierarchy.cpp.

References m_children.

Referenced by children(), and export_obj().

303  {
304  return ( m_children.size()>0 );
305 }
std::vector< Hierarchy * > m_children
Definition: Hierarchy.h:53

◆ numberOfChildren()

unsigned long Hierarchy::numberOfChildren ( )

Definition at line 125 of file Hierarchy.cpp.

References m_children.

Referenced by children(), and export_obj().

125  {
126  return m_children.size();
127 }
std::vector< Hierarchy * > m_children
Definition: Hierarchy.h:53

◆ origin()

Hierarchy* Hierarchy::origin ( )
inline

Definition at line 30 of file Hierarchy.h.

References addChild(), and m_origin.

Referenced by child(), export_obj(), and setParent().

30 { return m_origin; } //< Get the origin of the tree
Hierarchy * m_origin
Definition: Hierarchy.h:52

◆ parent() [1/2]

Hierarchy* Hierarchy::parent ( )
inline

◆ parent() [2/2]

Hierarchy * Hierarchy::parent ( std::string  type)

Definition at line 327 of file Hierarchy.cpp.

References parent(), and Object::type().

327  {
328  Hierarchy *parent = this->parent();
329  if ( 0 != parent){
330  if (parent->type().compare( type )==0) {
331  return parent;
332  }
333  else
334  return parent->parent( type );
335  }
336  else {
337  return (Hierarchy*)NULL;
338  }
339 }
Hierarchy * parent()
Definition: Hierarchy.h:28
std::string type()
Definition: Object.h:29

◆ path()

std::string Hierarchy::path ( std::string  str = std::string(""))

Definition at line 344 of file Hierarchy.cpp.

References m_parent, Object::name(), parent(), and path().

Referenced by child(), children(), childTyped(), export_obj(), path(), UsbFTMLInterface::usbReadU16(), UsbFTMLInterface::usbReadU32(), UsbFTMLInterface::usbReadU8(), UsbFTMLInterface::usbWriteRead(), UsbFTMLInterface::usbWriteU16(), UsbFTMLInterface::usbWriteU32(), and UsbFTMLInterface::usbWriteU8().

344  {
345  str="/"+name()+str;
347  if (0!=m_parent){
348  return m_parent->path(str);
349  }
350  return str;
351 }
Hierarchy * parent()
Definition: Hierarchy.h:28
std::string name() const
Definition: Object.h:28
Hierarchy * m_parent
Definition: Hierarchy.h:46
std::string path(std::string=std::string(""))
Definition: Hierarchy.cpp:344

◆ pathTyped()

std::string Hierarchy::pathTyped ( std::string  str = std::string(""))

Definition at line 356 of file Hierarchy.cpp.

References m_parent, Object::name(), parent(), pathTyped(), and Object::type().

Referenced by children(), export_obj(), and pathTyped().

356  {
358  if (0!=m_parent){
359  str="/"+name()+"["+type()+"]"+str;
360  return m_parent->pathTyped(str);
361  }
362  return str;
363 }
Hierarchy * parent()
Definition: Hierarchy.h:28
std::string name() const
Definition: Object.h:28
std::string pathTyped(std::string=std::string(""))
Definition: Hierarchy.cpp:356
std::string type()
Definition: Object.h:29
Hierarchy * m_parent
Definition: Hierarchy.h:46

◆ setParent()

void Hierarchy::setParent ( Hierarchy parent)

Definition at line 67 of file Hierarchy.cpp.

References m_origin, m_parent, origin(), and parent().

Referenced by SpecsMezzanine::addBus(), addChild(), SpecsSlave::addI2c(), Computer::Computer(), Application::create(), export_obj(), and SpecsMezzanine::SpecsMezzanine().

67  {
68  m_parent = parent;
69  if ((Hierarchy*)0==parent) return;
70 
71  Hierarchy *curr = this;
72  Hierarchy *prev = parent;
73  while ( prev != 0 ){
74  curr = prev;
75  prev = curr->parent();
76  }
77  if (parent->origin()!=0) m_origin=parent->origin();
78 }
Hierarchy * m_origin
Definition: Hierarchy.h:52
Hierarchy * parent()
Definition: Hierarchy.h:28
Hierarchy * m_parent
Definition: Hierarchy.h:46
Hierarchy * origin()
Definition: Hierarchy.h:30

◆ tree() [1/2]

void Hierarchy::tree ( std::string  indent = std::string(""))

Definition at line 310 of file Hierarchy.cpp.

References children(), Object::info(), Object::msgSvc(), Object::name(), MsgSvc::NONE, and Object::type().

310  {
311  std::string line=indent+" -> "+name()+"["+type()+"] ";
312  if (std::string("")==indent){
313  info("Hierarchy for Object "+name()+"["+type()+"]","Hierarchy::tree");
314  }
315  msgSvc(MsgSvc::NONE,line,"");
316  std::vector<Hierarchy*> list = children();
317  std::vector<Hierarchy*>::iterator iter;
318  for (iter=list.begin() ; iter!=list.end() ; ++iter){
319  std::string tab=" ";
320  (*iter)->tree(indent+tab);
321  }
322 }
void info(std::string mymsg)
Definition: Object.h:38
std::vector< Hierarchy * > children()
Definition: Hierarchy.h:33
std::string name() const
Definition: Object.h:28
void msgSvc(int level, std::string msg, std::string name)
Definition: Object.h:33
std::string type()
Definition: Object.h:29

◆ tree() [2/2]

void Hierarchy::tree ( )
inline

Definition at line 46 of file Hierarchy.h.

References m_parent, and tree().

Referenced by children(), export_obj(), and tree().

46 { tree(""); }; // output tree of Hierarchy from object
void tree()
Definition: Hierarchy.h:46

Member Data Documentation

◆ m_children

std::vector<Hierarchy*> Hierarchy::m_children
private

Definition at line 53 of file Hierarchy.h.

Referenced by addChild(), children(), clear(), delChild(), hasChildren(), and numberOfChildren().

◆ m_origin

Hierarchy* Hierarchy::m_origin
private

Definition at line 52 of file Hierarchy.h.

Referenced by childTyped(), Hierarchy(), origin(), and setParent().

◆ m_parent

Hierarchy* Hierarchy::m_parent
private

Definition at line 46 of file Hierarchy.h.

Referenced by parent(), path(), pathTyped(), setParent(), and tree().


The documentation for this class was generated from the following files: