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) {
116 virtual void StartVisitTypeId (std::string name) {
119 virtual void DoVisitAttribute (std::string name, std::string defaultValue) {
125 if (tmp.
name == name)
131 if (supportLevel == TypeId::SupportLevel::OBSOLETE)
134 << m_typeid <<
"::" << name
135 <<
" was not saved because it is OBSOLETE");
138 else if ((supportLevel == TypeId::SupportLevel::DEPRECATED) && (
m_saveDeprecated ==
false))
140 NS_LOG_WARN (
"Global attribute " << m_typeid <<
"::" << name
141 <<
" was not saved because it is DEPRECATED");
146 rc = xmlTextWriterStartElement (
m_writer, BAD_CAST
"default");
151 std::string fullname = m_typeid +
"::" + name;
152 rc = xmlTextWriterWriteAttribute (
m_writer, BAD_CAST
"name",
153 BAD_CAST fullname.c_str ());
158 rc = xmlTextWriterWriteAttribute (
m_writer, BAD_CAST
"value",
159 BAD_CAST defaultValue.c_str ());
164 rc = xmlTextWriterEndElement (
m_writer);
171 std::string m_typeid;
174 XmlDefaultIterator iterator = XmlDefaultIterator (
m_writer);
185 XmlTextAttributeIterator (xmlTextWriterPtr writer)
194 virtual void DoVisitAttribute (
Ptr<Object> object, std::string name) {
195 TypeId tid =
object->GetInstanceTypeId ();
200 if (tmp.
name == name)
206 if (supportLevel == TypeId::SupportLevel::OBSOLETE)
209 <<
" was not saved because it is OBSOLETE");
212 else if ((supportLevel == TypeId::SupportLevel::DEPRECATED) && (
m_saveDeprecated ==
false))
215 <<
" was not saved because it is DEPRECATED");
219 object->GetAttribute (name, str);
221 rc = xmlTextWriterStartElement (
m_writer, BAD_CAST
"value");
226 rc = xmlTextWriterWriteAttribute (
m_writer, BAD_CAST
"path",
227 BAD_CAST GetCurrentPath ().c_str ());
232 rc = xmlTextWriterWriteAttribute (
m_writer, BAD_CAST
"value",
233 BAD_CAST str.
Get ().c_str ());
238 rc = xmlTextWriterEndElement (
m_writer);
248 XmlTextAttributeIterator iter = XmlTextAttributeIterator (
m_writer);
260 (*i)->GetValue (value);
262 rc = xmlTextWriterStartElement (
m_writer, BAD_CAST
"global");
267 rc = xmlTextWriterWriteAttribute (
m_writer, BAD_CAST
"name",
268 BAD_CAST (*i)->GetName ().c_str ());
273 rc = xmlTextWriterWriteAttribute (
m_writer, BAD_CAST
"value",
274 BAD_CAST value.Get ().c_str ());
279 rc = xmlTextWriterEndElement (
m_writer);
305 xmlTextReaderPtr reader = xmlNewTextReaderFilename (
m_filename.c_str ());
311 rc = xmlTextReaderRead (reader);
314 const xmlChar *type = xmlTextReaderConstName (reader);
319 if (std::string ((
char*)type) ==
"default")
321 xmlChar *name = xmlTextReaderGetAttribute (reader, BAD_CAST
"name");
326 xmlChar *value = xmlTextReaderGetAttribute (reader, BAD_CAST
"value");
331 NS_LOG_DEBUG (
"default="<<(
char*)name<<
", value=" <<value);
336 rc = xmlTextReaderRead (reader);
338 xmlFreeTextReader (reader);
343 xmlTextReaderPtr reader = xmlNewTextReaderFilename (
m_filename.c_str ());
349 rc = xmlTextReaderRead (reader);
352 const xmlChar *type = xmlTextReaderConstName (reader);
357 if (std::string ((
char*)type) ==
"global")
359 xmlChar *name = xmlTextReaderGetAttribute (reader, BAD_CAST
"name");
364 xmlChar *value = xmlTextReaderGetAttribute (reader, BAD_CAST
"value");
369 NS_LOG_DEBUG (
"global="<<(
char*)name<<
", value=" <<value);
374 rc = xmlTextReaderRead (reader);
376 xmlFreeTextReader (reader);
381 xmlTextReaderPtr reader = xmlNewTextReaderFilename (
m_filename.c_str ());
387 rc = xmlTextReaderRead (reader);
390 const xmlChar *type = xmlTextReaderConstName (reader);
395 if (std::string ((
char*)type) ==
"value")
397 xmlChar *path = xmlTextReaderGetAttribute (reader, BAD_CAST
"path");
402 xmlChar *value = xmlTextReaderGetAttribute (reader, BAD_CAST
"value");
407 NS_LOG_DEBUG (
"path="<<(
char*)path <<
", value=" << (
char*)value);
412 rc = xmlTextReaderRead (reader);
414 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 End(void)
The End iterator.
static Iterator Begin(void)
The Begin iterator.
Hold variables of type string.
std::string Get(void) const
a unique identifier for an interface.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
std::size_t GetAttributeN(void) const
Get the number of attributes.
struct 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.
virtual void SetFilename(std::string filename)
Set the file name.
virtual void Attributes(void)
Load or save the attributes values.
virtual void Default(void)
Load or save the default values.
std::string m_filename
the file name
virtual void Global(void)
Load or save the global values.
virtual void Attributes(void)
Load or save the attributes values.
virtual void Global(void)
Load or save the global values.
xmlTextWriterPtr m_writer
XML writer.
virtual void SetFilename(std::string filename)
Set the file name.
virtual void Default(void)
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.