1 #include "config-store.h"
2 #include "raw-text-config.h"
4 #include "ns3/string.h"
6 #include "ns3/simulator.h"
7 #include "ns3/attribute-construction-list.h"
9 #include "ns3/config-store-config.h"
11 #include "xml-config.h"
26 NS_OBJECT_ENSURE_REGISTERED (ConfigStore);
29 ConfigStore::GetTypeId (
void)
31 static TypeId tid = TypeId (
"ns3::ConfigStore")
32 .SetParent<ObjectBase> ()
33 .AddAttribute (
"Mode",
35 EnumValue (ConfigStore::NONE),
36 MakeEnumAccessor (&ConfigStore::SetMode),
37 MakeEnumChecker (ConfigStore::NONE,
"None",
38 ConfigStore::LOAD,
"Load",
39 ConfigStore::SAVE,
"Save"))
40 .AddAttribute (
"Filename",
41 "The file where the configuration should be saved to or loaded from.",
43 MakeStringAccessor (&ConfigStore::SetFilename),
45 .AddAttribute (
"FileFormat",
46 "Type of file format",
47 EnumValue (ConfigStore::RAW_TEXT),
48 MakeEnumAccessor (&ConfigStore::SetFileFormat),
49 MakeEnumChecker (ConfigStore::RAW_TEXT,
"RawText",
50 ConfigStore::XML,
"Xml"))
61 ConfigStore::ConfigStore ()
66 if (m_fileFormat == ConfigStore::XML)
68 if (m_mode == ConfigStore::SAVE)
72 else if (m_mode == ConfigStore::LOAD)
74 m_file =
new XmlConfigLoad ();
78 m_file =
new NoneFileConfig ();
82 if (m_fileFormat == ConfigStore::XML)
84 if (m_mode == ConfigStore::SAVE || m_mode == ConfigStore::LOAD)
86 NS_ABORT_MSG (
"ConfigStore tried to read or write an XML file but XML is not supported.");
90 m_file =
new NoneFileConfig ();
95 if (m_fileFormat == ConfigStore::RAW_TEXT)
97 if (m_mode == ConfigStore::SAVE)
99 m_file =
new RawTextConfigSave ();
101 else if (m_mode == ConfigStore::LOAD)
103 m_file =
new RawTextConfigLoad ();
107 m_file =
new NoneFileConfig ();
110 m_file->SetFilename (m_filename);
113 ConfigStore::~ConfigStore ()
120 ConfigStore::SetMode (
enum Mode mode)
125 ConfigStore::SetFileFormat (
enum FileFormat format)
127 m_fileFormat = format;
130 ConfigStore::SetFilename (std::string filename)
132 m_filename = filename;
136 ConfigStore::ConfigureAttributes (
void)
138 m_file->Attributes ();
142 ConfigStore::ConfigureDefaults (
void)
virtual TypeId GetInstanceTypeId(void) const
#define NS_LOG_COMPONENT_DEFINE(name)
void ConstructSelf(const AttributeConstructionList &attributes)
#define NS_ABORT_MSG(msg)
Abnormal program termination.