A Discrete-Event Network Simulator
API
config-store.cc
Go to the documentation of this file.
1 #include "config-store.h"
2 #include "raw-text-config.h"
3 #include "ns3/abort.h"
4 #include "ns3/string.h"
5 #include "ns3/log.h"
6 #include "ns3/simulator.h"
7 #include "ns3/attribute-construction-list.h"
8 #include "ns3/enum.h"
9 #include "ns3/config-store-config.h"
10 #ifdef HAVE_LIBXML2
11 #include "xml-config.h"
12 #endif
13 
14 #include <string>
15 #include <fstream>
16 #include <iostream>
17 #include <unistd.h>
18 #include <cstdlib>
19 
20 
21 namespace ns3 {
22 
23 NS_LOG_COMPONENT_DEFINE ("ConfigStore");
24 
25 NS_OBJECT_ENSURE_REGISTERED (ConfigStore);
26 
27 TypeId
29 {
30  static TypeId tid = TypeId ("ns3::ConfigStore")
32  .AddAttribute ("Mode",
33  "Configuration mode",
37  ConfigStore::LOAD, "Load",
38  ConfigStore::SAVE, "Save"))
39  .AddAttribute ("Filename",
40  "The file where the configuration should be saved to or loaded from.",
41  StringValue (""),
44  .AddAttribute ("FileFormat",
45  "Type of file format",
49  ConfigStore::XML, "Xml"))
50  ;
51  return tid;
52 }
53 TypeId
55 {
56  return GetTypeId ();
57 }
58 
59 
61 {
63 
64 #ifdef HAVE_LIBXML2
66  {
68  {
69  m_file = new XmlConfigSave ();
70  }
71  else if (m_mode == ConfigStore::LOAD)
72  {
73  m_file = new XmlConfigLoad ();
74  }
75  else
76  {
77  m_file = new NoneFileConfig ();
78  }
79  }
80 #else
82  {
84  {
85  NS_ABORT_MSG ("ConfigStore tried to read or write an XML file but XML is not supported.");
86  }
87  else
88  {
89  m_file = new NoneFileConfig ();
90  }
91  }
92 #endif /* HAVE_LIBXML2 */
93 
95  {
97  {
98  m_file = new RawTextConfigSave ();
99  }
100  else if (m_mode == ConfigStore::LOAD)
101  {
102  m_file = new RawTextConfigLoad ();
103  }
104  else
105  {
106  m_file = new NoneFileConfig ();
107  }
108  }
110 }
111 
113 {
114  delete m_file;
115  m_file = 0;
116 }
117 
118 void
120 {
121  m_mode = mode;
122 }
123 void
125 {
126  m_fileFormat = format;
127 }
128 void
129 ConfigStore::SetFilename (std::string filename)
130 {
131  m_filename = filename;
132 }
133 
134 void
136 {
137  m_file->Attributes ();
138 }
139 
140 void
142 {
143  m_file->Default ();
144  m_file->Global ();
145 }
146 
147 } // namespace ns3
FileConfig * m_file
Definition: config-store.h:63
Ptr< const AttributeChecker > MakeStringChecker(void)
Definition: string.cc:30
virtual void Attributes(void)=0
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:50
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
Hold variables of type string.
Definition: string.h:41
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: config-store.cc:54
void SetFilename(std::string filename)
static TypeId GetTypeId(void)
Definition: config-store.cc:28
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: enum.h:209
virtual void Default(void)=0
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
Anchor the ns-3 type and attribute system.
Definition: object-base.h:68
Hold variables of type enum.
Definition: enum.h:54
List of Attribute name, value and checker triples used to construct Objects.
enum Mode m_mode
Definition: config-store.h:60
void ConfigureDefaults(void)
void SetFileFormat(enum FileFormat format)
void SetMode(enum Mode mode)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void ConstructSelf(const AttributeConstructionList &attributes)
Complete construction of ObjectBase; invoked by derived classes.
Definition: object-base.cc:79
enum FileFormat m_fileFormat
Definition: config-store.h:61
virtual void SetFilename(std::string filename)=0
virtual void Global(void)=0
Ptr< const AttributeChecker > MakeEnumChecker(int v1, std::string n1, int v2, std::string n2, int v3, std::string n3, int v4, std::string n4, int v5, std::string n5, int v6, std::string n6, int v7, std::string n7, int v8, std::string n8, int v9, std::string n9, int v10, std::string n10, int v11, std::string n11, int v12, std::string n12, int v13, std::string n13, int v14, std::string n14, int v15, std::string n15, int v16, std::string n16, int v17, std::string n17, int v18, std::string n18, int v19, std::string n19, int v20, std::string n20, int v21, std::string n21, int v22, std::string n22)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.cc:184
void ConfigureAttributes(void)
std::string m_filename
Definition: config-store.h:62
Ptr< const AttributeAccessor > MakeStringAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: string.h:42
a unique identifier for an interface.
Definition: type-id.h:51
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631