A Discrete-Event Network Simulator
API
model-node-creator.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License version 2 as
4  * published by the Free Software Foundation;
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * Authors: Faker Moatamri <faker.moatamri@sophia.inria.fr>
16  * Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
17  */
18 
19 #include "model-node-creator.h"
20 
21 namespace ns3
22 {
23 
25 {
26 }
27 
28 void
29 
30 ModelCreator::Build(GtkTreeStore* treestore)
31 {
32  m_treestore = treestore;
33  m_iters.push_back(nullptr);
34  // this function will go through all the objects and call on them
35  // DoStartVisitObject, DoIterate and DoEndVisitObject
36  Iterate();
37  NS_ASSERT(m_iters.size() == 1);
38 }
39 
40 void
42 {
43  GtkTreeIter* parent = m_iters.back();
44  auto current = g_new(GtkTreeIter, 1);
45  gtk_tree_store_append(m_treestore, current, parent);
46  gtk_tree_store_set(m_treestore, current, COL_NODE, node, -1);
47  m_iters.push_back(current);
48 }
49 
50 void
52 {
53  GtkTreeIter* iter = m_iters.back();
54  g_free(iter);
55  m_iters.pop_back();
56 }
57 
58 void
60 {
61  auto node = new ModelNode();
62  node->type = ModelNode::NODE_ATTRIBUTE;
63  node->object = object;
64  node->name = name;
65  Add(node);
66  Remove();
67 }
68 
69 void
71 {
72  auto node = new ModelNode();
73  node->type = ModelNode::NODE_OBJECT;
74  node->object = object;
75  Add(node);
76 }
77 
78 void
80 {
81  Remove();
82 }
83 
84 void
86 {
87  auto node = new ModelNode();
88  node->type = ModelNode::NODE_POINTER;
89  node->object = object;
90  node->name = name;
91  Add(node);
92 }
93 
94 void
96 {
97  Remove();
98 }
99 
100 void
102  std::string name,
103  const ObjectPtrContainerValue& vector)
104 {
105  auto node = new ModelNode();
106  node->type = ModelNode::NODE_VECTOR;
107  node->object = object;
108  node->name = name;
109  Add(node);
110 }
111 
112 void
114 {
115  Remove();
116 }
117 
118 void
120  uint32_t index,
121  Ptr<Object> item)
122 {
123  GtkTreeIter* parent = m_iters.back();
124  auto current = g_new(GtkTreeIter, 1);
125  auto node = new ModelNode();
126  node->type = ModelNode::NODE_VECTOR_ITEM;
127  node->object = item;
128  node->index = index;
129  gtk_tree_store_append(m_treestore, current, parent);
130  gtk_tree_store_set(m_treestore, current, COL_NODE, node, -1);
131  m_iters.push_back(current);
132 }
133 
134 void
136 {
137  GtkTreeIter* iter = m_iters.back();
138  g_free(iter);
139  m_iters.pop_back();
140 }
141 } // end namespace ns3
void Iterate()
Start the process of iterating all objects from the root namespace object.
void DoEndVisitArrayAttribute() override
End the visit to the attribute of type ns3::ObjectVectorValue.
void DoEndVisitPointerAttribute() override
End the visit to the attribute of type ns3::PointerValue.
GtkTreeStore * m_treestore
attribute tree
void DoStartVisitObject(Ptr< Object > object) override
This method is called to start the process of visiting the input object.
void DoStartVisitPointerAttribute(Ptr< Object > object, std::string name, Ptr< Object > value) override
Visit the attribute of type ns3::PointerValue, with the provided name, found on the object pointed to...
void DoStartVisitArrayItem(const ObjectPtrContainerValue &vector, uint32_t index, Ptr< Object > item) override
Start to visit the object found in the input array at the provided index.
std::vector< GtkTreeIter * > m_iters
attribute tree item
void Build(GtkTreeStore *treestore)
Allocate attribute tree.
void DoStartVisitArrayAttribute(Ptr< Object > object, std::string name, const ObjectPtrContainerValue &vector) override
Visit the attribute of type ns3::ObjectVectorValue, with the provided name, found on the object point...
void Add(ModelNode *node)
Add item to attribute tree.
void Remove()
Remove current tree item.
void DoEndVisitArrayItem() override
End the visit to the array item.
void DoEndVisitObject() override
This method is called to end the process of visiting the currently visited object.
void DoVisitAttribute(Ptr< Object > object, std::string name) override
This method visits and performs a config-store action (such as saving to a text file) on the attribut...
Container for a set of ns3::Object pointers.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
Every class exported by the ns3 library is enclosed in the ns3 namespace.
A class used in the implementation of the GtkConfigStore.