1 #include "raw-text-config.h"
2 #include "attribute-iterator.h"
3 #include "attribute-default-iterator.h"
4 #include "ns3/global-value.h"
5 #include "ns3/string.h"
7 #include "ns3/config.h"
13 RawTextConfigSave::RawTextConfigSave ()
17 RawTextConfigSave::~RawTextConfigSave ()
27 RawTextConfigSave::SetFilename (std::string filename)
29 m_os =
new std::ofstream ();
30 m_os->open (filename.c_str (), std::ios::out);
33 RawTextConfigSave::Default (
void)
35 class RawTextDefaultIterator :
public AttributeDefaultIterator
38 RawTextDefaultIterator (std::ostream *os) {
42 virtual void StartVisitTypeId (std::string name) {
45 virtual void DoVisitAttribute (std::string name, std::string defaultValue) {
46 *m_os <<
"default " << m_typeId <<
"::" << name <<
" \"" << defaultValue <<
"\"" << std::endl;
52 RawTextDefaultIterator iterator = RawTextDefaultIterator (m_os);
56 RawTextConfigSave::Global (
void)
61 (*i)->GetValue (value);
62 *m_os <<
"global " << (*i)->GetName () <<
" \"" << value.Get () <<
"\"" << std::endl;
66 RawTextConfigSave::Attributes (
void)
68 class RawTextAttributeIterator :
public AttributeIterator
71 RawTextAttributeIterator (std::ostream *os)
74 virtual void DoVisitAttribute (Ptr<Object>
object, std::string name) {
76 object->GetAttribute (name, str);
77 *m_os <<
"value " << GetCurrentPath () <<
" \"" << str.Get () <<
"\"" << std::endl;
82 RawTextAttributeIterator iter = RawTextAttributeIterator (m_os);
86 RawTextConfigLoad::RawTextConfigLoad ()
90 RawTextConfigLoad::~RawTextConfigLoad ()
100 RawTextConfigLoad::SetFilename (std::string filename)
102 m_is =
new std::ifstream ();
103 m_is->open (filename.c_str (), std::ios::in);
106 RawTextConfigLoad::Strip (std::string value)
108 std::string::size_type start = value.find (
"\"");
109 std::string::size_type end = value.find (
"\"", 1);
112 return value.substr (start+1, end-start-1);
116 RawTextConfigLoad::Default (
void)
120 std::string type, name, value;
121 *m_is >> type >> name >> value;
122 while (m_is->good ())
124 NS_LOG_DEBUG (
"type=" << type <<
", name=" << name <<
", value=" << value);
125 value = Strip (value);
126 if (type ==
"default")
130 *m_is >> type >> name >> value;
134 RawTextConfigLoad::Global (
void)
138 std::string type, name, value;
139 *m_is >> type >> name >> value;
140 while (m_is->good ())
142 NS_LOG_DEBUG (
"type=" << type <<
", name=" << name <<
", value=" << value);
143 value = Strip (value);
144 if (type ==
"global")
148 *m_is >> type >> name >> value;
152 RawTextConfigLoad::Attributes (
void)
155 std::string type, path, value;
156 *m_is >> type >> path >> value;
157 while (m_is->good ())
159 NS_LOG_DEBUG (
"type=" << type <<
", path=" << path <<
", value=" << value);
160 value = Strip (value);
165 *m_is >> type >> path >> value;
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
void Set(std::string path, const AttributeValue &value)
static Iterator Begin(void)
void SetDefault(std::string name, const AttributeValue &value)
static Iterator End(void)
#define NS_LOG_DEBUG(msg)
void SetGlobal(std::string name, const AttributeValue &value)