DABC (Data Acquisition Backbone Core)  2.9.9
Iterator.h
Go to the documentation of this file.
1 // $Id: Iterator.h 4471 2020-04-15 13:19:26Z linev $
2 
3 /************************************************************
4  * The Data Acquisition Backbone Core (DABC) *
5  ************************************************************
6  * Copyright (C) 2009 - *
7  * GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
8  * Planckstr. 1, 64291 Darmstadt, Germany *
9  * Contact: http://dabc.gsi.de *
10  ************************************************************
11  * This software can be used under the GPL license *
12  * agreements as stated in LICENSE.txt file *
13  * which is part of the distribution. *
14  ************************************************************/
15 
16 #ifndef DABC_Iterator
17 #define DABC_Iterator
18 
19 #ifndef DABC_Object
20 #include "dabc/Object.h"
21 #endif
22 
23 #ifndef DABC_ReferencesVector
24 #include "dabc/ReferencesVector.h"
25 #endif
26 
27 namespace dabc {
28 
36  class Iterator {
37  protected:
40  std::vector<unsigned> fIndexes;
42  std::string fFullName;
43  int fMaxLevel;
44  public:
45  Iterator(Reference ref, int maxlevel = -1);
46  Iterator(Object* topfolder, int maxlevel = -1);
47  virtual ~Iterator();
48  Object* next(bool goinside = true);
49  Object* current() const { return fCurrent(); }
50  Reference ref() const { return fCurrent; }
51  unsigned level() const { return fIndexes.size(); }
55  Object* parent(unsigned lvl);
56  const char* fullname() const { return fFullName.c_str(); }
57  const char* name() const { return fCurrent() ? fCurrent()->GetName() : "none"; }
58 
59  template<class T>
60  bool next_cast(T* &ptr, bool goinside = true)
61  {
62  while (next(goinside)) {
63  ptr = dynamic_cast<T*>(current());
64  if (ptr!=0) return true;
65  }
66  return false;
67  }
68 
69  static void PrintHieararchy(Reference ref);
70  };
71 
72 }
73 
74 #endif
Iterator over objects hierarchy
Definition: Iterator.h:36
Reference fTop
Definition: Iterator.h:38
const char * name() const
Definition: Iterator.h:57
const char * fullname() const
Definition: Iterator.h:56
std::vector< unsigned > fIndexes
Definition: Iterator.h:40
virtual ~Iterator()
Definition: Iterator.cxx:40
Object * next(bool goinside=true)
Definition: Iterator.cxx:44
Reference fCurrent
Definition: Iterator.h:39
Object * current() const
Definition: Iterator.h:49
Object * parent(unsigned lvl)
Returns parents of current object.
Definition: Iterator.cxx:91
ReferencesVector fFolders
Definition: Iterator.h:41
unsigned level() const
Definition: Iterator.h:51
Iterator(Reference ref, int maxlevel=-1)
Limit how deep iterator allowed to go inside hierarchy.
Definition: Iterator.cxx:20
Reference ref() const
Definition: Iterator.h:50
bool next_cast(T *&ptr, bool goinside=true)
Definition: Iterator.h:60
std::string fFullName
Definition: Iterator.h:42
static void PrintHieararchy(Reference ref)
Definition: Iterator.cxx:97
Base class for most of the DABC classes.
Definition: Object.h:116
Reference on the arbitrary object
Definition: Reference.h:73
const char * GetName() const
Return name of referenced object, if object not assigned, returns "---".
Definition: Reference.cxx:167
Vector of dabc::Reference objects.
Event manipulation API.
Definition: api.h:23