A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19#ifndef CONFIG_H
20#define CONFIG_H
21
22#include "ptr.h"
23
24#include <string>
25#include <vector>
26
27/**
28 * \file
29 * \ingroup config
30 * Declaration of the various ns3::Config functions and classes.
31 */
32
33namespace ns3
34{
35
36class AttributeValue;
37class Object;
38class CallbackBase;
39
40/**
41 * \ingroup core
42 * \defgroup config Configuration
43 * \brief Configuration of simulation parameters and tracing.
44 */
45
46/**
47 * \ingroup config
48 * Namespace for the various functions implementing the Config system.
49 */
50namespace Config
51{
52
53/**
54 * \ingroup config
55 * Reset the initial value of every attribute as well as the value of every
56 * global to what they were before any call to SetDefault and SetGlobal.
57 */
58void Reset();
59
60/**
61 * \ingroup config
62 * \param [in] path A path to match attributes.
63 * \param [in] value The value to set in all matching attributes.
64 *
65 * This function will attempt to find attributes which
66 * match the input path and will then set their value to the input
67 * value. If no such attributes are found, the function will throw
68 * a fatal error; use SetFailSafe if the lack of a match is to be permitted.
69 */
70void Set(std::string path, const AttributeValue& value);
71/**
72 * \ingroup config
73 * \param [in] path A path to match attributes.
74 * \param [in] value The value to set in all matching attributes.
75 *
76 * This function will attempt to find attributes which
77 * match the input path and will then set their value to the input
78 * value, and will return true if at least one such attribute is found.
79 * \return \c true if any matching attributes could be set.
80 */
81bool SetFailSafe(std::string path, const AttributeValue& value);
82/**
83 * \ingroup config
84 * \param [in] name The full name of the attribute
85 * \param [in] value The value to set.
86 *
87 * This method overrides the initial value of the
88 * matching attribute. This method cannot fail: it will
89 * crash if the input attribute name or value is invalid.
90 */
91void SetDefault(std::string name, const AttributeValue& value);
92/**
93 * \ingroup config
94 * \param [in] name The full name of the attribute
95 * \param [in] value The value to set.
96 * \returns \c true if the value was set successfully, false otherwise.
97 *
98 * This method overrides the initial value of the
99 * matching attribute.
100 */
101bool SetDefaultFailSafe(std::string name, const AttributeValue& value);
102/**
103 * \ingroup config
104 * \param [in] name The name of the requested GlobalValue.
105 * \param [in] value The value to set
106 *
107 * This method is equivalent to GlobalValue::Bind
108 */
109void SetGlobal(std::string name, const AttributeValue& value);
110/**
111 * \ingroup config
112 * \param [in] name The name of the requested GlobalValue.
113 * \param [in] value The value to set
114 * \return \c true if the GlobalValue could be set.
115 *
116 * This method is equivalent to GlobalValue::BindFailSafe
117 */
118bool SetGlobalFailSafe(std::string name, const AttributeValue& value);
119/**
120 * \ingroup config
121 * \param [in] path A path to match trace sources.
122 * \param [in] cb The callback to connect to the matching trace sources.
123 *
124 * This function will attempt to find all trace sources which
125 * match the input path and will then connect the input callback
126 * to them. If no matching trace sources are found, this method will
127 * throw a fatal error. Use ConnectWithoutContextFailSafe if the absence
128 * of matching trace sources should not be fatal.
129 */
130void ConnectWithoutContext(std::string path, const CallbackBase& cb);
131/**
132 * \ingroup config
133 * \param [in] path A path to match trace sources.
134 * \param [in] cb The callback to connect to the matching trace sources.
135 *
136 * This function will attempt to find all trace sources which
137 * match the input path and will then connect the input callback
138 * to them. If no matching trace sources are found, this method will
139 * return false; otherwise true.
140 * \returns \c true if any trace sources could be connected.
141 */
142bool ConnectWithoutContextFailSafe(std::string path, const CallbackBase& cb);
143/**
144 * \ingroup config
145 * \param [in] path A path to match trace sources.
146 * \param [in] cb The callback to disconnect to the matching trace sources.
147 *
148 * This function undoes the work of Config::Connect.
149 */
150void DisconnectWithoutContext(std::string path, const CallbackBase& cb);
151/**
152 * \ingroup config
153 * \param [in] path A path to match trace sources.
154 * \param [in] cb The callback to connect to the matching trace sources.
155 *
156 * This function will attempt to find all trace sources which
157 * match the input path and will then connect the input callback
158 * to them in such a way that the callback will receive an extra
159 * context string upon trace event notification.
160 * If no matching trace sources are found, this method will
161 * throw a fatal error. Use ConnectFailSafe if the absence
162 * of matching trace sources should not be fatal.
163 */
164void Connect(std::string path, const CallbackBase& cb);
165/**
166 * \ingroup config
167 * \param [in] path A path to match trace sources.
168 * \param [in] cb The callback to connect to the matching trace sources.
169 *
170 * This function will attempt to find all trace sources which
171 * match the input path and will then connect the input callback
172 * to them in such a way that the callback will receive an extra
173 * context string upon trace event notification.
174 * \returns \c true if any trace sources could be connected.
175 */
176bool ConnectFailSafe(std::string path, const CallbackBase& cb);
177/**
178 * \ingroup config
179 * \param [in] path A path to match trace sources.
180 * \param [in] cb The callback to connect to the matching trace sources.
181 *
182 * This function undoes the work of Config::ConnectWithContext.
183 */
184void Disconnect(std::string path, const CallbackBase& cb);
185
186/**
187 * \ingroup config
188 * \brief hold a set of objects which match a specific search string.
189 *
190 * This class also allows you to perform a set of configuration operations
191 * on the set of matching objects stored in the container. Specifically,
192 * it is possible to perform bulk Connects and Sets.
193 */
195{
196 public:
197 /** Const iterator over the objects in this container. */
198 typedef std::vector<Ptr<Object>>::const_iterator Iterator;
200 /**
201 * Constructor used only by implementation.
202 *
203 * \param [in] objects The vector of objects to store in this container.
204 * \param [in] contexts The corresponding contexts.
205 * \param [in] path The path used for object matching.
206 */
207 MatchContainer(const std::vector<Ptr<Object>>& objects,
208 const std::vector<std::string>& contexts,
209 std::string path);
210
211 /**
212 * \returns An iterator which points to the first item in the container
213 * @{
214 */
216
218 {
219 return Begin();
220 }
221
222 /** @} */
223 /**
224 * \returns An iterator which points to the last item in the container
225 * @{
226 */
228
230 {
231 return End();
232 }
233
234 /** @} */
235 /**
236 * \returns The number of items in the container
237 * @{
238 */
239 std::size_t GetN() const;
240
241 std::size_t size() const
242 {
243 return GetN();
244 }
245
246 /** @} */
247 /**
248 * \param [in] i Index of item to lookup ([0,n[)
249 * \returns The item requested.
250 */
251 Ptr<Object> Get(std::size_t i) const;
252 /**
253 * \param [in] i Index of item to lookup ([0,n[)
254 * \returns The fully-qualified matching path associated
255 * to the requested item.
256 *
257 * The matching patch uniquely identifies the requested object.
258 */
259 std::string GetMatchedPath(uint32_t i) const;
260 /**
261 * \returns The path used to perform the object matching.
262 */
263 std::string GetPath() const;
264
265 /**
266 * \param [in] name Name of attribute to set
267 * \param [in] value Value to set to the attribute
268 *
269 * Set the specified attribute value to all the objects stored in this
270 * container. This method will raise a fatal error if no such attribute
271 * exists; use SetFailSafe if the absence of the attribute is to be
272 * permitted.
273 * \sa ns3::Config::Set
274 */
275 void Set(std::string name, const AttributeValue& value);
276 /**
277 * \param [in] name Name of attribute to set
278 * \param [in] value Value to set to the attribute
279 *
280 * Set the specified attribute value to all the objects stored in this
281 * container. This method will return true if any attributes could be
282 * set, and false otherwise.
283 * \returns \c true if any attributes could be set.
284 */
285 bool SetFailSafe(std::string name, const AttributeValue& value);
286 /**
287 * \param [in] name The name of the trace source to connect to
288 * \param [in] cb The sink to connect to the trace source
289 *
290 * Connect the specified sink to all the objects stored in this
291 * container. This method will raise a fatal error if no objects could
292 * be connected; use ConnectFailSafe if no connections is a valid possible
293 * outcome.
294 * \sa ns3::Config::Connect
295 */
296 void Connect(std::string name, const CallbackBase& cb);
297 /**
298 * \param [in] name The name of the trace source to connect to
299 * \param [in] cb The sink to connect to the trace source
300 *
301 * Connect the specified sink to all the objects stored in this
302 * container. This method will return true if any trace sources could be
303 * connected, and false otherwise.
304 * \returns \c true if any trace sources could be connected.
305 */
306 bool ConnectFailSafe(std::string name, const CallbackBase& cb);
307 /**
308 * \param [in] name The name of the trace source to connect to
309 * \param [in] cb The sink to connect to the trace source
310 *
311 * Connect the specified sink to all the objects stored in this
312 * container. This method will raise a fatal error if no objects could
313 * be connected; use ConnectWithoutContextFailSafe if no connections is
314 * a valid possible outcome.
315 * \sa ns3::Config::ConnectWithoutContext
316 */
317 void ConnectWithoutContext(std::string name, const CallbackBase& cb);
318 /**
319 * \param [in] name The name of the trace source to connect to
320 * \param [in] cb The sink to connect to the trace source
321 *
322 * Connect the specified sink to all the objects stored in this
323 * container. This method will return true if any trace sources could be
324 * connected, and false otherwise.
325 * \returns \c true if any trace sources could be connected.
326 */
327 bool ConnectWithoutContextFailSafe(std::string name, const CallbackBase& cb);
328 /**
329 * \param [in] name The name of the trace source to disconnect from
330 * \param [in] cb The sink to disconnect from the trace source
331 *
332 * Disconnect the specified sink from all the objects stored in this
333 * container.
334 * \sa ns3::Config::Disconnect
335 */
336 void Disconnect(std::string name, const CallbackBase& cb);
337 /**
338 * \param [in] name The name of the trace source to disconnect from
339 * \param [in] cb The sink to disconnect from the trace source
340 *
341 * Disconnect the specified sink from all the objects stored in this
342 * container.
343 * \sa ns3::Config::DisconnectWithoutContext
344 */
345 void DisconnectWithoutContext(std::string name, const CallbackBase& cb);
346
347 private:
348 /** The list of objects in this container. */
349 std::vector<Ptr<Object>> m_objects;
350 /** The context for each object. */
351 std::vector<std::string> m_contexts;
352 /** The path used to perform the object matching. */
353 std::string m_path;
354};
355
356/**
357 * \ingroup config
358 * \param [in] path The path to perform a match against
359 * \returns A container which contains all the objects which match the input
360 * path.
361 */
362MatchContainer LookupMatches(std::string path);
363
364/**
365 * \ingroup config
366 * \param [in] obj A new root object
367 *
368 * Each root object is used during path matching as
369 * the root of the path by Config::Connect, and Config::Set.
370 */
372/**
373 * \ingroup config
374 * \param [in] obj A new root object
375 *
376 * This function undoes the work of Config::RegisterRootNamespaceObject.
377 */
379
380/**
381 * \ingroup config
382 * \returns The number of registered root namespace objects.
383 */
384std::size_t GetRootNamespaceObjectN();
385
386/**
387 * \ingroup config
388 * \param [in] i The index of the requested object.
389 * \returns The requested root namespace object
390 */
392
393} // namespace Config
394
395} // namespace ns3
396
397#endif /* CONFIG_H */
Hold a value for an Attribute.
Definition: attribute.h:70
Base class for Callback class.
Definition: callback.h:360
hold a set of objects which match a specific search string.
Definition: config.h:195
bool SetFailSafe(std::string name, const AttributeValue &value)
Definition: config.cc:119
void Connect(std::string name, const CallbackBase &cb)
Definition: config.cc:132
void DisconnectWithoutContext(std::string name, const CallbackBase &cb)
Definition: config.cc:191
void Set(std::string name, const AttributeValue &value)
Definition: config.cc:107
Ptr< Object > Get(std::size_t i) const
Definition: config.cc:86
void Disconnect(std::string name, const CallbackBase &cb)
Definition: config.cc:178
std::string GetMatchedPath(uint32_t i) const
Definition: config.cc:93
MatchContainer::Iterator End() const
Definition: config.cc:72
MatchContainer::Iterator begin() const
Definition: config.h:217
bool ConnectFailSafe(std::string name, const CallbackBase &cb)
Definition: config.cc:141
std::string GetPath() const
Definition: config.cc:100
bool ConnectWithoutContextFailSafe(std::string name, const CallbackBase &cb)
Definition: config.cc:165
std::size_t size() const
Definition: config.h:241
std::string m_path
The path used to perform the object matching.
Definition: config.h:353
void ConnectWithoutContext(std::string name, const CallbackBase &cb)
Definition: config.cc:156
std::size_t GetN() const
Definition: config.cc:79
std::vector< Ptr< Object > >::const_iterator Iterator
Const iterator over the objects in this container.
Definition: config.h:198
MatchContainer::Iterator end() const
Definition: config.h:229
std::vector< Ptr< Object > > m_objects
The list of objects in this container.
Definition: config.h:349
MatchContainer::Iterator Begin() const
Definition: config.cc:65
std::vector< std::string > m_contexts
The context for each object.
Definition: config.h:351
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
void Reset()
Reset the initial value of every attribute as well as the value of every global to what they were bef...
Definition: config.cc:859
void SetGlobal(std::string name, const AttributeValue &value)
Definition: config.cc:940
bool SetFailSafe(std::string path, const AttributeValue &value)
Definition: config.cc:887
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:894
void Disconnect(std::string path, const CallbackBase &cb)
Definition: config.cc:995
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:978
MatchContainer LookupMatches(std::string path)
Definition: config.cc:1002
void DisconnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:971
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:954
bool ConnectFailSafe(std::string path, const CallbackBase &cb)
Definition: config.cc:988
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:1016
Ptr< Object > GetRootNamespaceObject(uint32_t i)
Definition: config.cc:1030
bool SetGlobalFailSafe(std::string name, const AttributeValue &value)
Definition: config.cc:947
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:880
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:1009
std::size_t GetRootNamespaceObjectN()
Definition: config.cc:1023
bool SetDefaultFailSafe(std::string fullName, const AttributeValue &value)
Definition: config.cc:904
bool ConnectWithoutContextFailSafe(std::string path, const CallbackBase &cb)
Definition: config.cc:964
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Ptr smart pointer declaration and implementation.