25 #include "ns3/config.h"
26 #include "ns3/fatal-error.h"
27 #include "ns3/global-value.h"
29 #include "ns3/string.h"
31 #include <libxml/encoding.h>
32 #include <libxml/xmlreader.h>
33 #include <libxml/xmlwriter.h>
57 m_writer = xmlNewTextWriterFilename(filename.c_str(), 0);
70 rc = xmlTextWriterStartDocument(
m_writer,
nullptr,
"utf-8",
nullptr);
78 rc = xmlTextWriterStartElement(
m_writer, BAD_CAST
"ns3");
124 void StartVisitTypeId(std::string name)
override
129 void DoVisitAttribute(std::string name, std::string defaultValue)
override
136 if (tmp.
name == name)
142 if (supportLevel == TypeId::SupportLevel::OBSOLETE)
144 NS_LOG_WARN(
"Global attribute " << m_typeid <<
"::" << name
145 <<
" was not saved because it is OBSOLETE");
148 else if ((supportLevel == TypeId::SupportLevel::DEPRECATED) &&
151 NS_LOG_WARN(
"Global attribute " << m_typeid <<
"::" << name
152 <<
" was not saved because it is DEPRECATED");
157 rc = xmlTextWriterStartElement(
m_writer, BAD_CAST
"default");
162 std::string fullname = m_typeid +
"::" + name;
163 rc = xmlTextWriterWriteAttribute(
m_writer, BAD_CAST
"name", BAD_CAST fullname.c_str());
170 BAD_CAST defaultValue.c_str());
183 std::string m_typeid;
187 XmlDefaultIterator iterator = XmlDefaultIterator(
m_writer);
209 void DoVisitAttribute(
Ptr<Object> object, std::string name)
override
211 TypeId tid =
object->GetInstanceTypeId();
216 if (tmp.
name == name)
222 if (supportLevel == TypeId::SupportLevel::OBSOLETE)
225 <<
" was not saved because it is OBSOLETE");
228 else if ((supportLevel == TypeId::SupportLevel::DEPRECATED) &&
232 <<
" was not saved because it is DEPRECATED");
236 object->GetAttribute(name, str);
238 rc = xmlTextWriterStartElement(
m_writer, BAD_CAST
"value");
245 BAD_CAST GetCurrentPath().c_str());
251 xmlTextWriterWriteAttribute(
m_writer, BAD_CAST
"value", BAD_CAST str.
Get().c_str());
267 XmlTextAttributeIterator iter = XmlTextAttributeIterator(
m_writer);
279 (*i)->GetValue(
value);
281 rc = xmlTextWriterStartElement(
m_writer, BAD_CAST
"global");
287 xmlTextWriterWriteAttribute(
m_writer, BAD_CAST
"name", BAD_CAST(*i)->GetName().c_str());
292 rc = xmlTextWriterWriteAttribute(
m_writer, BAD_CAST
"value", BAD_CAST
value.Get().c_str());
325 xmlTextReaderPtr reader = xmlNewTextReaderFilename(
m_filename.c_str());
326 if (reader ==
nullptr)
331 rc = xmlTextReaderRead(reader);
334 const xmlChar*
type = xmlTextReaderConstName(reader);
339 if (std::string((
char*)
type) ==
"default")
341 xmlChar* name = xmlTextReaderGetAttribute(reader, BAD_CAST
"name");
346 xmlChar*
value = xmlTextReaderGetAttribute(reader, BAD_CAST
"value");
347 if (
value ==
nullptr)
356 rc = xmlTextReaderRead(reader);
358 xmlFreeTextReader(reader);
364 xmlTextReaderPtr reader = xmlNewTextReaderFilename(
m_filename.c_str());
365 if (reader ==
nullptr)
370 rc = xmlTextReaderRead(reader);
373 const xmlChar*
type = xmlTextReaderConstName(reader);
378 if (std::string((
char*)
type) ==
"global")
380 xmlChar* name = xmlTextReaderGetAttribute(reader, BAD_CAST
"name");
385 xmlChar*
value = xmlTextReaderGetAttribute(reader, BAD_CAST
"value");
386 if (
value ==
nullptr)
395 rc = xmlTextReaderRead(reader);
397 xmlFreeTextReader(reader);
403 xmlTextReaderPtr reader = xmlNewTextReaderFilename(
m_filename.c_str());
404 if (reader ==
nullptr)
409 rc = xmlTextReaderRead(reader);
412 const xmlChar*
type = xmlTextReaderConstName(reader);
417 if (std::string((
char*)
type) ==
"value")
419 xmlChar*
path = xmlTextReaderGetAttribute(reader, BAD_CAST
"path");
424 xmlChar*
value = xmlTextReaderGetAttribute(reader, BAD_CAST
"value");
425 if (
value ==
nullptr)
434 rc = xmlTextReaderRead(reader);
436 xmlFreeTextReader(reader);
Iterator to iterate on the default values of attributes of an ns3::Object.
Iterator to iterate on the values of attributes of an ns3::Object.
void SetSaveDeprecated(bool saveDeprecated)
Set if to save deprecated attributes.
bool m_saveDeprecated
save deprecated attributes
Vector::const_iterator Iterator
Iterator type for the list of all global values.
static Iterator Begin()
The Begin iterator.
static Iterator End()
The End iterator.
Hold variables of type string.
a unique identifier for an interface.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
struct TypeId::AttributeInformation GetAttribute(std::size_t i) const
Get Attribute information by index.
std::size_t GetAttributeN() const
Get the number of attributes.
SupportLevel
The level of support or deprecation for attributes or trace sources.
void Global() override
Load or save the global values.
void SetFilename(std::string filename) override
Set the file name.
void Default() override
Load or save the default values.
std::string m_filename
the file name
void Attributes() override
Load or save the attributes values.
~XmlConfigLoad() override
void Global() override
Load or save the global values.
void Attributes() override
Load or save the attributes values.
~XmlConfigSave() override
xmlTextWriterPtr m_writer
XML writer.
void SetFilename(std::string filename) override
Set the file name.
void Default() override
Load or save the default values.
void SetGlobal(std::string name, const AttributeValue &value)
void SetDefault(std::string name, const AttributeValue &value)
void Set(std::string path, const AttributeValue &value)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
xmlTextWriter * xmlTextWriterPtr