A Discrete-Event Network Simulator
API
topology-reader.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2010 Universita' di Firenze, Italy
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Tommaso Pecorella (tommaso.pecorella@unifi.it)
19  * Author: Valerio Sartini (valesar@gmail.com)
20  */
21 
22 #include "ns3/log.h"
23 #include "topology-reader.h"
24 
25 
32 namespace ns3 {
33 
34 NS_LOG_COMPONENT_DEFINE ("TopologyReader");
35 
36 NS_OBJECT_ENSURE_REGISTERED (TopologyReader);
37 
39 {
40  static TypeId tid = TypeId ("ns3::TopologyReader")
41  .SetParent<Object> ()
42  .SetGroupName ("TopologyReader")
43  ;
44  return tid;
45 }
46 
48 {
49  NS_LOG_FUNCTION (this);
50 }
51 
53 {
54  NS_LOG_FUNCTION (this);
55 }
56 
57 void
58 TopologyReader::SetFileName (const std::string &fileName)
59 {
60  m_fileName = fileName;
61 }
62 
63 std::string
65 {
66  return m_fileName;
67 }
68 
69 /* Manipulating the address block */
70 
73 {
74  return m_linksList.begin ();
75 }
76 
79 {
80  return m_linksList.end ();
81 }
82 
83 int
85 {
86  return m_linksList.size ();
87 }
88 
89 bool
91 {
92  return m_linksList.empty ();
93 }
94 
95 void
97 {
98  m_linksList.push_back (link);
99  return;
100 }
101 
102 
103 TopologyReader::Link::Link ( Ptr<Node> fromPtr, const std::string &fromName, Ptr<Node> toPtr, const std::string &toName )
104 {
105  m_fromPtr = fromPtr;
106  m_fromName = fromName;
107  m_toPtr = toPtr;
108  m_toName = toName;
109 }
110 
112 {
113 }
114 
115 
117 {
118  return m_fromPtr;
119 }
120 
121 std::string
123 {
124  return m_fromName;
125 }
126 
127 Ptr<Node>
129 {
130  return m_toPtr;
131 }
132 
133 std::string
135 {
136  return m_toName;
137 }
138 
139 std::string
140 TopologyReader::Link::GetAttribute (const std::string &name) const
141 {
142  NS_ASSERT_MSG (m_linkAttr.find (name) != m_linkAttr.end (), "Requested topology link attribute not found");
143  return m_linkAttr.find (name)->second;
144 }
145 
146 bool
147 TopologyReader::Link::GetAttributeFailSafe (const std::string &name, std::string &value) const
148 {
149  if ( m_linkAttr.find (name) == m_linkAttr.end () )
150  {
151  return false;
152  }
153  value = m_linkAttr.find (name)->second;
154  return true;
155 }
156 
157 void
158 TopologyReader::Link::SetAttribute (const std::string &name, const std::string &value)
159 {
160  m_linkAttr[name] = value;
161 }
162 
165 {
166  return m_linkAttr.begin ();
167 }
170 {
171  return m_linkAttr.end ();
172 }
173 
174 
175 } /* namespace ns3 */
A base class which provides memory management and object aggregation.
Definition: object.h:88
std::list< Link > m_linksList
The container of the links between the nodes.
ConstLinksIterator LinksBegin(void) const
Returns an iterator to the the first link in this block.
void AddLink(Link link)
Adds a link to the topology.
std::list< Link >::const_iterator ConstLinksIterator
Constant iterator to the list of the links.
int LinksSize(void) const
Returns the number of links in this block.
bool LinksEmpty(void) const
Checks if the block contains any links.
ConstLinksIterator LinksEnd(void) const
Returns an iterator to the the last link in this block.
std::string GetFileName(void) const
Returns the input file name.
static TypeId GetTypeId(void)
Get the type ID.
void SetFileName(const std::string &fileName)
Sets the input file name.
std::string m_fileName
The name of the input file.
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:88
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::TopologyReader declaration.