A Discrete-Event Network Simulator
API
attribute-default-iterator.cc
Go to the documentation of this file.
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  * Authors: Faker Moatamri <faker.moatamri@sophia.inria.fr>
17  * Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 
21 #include "ns3/attribute.h"
22 #include "ns3/pointer.h"
23 #include "ns3/callback.h"
24 #include "ns3/global-value.h"
25 #include "ns3/string.h"
26 #include "ns3/object-ptr-container.h"
27 
28 namespace ns3
29 {
30 
32 {
33 }
34 void
36 {
37  for (uint32_t i = 0; i < TypeId::GetRegisteredN (); i++)
38  {
39  TypeId tid = TypeId::GetRegistered (i);
40  if (tid.MustHideFromDocumentation ())
41  {
42  continue;
43  }
44  bool calledStart = false;
45  for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
46  {
47  struct TypeId::AttributeInformation info = tid.GetAttribute (j);
48  if (!(info.flags & TypeId::ATTR_CONSTRUCT))
49  {
50  // we can't construct the attribute, so, there is no
51  // initial value for the attribute
52  continue;
53  }
54  //No accessor, go to next attribute
55  if (info.accessor == 0)
56  {
57  continue;
58  }
59  if (!info.accessor->HasSetter ())
60  {
61  //skip this attribute it doesn't have an setter
62  continue;
63  }
64  if (info.checker == 0)
65  {
66  //skip, it doesn't have a checker
67  continue;
68  }
69  if (info.initialValue == 0)
70  {
71  //No value, check next attribute
72  continue;
73  }
74  Ptr<const ObjectPtrContainerValue> vector = DynamicCast<const ObjectPtrContainerValue> (info.initialValue);
75  if (vector != 0)
76  {
77  //a vector value, won't take it
78  continue;
79  }
80  Ptr<const PointerValue> pointer = DynamicCast<const PointerValue> (info.initialValue);
81  if (pointer != 0)
82  {
83  //pointer value, won't take it
84  continue;
85  }
86  Ptr<const CallbackValue> callback = DynamicCast<const CallbackValue> (info.initialValue);
87  if (callback != 0)
88  {
89  //callback value, won't take it
90  continue;
91  }
92  //We take only values, no pointers or vectors or callbacks
93  if (!calledStart)
94  {
95  StartVisitTypeId (tid.GetName ());
96  }
97  VisitAttribute (tid, info.name, info.initialValue->SerializeToString (info.checker), j);
98  calledStart = true;
99  }
100  if (calledStart)
101  {
102  EndVisitTypeId ();
103  }
104  }
105 }
106 
107 void
109 {
110 }
111 void
113 {
114 }
115 
116 void
117 AttributeDefaultIterator::DoVisitAttribute (std::string name, std::string defaultValue)
118 {
119 }
120 
121 void
122 AttributeDefaultIterator::VisitAttribute (TypeId tid, std::string name, std::string defaultValue, uint32_t index)
123 {
124  DoVisitAttribute (name, defaultValue);
125 }
126 
127 } // namespace ns3
std::string GetName(void) const
Get the name.
Definition: type-id.cc:969
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
static TypeId GetRegistered(uint16_t i)
Get a TypeId by index.
Definition: type-id.cc:870
The attribute can be written at construction-time.
Definition: type-id.h:65
virtual void EndVisitTypeId(void)
Just an interface that needs to be implemented.
Ptr< const AttributeAccessor > accessor
Accessor object.
Definition: type-id.h:88
Ptr< const AttributeValue > initialValue
Configured initial value.
Definition: type-id.h:86
bool MustHideFromDocumentation(void) const
Check if this TypeId should not be listed in documentation.
Definition: type-id.cc:1061
Attribute implementation.
Definition: type-id.h:76
uint32_t flags
AttributeFlags value.
Definition: type-id.h:82
Ptr< const AttributeChecker > checker
Checker object.
Definition: type-id.h:90
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::string name
Attribute name.
Definition: type-id.h:78
std::size_t GetAttributeN(void) const
Get the number of attributes.
Definition: type-id.cc:1069
void Iterate(void)
This function will go through all the TypeIds and get only the attributes which are explicit values (...
struct TypeId::AttributeInformation GetAttribute(std::size_t i) const
Get Attribute information by index.
Definition: type-id.cc:1076
virtual void DoVisitAttribute(std::string name, std::string defaultValue)
This method is just an interface and needs to be implemented.
virtual void VisitAttribute(TypeId tid, std::string name, std::string defaultValue, uint32_t index)
This method can be implemented, otherwise, it will call DoVisitAttribute.
static uint16_t GetRegisteredN(void)
Get the number of registered TypeIds.
Definition: type-id.cc:864
virtual void StartVisitTypeId(std::string name)
Just an interface that needs to be implemented.
a unique identifier for an interface.
Definition: type-id.h:58