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 && !
m_saveDeprecated)
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());
169 BAD_CAST defaultValue.c_str());
182 std::string m_typeid;
186 XmlDefaultIterator iterator = XmlDefaultIterator(
m_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 && !
m_saveDeprecated)
230 <<
" was not saved because it is DEPRECATED");
234 object->GetAttribute(name, str);
236 rc = xmlTextWriterStartElement(
m_writer, BAD_CAST
"value");
243 BAD_CAST GetCurrentPath().c_str());
249 xmlTextWriterWriteAttribute(
m_writer, BAD_CAST
"value", BAD_CAST str.
Get().c_str());
265 XmlTextAttributeIterator iter = XmlTextAttributeIterator(
m_writer);
277 (*i)->GetValue(value);
279 rc = xmlTextWriterStartElement(
m_writer, BAD_CAST
"global");
285 xmlTextWriterWriteAttribute(
m_writer, BAD_CAST
"name", BAD_CAST(*i)->GetName().c_str());
290 rc = xmlTextWriterWriteAttribute(
m_writer, BAD_CAST
"value", BAD_CAST value.Get().c_str());
323 xmlTextReaderPtr reader = xmlNewTextReaderFilename(
m_filename.c_str());
324 if (reader ==
nullptr)
329 rc = xmlTextReaderRead(reader);
332 const xmlChar*
type = xmlTextReaderConstName(reader);
337 if (std::string((
char*)
type) ==
"default")
339 xmlChar* name = xmlTextReaderGetAttribute(reader, BAD_CAST
"name");
344 xmlChar* value = xmlTextReaderGetAttribute(reader, BAD_CAST
"value");
345 if (value ==
nullptr)
349 NS_LOG_DEBUG(
"default=" << (
char*)name <<
", value=" << value);
354 rc = xmlTextReaderRead(reader);
356 xmlFreeTextReader(reader);
362 xmlTextReaderPtr reader = xmlNewTextReaderFilename(
m_filename.c_str());
363 if (reader ==
nullptr)
368 rc = xmlTextReaderRead(reader);
371 const xmlChar*
type = xmlTextReaderConstName(reader);
376 if (std::string((
char*)
type) ==
"global")
378 xmlChar* name = xmlTextReaderGetAttribute(reader, BAD_CAST
"name");
383 xmlChar* value = xmlTextReaderGetAttribute(reader, BAD_CAST
"value");
384 if (value ==
nullptr)
388 NS_LOG_DEBUG(
"global=" << (
char*)name <<
", value=" << value);
393 rc = xmlTextReaderRead(reader);
395 xmlFreeTextReader(reader);
401 xmlTextReaderPtr reader = xmlNewTextReaderFilename(
m_filename.c_str());
402 if (reader ==
nullptr)
407 rc = xmlTextReaderRead(reader);
410 const xmlChar*
type = xmlTextReaderConstName(reader);
415 if (std::string((
char*)
type) ==
"value")
417 xmlChar* path = xmlTextReaderGetAttribute(reader, BAD_CAST
"path");
422 xmlChar* value = xmlTextReaderGetAttribute(reader, BAD_CAST
"value");
423 if (value ==
nullptr)
427 NS_LOG_DEBUG(
"path=" << (
char*)path <<
", value=" << (
char*)value);
432 rc = xmlTextReaderRead(reader);
434 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
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.
std::size_t GetAttributeN() const
Get the number of attributes.
TypeId::AttributeInformation GetAttribute(std::size_t i) const
Get Attribute information by index.
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