1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  *  This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  *
16  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
17  */
18 
19 #ifndef ATTRIBUTE_ITERATOR_H
20 #define ATTRIBUTE_ITERATOR_H
21 
22 #include "ns3/ptr.h"
23 #include "ns3/object.h"
24 #include "ns3/object-ptr-container.h"
25 #include <vector>
26 
27 namespace ns3 {
28 
29 /**
30  * \ingroup configstore
31  *
32  * \brief Iterator to iterate on the values of attributes of an ns3::Object
33  * \note This class is used internally by ConfigStore and GtkConfigStore.
34  */
35 class AttributeIterator
36 {
37 public:
38   AttributeIterator ();
39   virtual ~AttributeIterator ();
40 
41   /**
42    * Start the process of iterating all objects from the root namespace object
43    */
44   void Iterate (void);
45 protected:
46   /**
47    * Get the current attribute path
48    * \returns the current path string
49    */
50   std::string GetCurrentPath (void) const;
51 private:
52   /**
53    * This method visits and performs a config-store action (such as saving
54    * to a text file) on the attribute values corresponding to the input
55    * object pointer and attribute name.
56    *
57    * \param object the object visited
58    * \param name the attribute name
59    */
60   virtual void DoVisitAttribute (Ptr<Object> object, std::string name) = 0;
61   /**
62    * This method is called to start the process of visiting the input object
63    * \param object the object visited
64    */
65   virtual void DoStartVisitObject (Ptr<Object> object);
66   /**
67    * This method is called to end the process of visiting the currently
68    * visited object.
69    */
70   virtual void DoEndVisitObject (void);
71   /**
72    * Visit the attribute of type ns3::PointerValue, with the provided name,
73    * found on the object pointed to by the first argument.
74    *
75    * \param object the object on which the attribute of type PointerValue resides
76    * \param name the attribute name provided
77    * \param [in] value Ptr to the ns3::Object pointed to by the attribute
78    */
79   virtual void DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value);
80   /**
81    * End the visit to the attribute of type ns3::PointerValue.
82    */
83   virtual void DoEndVisitPointerAttribute (void);
84   /**
85    * Visit the attribute of type ns3::ObjectVectorValue, with the
86    * provided name, found on the object pointed to by the first argument.
87    *
88    * \note type name ObjectVectorValue is an alias for ObjectPtrContainerValue
89    *
90    * \param object the object on which the attribute of type ObjectVectorValue resides
91    * \param name the attribute name provided
92    * \param [in] vector the ObjectPtrContainerValue corresponding to the named attribute
93    */
94   virtual void DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectPtrContainerValue &vector);
95   /**
96    * End the visit to the attribute of type ns3::ObjectVectorValue.
97    */
98   virtual void DoEndVisitArrayAttribute (void);
99   /**
100    * Start to visit the object found in the input array at the provided index
101    * \param vector the array
102    * \param index the index into the array
103    * \param [in] item the array item to visit
104    */
105   virtual void DoStartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr<Object> item);
106   /**
107    * End the visit to the array item
108    */
109   virtual void DoEndVisitArrayItem (void);
110 
111   /**
112    * Perform the iteration
113    * \param object the object visited
114    */
115   void DoIterate (Ptr<Object> object);
116   /**
117    * Check if this object has already been examined
118    * \param object the object to check
119    * \returns true if object has been examined
120    */
121   bool IsExamined (Ptr<const Object> object);
122   /**
123    * Get current attribute path
124    * \param attr the current attribute string
125    * \returns the current path string
126    */
127   std::string GetCurrentPath (std::string attr) const;
128 
129   /**
130    * Visit attribute to perform a config store operation on it
131    * \param object the current object
132    * \param name the attribute name
133    */
134   void VisitAttribute (Ptr<Object> object, std::string name);
135   /**
136    * Start to visit an object to visit its attributes
137    * \param object the current object
138    */
139   void StartVisitObject (Ptr<Object> object);
140   /**
141    * End the visit to the object
142    */
143   void EndVisitObject (void);
144   /**
145    * Visit the attribute of type ns3::PointerValue, with the provided name,
146    * found on the object pointed to by the first argument.
147    *
148    * \param object the object on which the attribute of type PointerValue resides
149    * \param name the attribute name provided
150    * \param [in] value Ptr to the ns3::Object pointed to by the attribute
151    */
152   void StartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value);
153   /**
154    * End the visit to the attribute of type ns3::PointerValue.
155    */
156   void EndVisitPointerAttribute (void);
157   /**
158    * Visit the attribute of type ns3::ObjectVectorValue, with the
159    * provided name, found on the object pointed to by the first argument.
160    *
161    * \note type name ObjectVectorValue is an alias for ObjectPtrContainerValue
162    *
163    * \param object the object on which the attribute of type ObjectVectorValue resides
164    * \param name the attribute name provided
165    * \param [in] vector the ObjectPtrContainerValue corresponding to the named attribute
166    */
167   void StartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectPtrContainerValue &vector);
168   /**
169    * End the visit to the attribute of type ns3::ObjectVectorValue.
170    */
171   void EndVisitArrayAttribute (void);
172   /**
173    * Start to visit the object found in the input array at the provided index
174    * \param vector the array
175    * \param index the index into the array
176    * \param [in] item the array item to visit
177    */
178   void StartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr<Object> item);
179   /**
180    * End the visit to the array item
181    */
182   void EndVisitArrayItem (void);
183 
184 
185   std::vector<Ptr<Object> > m_examined; ///< list of attributes examined
186   std::vector<std::string> m_currentPath; ///< current attribute path
187 };
188 
189 } // namespace ns3
190 
191 #endif /* ATTRIBUTE_ITERATOR_H */
192