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
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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
28
// Assign a new default value to A::TestInt16 (-5)
29
// Configure a TestInt16 value for a special instance of A (to -3)
30
// View the output from the config store
31
//
32
int
main
(
int
argc,
char
*argv[])
33
{
34
Config::SetDefault
(
"ns3::ConfigExample::TestInt16"
,
IntegerValue
(-5));
35
36
Ptr<ConfigExample>
a_obj = CreateObject<ConfigExample> ();
37
NS_ABORT_MSG_UNLESS
(a_obj->
m_int16
== -5,
"Cannot set ConfigExample's integer attribute via Config::SetDefault"
);
38
39
Ptr<ConfigExample>
b_obj = CreateObject<ConfigExample> ();
40
b_obj->
SetAttribute
(
"TestInt16"
,
IntegerValue
(-3));
41
IntegerValue
iv;
42
b_obj->
GetAttribute
(
"TestInt16"
, iv);
43
NS_ABORT_MSG_UNLESS
(iv.
Get
() == -3,
"Cannot set ConfigExample's integer attribute via SetAttribute"
);
44
45
// These test objects are not rooted in any ns-3 configuration namespace.
46
// This is usually done automatically for ns3 nodes and channels, but
47
// we can establish a new root and anchor one of them there (note; we
48
// can't use two objects of the same type as roots). Rooting one of these
49
// is necessary for it to show up in the config namespace so that
50
// ConfigureAttributes() will work below.
51
Config::RegisterRootNamespaceObject
(b_obj);
52
53
#ifdef HAVE_LIBXML2
54
// Output config store to XML format
55
Config::SetDefault
(
"ns3::ConfigStore::Filename"
,
StringValue
(
"output-attributes.xml"
));
56
Config::SetDefault
(
"ns3::ConfigStore::FileFormat"
,
StringValue
(
"Xml"
));
57
Config::SetDefault
(
"ns3::ConfigStore::Mode"
,
StringValue
(
"Save"
));
58
ConfigStore
outputConfig;
59
outputConfig.
ConfigureDefaults
();
60
outputConfig.
ConfigureAttributes
();
61
#endif
/* HAVE_LIBXML2 */
62
63
// Output config store to txt format
64
Config::SetDefault
(
"ns3::ConfigStore::Filename"
,
StringValue
(
"output-attributes.txt"
));
65
Config::SetDefault
(
"ns3::ConfigStore::FileFormat"
,
StringValue
(
"RawText"
));
66
Config::SetDefault
(
"ns3::ConfigStore::Mode"
,
StringValue
(
"Save"
));
67
ConfigStore
outputConfig2;
68
outputConfig2.
ConfigureDefaults
();
69
outputConfig2.
ConfigureAttributes
();
70
71
Simulator::Run
();
72
73
Simulator::Destroy
();
74
}
ns3::ConfigStore
Doxygen 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:59
ns3::StringValue
hold variables of type string
Definition:
string.h:19
ns3::Simulator::Run
static void Run(void)
Run the simulation until one of:
Definition:
simulator.cc:157
ns3::IntegerValue
Hold a signed integer type.
Definition:
integer.h:45
ns3::NS_OBJECT_ENSURE_REGISTERED
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
ConfigExample::m_int16
int16_t m_int16
Definition:
config-store-save.cc:22
NS_ABORT_MSG_UNLESS
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if cond is false.
Definition:
abort.h:131
ns3::IntegerValue::Get
int64_t Get(void) const
main
int main(int argc, char *argv[])
Definition:
config-store-save.cc:32
ns3::Simulator::Destroy
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition:
simulator.cc:121
ns3::ConfigStore::ConfigureDefaults
void ConfigureDefaults(void)
Definition:
config-store.cc:143
ns3::Config::SetDefault
void SetDefault(std::string name, const AttributeValue &value)
Definition:
config.cc:667
ns3::ObjectBase::GetAttribute
void GetAttribute(std::string name, AttributeValue &value) const
Definition:
object-base.cc:199
ns3::Config::RegisterRootNamespaceObject
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition:
config.cc:745
ns3::ConfigStore::ConfigureAttributes
void ConfigureAttributes(void)
Definition:
config-store.cc:137
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:63
ns3::ObjectBase::SetAttribute
void SetAttribute(std::string name, const AttributeValue &value)
Definition:
object-base.cc:161
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:49
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Definition:
type-id.cc:611
src
config-store
examples
config-store-save.cc
Generated on Sat Apr 19 2014 14:06:51 for ns-3 by
1.8.6