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