vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AttributesDescription.h
Go to the documentation of this file.
1 
13 // header definitions
14 #ifndef _ATTRIBUTES_DESCRIPTION_H_
15 #define _ATTRIBUTES_DESCRIPTION_H_
16 
17 // attributes description includes
18 #include "Attribute.h"
19 #include "DynamicAttribute.h"
20 
21 // STL includes
22 #include <string>
23 #include <list>
24 #include <map>
25 
26 // namespaces used
27 using namespace std;
28 
29 // VRECKO namespace
30 namespace vrecko
31 {
32 
45 {
46 public:
47 
52  {
53  // prepare the internal iterator
54  attributesListIter = attributesList.begin();
55 
56  // while the iterator is not at the end
57  while (attributesListIter != attributesList.end())
58  {
59  // if the pointer is not null
60  if (*attributesListIter != null)
61  {
62  // delete the data and null the pointer
63  delete *attributesListIter;
64  *attributesListIter = null;
65  }
66 
67  // increment the iterator
68  attributesListIter++;
69  }
70  }
71 
84  bool addAttribute(Attribute* pAttribute)
85  {
86  // if the name already exists, or the attribute is dynamic and has no sub-attributes
87  if (containsAttribute(pAttribute->getName()) || (pAttribute->isDynamic()
88  && ((DynamicAttribute*) pAttribute)->attributesCount() == 0))
89  {
90  // delete the data and null the pointer
91  delete pAttribute;
92  pAttribute = null;
93 
94  return false;
95  }
96 
97  // insert the attribute into both containers
98  attributesList.push_back(pAttribute);
99  attributesMap[pAttribute->getName()] = pAttribute;
100 
101  return true;
102  }
103 
109  inline bool hasAnyAttributes() const
110  {
111  return !attributesList.empty();
112  }
113 
119  inline unsigned int attributesCount() const
120  {
121  return attributesList.size();
122  }
123 
131  inline bool containsAttribute(const string& strName) const
132  {
133  return (attributesMap.find(strName) != attributesMap.end());
134  }
135 
143  inline const Attribute* getAttributePtr(const string& strName) const
144  {
145  return attributesMap.find(strName)->second;
146  }
147 
151  inline void startIteration()
152  {
153  attributesListIter = attributesList.begin();
154  }
155 
167  inline bool hasNextAttribute() const
168  {
169  return (attributesListIter != attributesList.end());
170  }
171 
183  inline const Attribute* nextAttributePtr()
184  {
185  return *attributesListIter++;
186  }
187 
188 private:
189 
190  // containers
191  list<Attribute*> attributesList;
192  map<string, const Attribute*> attributesMap;
193 
194  // internal list iterator
195  list<Attribute*>::iterator attributesListIter;
196 };
197 
198 // end of vrecko namespace
199 }
200 
201 // end header definitions
202 #endif