A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
topology-reader.cc
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 
24 #include "topology-reader.h"
25 
26 
27 namespace ns3 {
28 
29 NS_LOG_COMPONENT_DEFINE ("TopologyReader");
30 
31 NS_OBJECT_ENSURE_REGISTERED (TopologyReader);
32 
33 TypeId TopologyReader::GetTypeId (void)
34 {
35  static TypeId tid = TypeId ("ns3::TopologyReader")
36  .SetParent<Object> ()
37  ;
38  return tid;
39 }
40 
41 TopologyReader::TopologyReader ()
42 {
43  NS_LOG_FUNCTION (this);
44 }
45 
46 TopologyReader::~TopologyReader ()
47 {
48  NS_LOG_FUNCTION (this);
49 }
50 
51 void
52 TopologyReader::SetFileName (const std::string &fileName)
53 {
54  m_fileName = fileName;
55 }
56 
57 std::string
59 {
60  return m_fileName;
61 }
62 
63 /* Manipulating the address block */
64 
67 {
68  return m_linksList.begin ();
69 }
70 
73 {
74  return m_linksList.end ();
75 }
76 
77 int
79 {
80  return m_linksList.size ();
81 }
82 
83 bool
85 {
86  return m_linksList.empty ();
87 }
88 
89 void
91 {
92  m_linksList.push_back (link);
93  return;
94 }
95 
96 
97 TopologyReader::Link::Link ( Ptr<Node> fromPtr, const std::string &fromName, Ptr<Node> toPtr, const std::string &toName )
98 {
99  m_fromPtr = fromPtr;
100  m_fromName = fromName;
101  m_toPtr = toPtr;
102  m_toName = toName;
103 }
104 
105 TopologyReader::Link::Link ()
106 {
107 }
108 
109 
111 {
112  return m_fromPtr;
113 }
114 
115 std::string
117 {
118  return m_fromName;
119 }
120 
121 Ptr<Node>
123 {
124  return m_toPtr;
125 }
126 
127 std::string
129 {
130  return m_toName;
131 }
132 
133 std::string
134 TopologyReader::Link::GetAttribute (const std::string &name) const
135 {
136  NS_ASSERT_MSG (m_linkAttr.find (name) != m_linkAttr.end (), "Requested topology link attribute not found");
137  return m_linkAttr.find (name)->second;
138 }
139 
140 bool
141 TopologyReader::Link::GetAttributeFailSafe (const std::string &name, std::string &value) const
142 {
143  if ( m_linkAttr.find (name) == m_linkAttr.end () )
144  {
145  return false;
146  }
147  value = m_linkAttr.find (name)->second;
148  return true;
149 }
150 
151 void
152 TopologyReader::Link::SetAttribute (const std::string &name, const std::string &value)
153 {
154  m_linkAttr[name] = value;
155 }
156 
159 {
160  return m_linkAttr.begin ();
161 }
164 {
165  return m_linkAttr.end ();
166 }
167 
168 
169 } /* namespace ns3 */
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
ConstLinksIterator LinksBegin(void) const
Returns an iterator to the the first link in this block.
std::string GetFileName(void) const
Returns the input file name.
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
bool LinksEmpty(void) const
Checks if the block contains any links.
void AddLink(Link link)
Adds a link to the topology.
int LinksSize(void) const
Returns the number of links in this block.
void SetFileName(const std::string &fileName)
Sets the input file name.
std::list< Link >::const_iterator ConstLinksIterator
Constant iterator to the list of the links.
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
ConstLinksIterator LinksEnd(void) const
Returns an iterator to the the last link in this block.