A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
config-store-save.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
#include "ns3/core-module.h"
3
#include "ns3/config-store-module.h"
4
5
#include <iostream>
6
7
using namespace
ns3
;
8
9
class
ConfigExample
:
public
Object
10
{
11
public
:
12
static
TypeId
GetTypeId
(
void
) {
13
static
TypeId
tid =
TypeId
(
"ns3::ConfigExample"
)
14
.
SetParent
<
Object
> ()
15
.AddAttribute (
"TestInt16"
,
"help text"
,
16
IntegerValue
(-2),
17
MakeIntegerAccessor
(&
ConfigExample::m_int16
),
18
MakeIntegerChecker<int16_t> ())
19
;
20
return
tid;
21
}
22
int16_t
m_int16
;
23
};
24
25
NS_OBJECT_ENSURE_REGISTERED
(
ConfigExample
);
26
27
// Assign a new default value to A::TestInt16 (-5)
28
// Configure a TestInt16 value for a special instance of A (to -3)
29
// View the output from the config store
30
//
31
int
main (
int
argc,
char
*argv[])
32
{
33
Config::SetDefault
(
"ns3::ConfigExample::TestInt16"
,
IntegerValue
(-5));
34
35
Ptr<ConfigExample>
a_obj = CreateObject<ConfigExample> ();
36
NS_ABORT_MSG_UNLESS
(a_obj->
m_int16
== -5,
"Cannot set ConfigExample's integer attribute via Config::SetDefault"
);
37
38
Ptr<ConfigExample>
b_obj = CreateObject<ConfigExample> ();
39
b_obj->
SetAttribute
(
"TestInt16"
,
IntegerValue
(-3));
40
IntegerValue
iv;
41
b_obj->
GetAttribute
(
"TestInt16"
, iv);
42
NS_ABORT_MSG_UNLESS
(iv.
Get
() == -3,
"Cannot set ConfigExample's integer attribute via SetAttribute"
);
43
44
// These test objects are not rooted in any ns-3 configuration namespace.
45
// This is usually done automatically for ns3 nodes and channels, but
46
// we can establish a new root and anchor one of them there (note; we
47
// can't use two objects of the same type as roots). Rooting one of these
48
// is necessary for it to show up in the config namespace so that
49
// ConfigureAttributes() will work below.
50
Config::RegisterRootNamespaceObject
(b_obj);
51
52
#ifdef HAVE_LIBXML2
53
// Output config store to XML format
54
Config::SetDefault
(
"ns3::ConfigStore::Filename"
,
StringValue
(
"output-attributes.xml"
));
55
Config::SetDefault
(
"ns3::ConfigStore::FileFormat"
,
StringValue
(
"Xml"
));
56
Config::SetDefault
(
"ns3::ConfigStore::Mode"
,
StringValue
(
"Save"
));
57
ConfigStore
outputConfig;
58
outputConfig.
ConfigureDefaults
();
59
outputConfig.
ConfigureAttributes
();
60
#endif
/* HAVE_LIBXML2 */
61
62
// Output config store to txt format
63
Config::SetDefault
(
"ns3::ConfigStore::Filename"
,
StringValue
(
"output-attributes.txt"
));
64
Config::SetDefault
(
"ns3::ConfigStore::FileFormat"
,
StringValue
(
"RawText"
));
65
Config::SetDefault
(
"ns3::ConfigStore::Mode"
,
StringValue
(
"Save"
));
66
ConfigStore
outputConfig2;
67
outputConfig2.
ConfigureDefaults
();
68
outputConfig2.
ConfigureAttributes
();
69
70
Simulator::Run
();
71
72
Simulator::Destroy
();
73
}
ns3::ConfigStore
Introspection did not find any typical Config paths.
Definition:
config-store.h:34
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:73
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:44
ns3::StringValue
Hold variables of type string.
Definition:
string.h:41
ns3::Simulator::Run
static void Run(void)
Run the simulation.
Definition:
simulator.cc:200
ns3::IntegerValue
Hold a signed integer type.
Definition:
integer.h:44
ConfigExample::m_int16
int16_t m_int16
Definition:
config-store-save.cc:22
ns3::Config::RegisterRootNamespaceObject
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition:
config.cc:761
ns3::MakeIntegerAccessor
Ptr< const AttributeAccessor > MakeIntegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition:
integer.h:45
ns3::IntegerValue::Get
int64_t Get(void) const
Definition:
integer.cc:35
ns3::Simulator::Destroy
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition:
simulator.cc:164
ns3::ConfigStore::ConfigureDefaults
void ConfigureDefaults(void)
Definition:
config-store.cc:142
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::ObjectBase::GetAttribute
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
Definition:
object-base.cc:228
ns3::ConfigStore::ConfigureAttributes
void ConfigureAttributes(void)
Definition:
config-store.cc:136
NS_ABORT_MSG_UNLESS
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
Definition:
abort.h:144
ns3::Config::SetDefault
void SetDefault(std::string name, const AttributeValue &value)
Definition:
config.cc:683
ConfigExample
Definition:
config-store-save.cc:9
ConfigExample::GetTypeId
static TypeId GetTypeId(void)
Definition:
config-store-save.cc:12
ns3::Object
A base class which provides memory management and object aggregation.
Definition:
object.h:87
ns3::ObjectBase::SetAttribute
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition:
object-base.cc:190
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:57
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Definition:
type-id.cc:638
src
config-store
examples
config-store-save.cc
Generated on Wed May 13 2015 14:59:10 for ns-3 by
1.8.9.1