A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("ConfigStore");
22 
23 namespace ns3 {
24 
25 
26 NS_OBJECT_ENSURE_REGISTERED (ConfigStore)
27  ;
28 
29 TypeId
31 {
32  static TypeId tid = TypeId ("ns3::ConfigStore")
34  .AddAttribute ("Mode",
35  "Configuration mode",
39  ConfigStore::LOAD, "Load",
40  ConfigStore::SAVE, "Save"))
41  .AddAttribute ("Filename",
42  "The file where the configuration should be saved to or loaded from.",
43  StringValue (""),
44  MakeStringAccessor (&ConfigStore::SetFilename),
45  MakeStringChecker ())
46  .AddAttribute ("FileFormat",
47  "Type of file format",
51  ConfigStore::XML, "Xml"))
52  ;
53  return tid;
54 }
55 TypeId
57 {
58  return GetTypeId ();
59 }
60 
61 
63 {
65 
66 #ifdef HAVE_LIBXML2
68  {
70  {
71  m_file = new XmlConfigSave ();
72  }
73  else if (m_mode == ConfigStore::LOAD)
74  {
75  m_file = new XmlConfigLoad ();
76  }
77  else
78  {
79  m_file = new NoneFileConfig ();
80  }
81  }
82 #else
84  {
86  {
87  NS_ABORT_MSG ("ConfigStore tried to read or write an XML file but XML is not supported.");
88  }
89  else
90  {
91  m_file = new NoneFileConfig ();
92  }
93  }
94 #endif /* HAVE_LIBXML2 */
95 
97  {
99  {
100  m_file = new RawTextConfigSave ();
101  }
102  else if (m_mode == ConfigStore::LOAD)
103  {
104  m_file = new RawTextConfigLoad ();
105  }
106  else
107  {
108  m_file = new NoneFileConfig ();
109  }
110  }
112 }
113 
115 {
116  delete m_file;
117  m_file = 0;
118 }
119 
120 void
122 {
123  m_mode = mode;
124 }
125 void
127 {
128  m_fileFormat = format;
129 }
130 void
131 ConfigStore::SetFilename (std::string filename)
132 {
133  m_filename = filename;
134 }
135 
136 void
138 {
139  m_file->Attributes ();
140 }
141 
142 void
144 {
145  m_file->Default ();
146  m_file->Global ();
147 }
148 
149 } // namespace ns3
FileConfig * m_file
Definition: config-store.h:63
virtual void Attributes(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)
Definition: enum.cc:178
NS_LOG_COMPONENT_DEFINE("ConfigStore")
hold variables of type string
Definition: string.h:19
virtual TypeId GetInstanceTypeId(void) const
Definition: config-store.cc:56
void SetFilename(std::string filename)
static TypeId GetTypeId(void)
Definition: config-store.cc:30
virtual void Default(void)=0
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
implement the ns-3 type and attribute system
Definition: object-base.h:70
hold variables of type 'enum'
Definition: enum.h:37
enum Mode m_mode
Definition: config-store.h:60
void ConfigureDefaults(void)
void SetFileFormat(enum FileFormat format)
void SetMode(enum Mode mode)
void ConstructSelf(const AttributeConstructionList &attributes)
Definition: object-base.cc:66
enum FileFormat m_fileFormat
Definition: config-store.h:61
virtual void SetFilename(std::string filename)=0
virtual void Global(void)=0
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Definition: enum.h:118
#define NS_ABORT_MSG(msg)
Abnormal program termination.
Definition: abort.h:43
void ConfigureAttributes(void)
std::string m_filename
Definition: config-store.h:62
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611