24 #include "ns3/fatal-error.h" 26 #include "ns3/global-value.h" 27 #include "ns3/string.h" 28 #include "ns3/config.h" 29 #include <libxml/encoding.h> 30 #include <libxml/xmlwriter.h> 52 m_writer = xmlNewTextWriterFilename (filename.c_str (), 0);
57 rc = xmlTextWriterSetIndent (
m_writer, 1);
65 rc = xmlTextWriterStartDocument (
m_writer, NULL,
"utf-8", NULL);
73 rc = xmlTextWriterStartElement (
m_writer, BAD_CAST
"ns3");
91 rc = xmlTextWriterEndDocument (
m_writer);
106 XmlDefaultIterator (xmlTextWriterPtr writer) {
110 virtual void StartVisitTypeId (std::string name) {
113 virtual void DoVisitAttribute (std::string name, std::string defaultValue) {
115 rc = xmlTextWriterStartElement (
m_writer, BAD_CAST
"default");
120 std::string fullname = m_typeid +
"::" + name;
121 rc = xmlTextWriterWriteAttribute (
m_writer, BAD_CAST
"name",
122 BAD_CAST fullname.c_str ());
127 rc = xmlTextWriterWriteAttribute (
m_writer, BAD_CAST
"value",
128 BAD_CAST defaultValue.c_str ());
133 rc = xmlTextWriterEndElement (
m_writer);
140 std::string m_typeid;
142 XmlDefaultIterator iterator = XmlDefaultIterator (
m_writer);
152 XmlTextAttributeIterator (xmlTextWriterPtr writer)
155 virtual void DoVisitAttribute (
Ptr<Object> object, std::string name) {
157 object->GetAttribute (name, str);
159 rc = xmlTextWriterStartElement (
m_writer, BAD_CAST
"value");
164 rc = xmlTextWriterWriteAttribute (
m_writer, BAD_CAST
"path",
165 BAD_CAST GetCurrentPath ().c_str ());
170 rc = xmlTextWriterWriteAttribute (
m_writer, BAD_CAST
"value",
171 BAD_CAST str.
Get ().c_str ());
176 rc = xmlTextWriterEndElement (
m_writer);
185 XmlTextAttributeIterator iter = XmlTextAttributeIterator (
m_writer);
196 (*i)->GetValue (value);
198 rc = xmlTextWriterStartElement (
m_writer, BAD_CAST
"global");
203 rc = xmlTextWriterWriteAttribute (
m_writer, BAD_CAST
"name",
204 BAD_CAST (*i)->GetName ().c_str ());
209 rc = xmlTextWriterWriteAttribute (
m_writer, BAD_CAST
"value",
210 BAD_CAST value.
Get ().c_str ());
215 rc = xmlTextWriterEndElement (
m_writer);
241 xmlTextReaderPtr reader = xmlNewTextReaderFilename (
m_filename.c_str ());
247 rc = xmlTextReaderRead (reader);
250 const xmlChar *type = xmlTextReaderConstName (reader);
255 if (std::string ((
char*)type) ==
"default")
257 xmlChar *name = xmlTextReaderGetAttribute (reader, BAD_CAST
"name");
262 xmlChar *value = xmlTextReaderGetAttribute (reader, BAD_CAST
"value");
267 NS_LOG_DEBUG (
"default="<<(
char*)name<<
", value=" <<value);
272 rc = xmlTextReaderRead (reader);
274 xmlFreeTextReader (reader);
279 xmlTextReaderPtr reader = xmlNewTextReaderFilename (
m_filename.c_str ());
285 rc = xmlTextReaderRead (reader);
288 const xmlChar *type = xmlTextReaderConstName (reader);
293 if (std::string ((
char*)type) ==
"global")
295 xmlChar *name = xmlTextReaderGetAttribute (reader, BAD_CAST
"name");
300 xmlChar *value = xmlTextReaderGetAttribute (reader, BAD_CAST
"value");
305 NS_LOG_DEBUG (
"global="<<(
char*)name<<
", value=" <<value);
310 rc = xmlTextReaderRead (reader);
312 xmlFreeTextReader (reader);
317 xmlTextReaderPtr reader = xmlNewTextReaderFilename (
m_filename.c_str ());
323 rc = xmlTextReaderRead (reader);
326 const xmlChar *type = xmlTextReaderConstName (reader);
331 if (std::string ((
char*)type) ==
"value")
333 xmlChar *path = xmlTextReaderGetAttribute (reader, BAD_CAST
"path");
338 xmlChar *value = xmlTextReaderGetAttribute (reader, BAD_CAST
"value");
343 NS_LOG_DEBUG (
"path="<<(
char*)path <<
", value=" << (
char*)value);
348 rc = xmlTextReaderRead (reader);
350 xmlFreeTextReader (reader);
virtual void Attributes(void)
Load or save the attributes values.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
virtual void SetFilename(std::string filename)
Set the file name.
Hold variables of type string.
virtual void Default(void)
Load or save the default values.
void Set(std::string path, const AttributeValue &value)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Vector::const_iterator Iterator
Iterator type for the list of all global values.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
std::string Get(void) const
static Iterator Begin(void)
The Begin iterator.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void SetFilename(std::string filename)
Set the file name.
virtual void Global(void)
Load or save the global values.
std::string m_filename
the file name
virtual void Attributes(void)
Load or save the attributes values.
void SetGlobal(std::string name, const AttributeValue &value)
virtual void Global(void)
Load or save the global values.
static Iterator End(void)
The End iterator.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
void SetDefault(std::string name, const AttributeValue &value)
virtual void Default(void)
Load or save the default values.
Iterator to iterate on the values of attributes of an ns3::Object.
xmlTextWriterPtr m_writer
XML writer.
Iterator to iterate on the default values of attributes of an ns3::Object.