A Discrete-Event Network Simulator
API
model-typeid-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  * Author: Faker Moatamri <faker.moatamri@sophia.inria.fr>
16  */
17 
18 #include "model-typeid-creator.h"
19 
20 namespace ns3
21 {
22 
24 {
25 }
26 
27 void
28 
29 ModelTypeidCreator::Build(GtkTreeStore* treestore)
30 {
31  m_treestore = treestore;
32  m_iters.push_back(nullptr);
33  Iterate();
34  NS_ASSERT(m_iters.size() == 1);
35 }
36 
37 void
39 {
40  GtkTreeIter* parent = m_iters.back();
41  auto current = g_new(GtkTreeIter, 1);
42  gtk_tree_store_append(m_treestore, current, parent);
43  gtk_tree_store_set(m_treestore, current, COL_TYPEID, node, -1);
44  m_iters.push_back(current);
45 }
46 
47 void
49 {
50  GtkTreeIter* iter = m_iters.back();
51  g_free(iter);
52  m_iters.pop_back();
53 }
54 
55 void
57  std::string name,
58  std::string defaultValue,
59  uint32_t index)
60 {
61  auto node = new ModelTypeid();
62  node->type = ModelTypeid::NODE_ATTRIBUTE;
63  node->tid = tid;
64  node->name = name;
65  node->defaultValue = defaultValue;
66  node->index = index;
67  Add(node);
68  Remove();
69 }
70 
71 void
73 {
74  auto node = new ModelTypeid();
75  node->type = ModelTypeid::NODE_TYPEID;
76  node->tid = TypeId::LookupByName(name);
77  Add(node);
78 }
79 
80 void
82 {
83  Remove();
84 }
85 } // end namespace ns3
void Iterate()
This function will go through all the TypeIds and get only the attributes which are explicit values (...
void EndVisitTypeId() override
Remove the last gtk tree iterator.
void StartVisitTypeId(std::string name) override
Add a node for the new TypeId object.
std::vector< GtkTreeIter * > m_iters
This contains a vector of iterators used to build the TreeStore.
void VisitAttribute(TypeId tid, std::string name, std::string defaultValue, uint32_t index) override
This method will add a ModelTypeid to the GtkTreeIterator.
void Build(GtkTreeStore *treestore)
This method will iterate on typeIds having default attributes and create a model for them,...
void Add(ModelTypeid *node)
Adds a treestore iterator to m_treestore model.
GtkTreeStore * m_treestore
this is the TreeStore model corresponding to the view
void Remove()
Removes the last GtkTreeIterator from m_iters.
a unique identifier for an interface.
Definition: type-id.h:59
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:835
#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.