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
A
:
public
Object
10
{
11
public
:
12
static
TypeId
GetTypeId
(
void
) {
13
static
TypeId
tid =
TypeId
(
"ns3::A"
)
14
.
SetParent
<
Object
> ()
15
.AddAttribute (
"TestInt16"
,
"help text"
,
16
IntegerValue
(-2),
17
MakeIntegerAccessor (&
A::m_int16
),
18
MakeIntegerChecker<int16_t> ())
19
;
20
return
tid;
21
}
22
int16_t
m_int16
;
23
};
24
25
NS_OBJECT_ENSURE_REGISTERED
(
A
);
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::A::TestInt16"
,
IntegerValue
(-5));
34
35
Ptr<A>
a_obj = CreateObject<A> ();
36
NS_ABORT_MSG_UNLESS
(a_obj->
m_int16
== -5,
"Cannot set A's integer attribute via Config::SetDefault"
);
37
38
Ptr<A>
a2_obj = CreateObject<A> ();
39
a2_obj->
SetAttribute
(
"TestInt16"
,
IntegerValue
(-3));
40
IntegerValue
iv;
41
a2_obj->
GetAttribute
(
"TestInt16"
, iv);
42
NS_ABORT_MSG_UNLESS
(iv.
Get
() == -3,
"Cannot set A'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
(a2_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
}
src
config-store
examples
config-store-save.cc
Generated on Tue Nov 13 2012 10:32:10 for ns-3 by
1.8.1.2