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/xmlwriter.h>
56 m_writer = xmlNewTextWriterFilename(filename.c_str(), 0);
61 rc = xmlTextWriterSetIndent(
m_writer, 1);
69 rc = xmlTextWriterStartDocument(
m_writer,
nullptr,
"utf-8",
nullptr);
77 rc = xmlTextWriterStartElement(
m_writer, BAD_CAST
"ns3");
96 rc = xmlTextWriterEndDocument(
m_writer);
112 XmlDefaultIterator(xmlTextWriterPtr writer)
123 void StartVisitTypeId(std::string name)
override
128 void DoVisitAttribute(std::string name, std::string defaultValue)
override
135 if (tmp.
name == name)
141 if (supportLevel == TypeId::SupportLevel::OBSOLETE)
143 NS_LOG_WARN(
"Global attribute " << m_typeid <<
"::" << name
144 <<
" was not saved because it is OBSOLETE");
147 else if ((supportLevel == TypeId::SupportLevel::DEPRECATED) &&
150 NS_LOG_WARN(
"Global attribute " << m_typeid <<
"::" << name
151 <<
" was not saved because it is DEPRECATED");
156 rc = xmlTextWriterStartElement(
m_writer, BAD_CAST
"default");
161 std::string fullname = m_typeid +
"::" + name;
162 rc = xmlTextWriterWriteAttribute(
m_writer, BAD_CAST
"name", BAD_CAST fullname.c_str());
167 rc = xmlTextWriterWriteAttribute(
m_writer,
169 BAD_CAST defaultValue.c_str());
174 rc = xmlTextWriterEndElement(
m_writer);
182 std::string m_typeid;
186 XmlDefaultIterator iterator = XmlDefaultIterator(
m_writer);
197 XmlTextAttributeIterator(xmlTextWriterPtr writer)
208 void DoVisitAttribute(
Ptr<Object> object, std::string name)
override
210 TypeId tid =
object->GetInstanceTypeId();
215 if (tmp.
name == name)
221 if (supportLevel == TypeId::SupportLevel::OBSOLETE)
224 <<
" was not saved because it is OBSOLETE");
227 else if ((supportLevel == TypeId::SupportLevel::DEPRECATED) &&
231 <<
" was not saved because it is DEPRECATED");
235 object->GetAttribute(name, str);
237 rc = xmlTextWriterStartElement(
m_writer, BAD_CAST
"value");
242 rc = xmlTextWriterWriteAttribute(
m_writer,
244 BAD_CAST GetCurrentPath().c_str());
250 xmlTextWriterWriteAttribute(
m_writer, BAD_CAST
"value", BAD_CAST str.
Get().c_str());
255 rc = xmlTextWriterEndElement(
m_writer);
266 XmlTextAttributeIterator iter = XmlTextAttributeIterator(
m_writer);
278 (*i)->GetValue(
value);
280 rc = xmlTextWriterStartElement(
m_writer, BAD_CAST
"global");
286 xmlTextWriterWriteAttribute(
m_writer, BAD_CAST
"name", BAD_CAST(*i)->GetName().c_str());
291 rc = xmlTextWriterWriteAttribute(
m_writer, BAD_CAST
"value", BAD_CAST
value.Get().c_str());
296 rc = xmlTextWriterEndElement(
m_writer);
324 xmlTextReaderPtr reader = xmlNewTextReaderFilename(
m_filename.c_str());
325 if (reader ==
nullptr)
330 rc = xmlTextReaderRead(reader);
333 const xmlChar*
type = xmlTextReaderConstName(reader);
338 if (std::string((
char*)
type) ==
"default")
340 xmlChar* name = xmlTextReaderGetAttribute(reader, BAD_CAST
"name");
345 xmlChar*
value = xmlTextReaderGetAttribute(reader, BAD_CAST
"value");
346 if (
value ==
nullptr)
355 rc = xmlTextReaderRead(reader);
357 xmlFreeTextReader(reader);
363 xmlTextReaderPtr reader = xmlNewTextReaderFilename(
m_filename.c_str());
364 if (reader ==
nullptr)
369 rc = xmlTextReaderRead(reader);
372 const xmlChar*
type = xmlTextReaderConstName(reader);
377 if (std::string((
char*)
type) ==
"global")
379 xmlChar* name = xmlTextReaderGetAttribute(reader, BAD_CAST
"name");
384 xmlChar*
value = xmlTextReaderGetAttribute(reader, BAD_CAST
"value");
385 if (
value ==
nullptr)
394 rc = xmlTextReaderRead(reader);
396 xmlFreeTextReader(reader);
402 xmlTextReaderPtr reader = xmlNewTextReaderFilename(
m_filename.c_str());
403 if (reader ==
nullptr)
408 rc = xmlTextReaderRead(reader);
411 const xmlChar*
type = xmlTextReaderConstName(reader);
416 if (std::string((
char*)
type) ==
"value")
418 xmlChar*
path = xmlTextReaderGetAttribute(reader, BAD_CAST
"path");
423 xmlChar*
value = xmlTextReaderGetAttribute(reader, BAD_CAST
"value");
424 if (
value ==
nullptr)
433 rc = xmlTextReaderRead(reader);
435 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.