14#include "ns3/config.h"
15#include "ns3/fatal-error.h"
16#include "ns3/global-value.h"
18#include "ns3/string.h"
20#include <libxml/encoding.h>
21#include <libxml/xmlreader.h>
22#include <libxml/xmlwriter.h>
108 void StartVisitTypeId(std::string name)
override
113 void DoVisitAttribute(std::string name, std::string defaultValue)
override
115 TypeId tid = TypeId::LookupByName(m_typeid);
117 std::string originalInitialValue;
118 std::string valueTypeName;
122 if (tmp.
name == name)
126 valueTypeName = tmp.
checker->GetValueTypeName();
130 if (valueTypeName ==
"ns3::CallbackValue")
132 NS_LOG_WARN(
"Global attribute " << m_typeid <<
"::" << name
133 <<
" was not saved because it is a CallbackValue");
136 if (supportLevel == TypeId::SupportLevel::OBSOLETE)
138 NS_LOG_WARN(
"Global attribute " << m_typeid <<
"::" << name
139 <<
" was not saved because it is OBSOLETE");
142 if (supportLevel == TypeId::SupportLevel::DEPRECATED &&
143 defaultValue == originalInitialValue)
146 << m_typeid <<
"::" << name
147 <<
" was not saved because it is DEPRECATED and its value has not "
148 "changed from the original initial value");
153 rc = xmlTextWriterStartElement(m_writer, BAD_CAST
"default");
158 std::string fullname = m_typeid +
"::" + name;
159 rc = xmlTextWriterWriteAttribute(m_writer, BAD_CAST
"name", BAD_CAST fullname.c_str());
164 rc = xmlTextWriterWriteAttribute(m_writer,
166 BAD_CAST defaultValue.c_str());
171 rc = xmlTextWriterEndElement(m_writer);
179 std::string m_typeid;
198 void DoVisitAttribute(
Ptr<Object> object, std::string name)
override
201 TypeId tid =
object->GetInstanceTypeId();
203 auto [found, inTid, attr] = TypeId::FindAttribute(tid, name);
207 if (attr.checker && attr.checker->GetValueTypeName() ==
"ns3::CallbackValue")
210 <<
" was not saved because it is a CallbackValue");
213 auto supportLevel = attr.supportLevel;
214 if (supportLevel == TypeId::SupportLevel::OBSOLETE)
217 <<
" was not saved because it is OBSOLETE");
221 std::string originalInitialValue =
222 attr.originalInitialValue->SerializeToString(attr.checker);
223 object->GetAttribute(name, str,
true);
225 if (supportLevel == TypeId::SupportLevel::DEPRECATED &&
226 str.
Get() == originalInitialValue)
230 <<
" was not saved because it is DEPRECATED and its value has not "
231 "changed from the original initial value");
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);
276 (*i)->GetValue(
value);
336 if (std::string((
char*)type) ==
"default")
344 if (
value ==
nullptr)
375 if (std::string((
char*)type) ==
"global")
383 if (
value ==
nullptr)
414 if (std::string((
char*)type) ==
"value")
422 if (
value ==
nullptr)
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.
static Iterator Begin()
The Begin iterator.
static Iterator End()
The End iterator.
Smart pointer class similar to boost::intrusive_ptr.
Hold variables of type string.
a unique identifier for an interface.
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.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static unsigned int value(char c)
xmlTextWriter * xmlTextWriterPtr