14#include "ns3/config.h"
15#include "ns3/global-value.h"
17#include "ns3/string.h"
50 m_os =
new std::ofstream();
62 RawTextDefaultIterator(std::ostream* os)
68 void StartVisitTypeId(std::string name)
override
73 void DoVisitAttribute(std::string name, std::string defaultValue)
override
76 TypeId tid = TypeId::LookupByName(m_typeId);
78 std::string originalInitialValue;
79 std::string valueTypeName;
87 valueTypeName = tmp.
checker->GetValueTypeName();
91 if (valueTypeName ==
"ns3::CallbackValue")
93 NS_LOG_WARN(
"Global attribute " << m_typeId <<
"::" << name
94 <<
" was not saved because it is a CallbackValue");
97 if (supportLevel == TypeId::SupportLevel::OBSOLETE)
99 NS_LOG_WARN(
"Global attribute " << m_typeId <<
"::" << name
100 <<
" was not saved because it is OBSOLETE");
103 if (supportLevel == TypeId::SupportLevel::DEPRECATED &&
104 defaultValue == originalInitialValue)
107 << m_typeId <<
"::" << name
108 <<
" was not saved because it is DEPRECATED and its value has not "
109 "changed from the original initial value");
112 *m_os <<
"default " << m_typeId <<
"::" << name <<
" \"" << defaultValue <<
"\""
116 std::string m_typeId;
131 (*i)->GetValue(
value);
133 *
m_os <<
"global " << (*i)->GetName() <<
" \"" <<
value.Get() <<
"\"" << std::endl;
145 RawTextAttributeIterator(std::ostream* os)
151 void DoVisitAttribute(
Ptr<Object> object, std::string name)
override
154 TypeId tid =
object->GetInstanceTypeId();
156 auto [found, inTid, attr] = TypeId::FindAttribute(tid, name);
160 if (attr.checker && attr.checker->GetValueTypeName() ==
"ns3::CallbackValue")
163 <<
" was not saved because it is a CallbackValue");
166 auto supportLevel = attr.supportLevel;
167 if (supportLevel == TypeId::SupportLevel::OBSOLETE)
170 <<
" was not saved because it is OBSOLETE");
174 std::string originalInitialValue =
175 attr.originalInitialValue->SerializeToString(attr.checker);
176 object->GetAttribute(name, str,
true);
178 if (supportLevel == TypeId::SupportLevel::DEPRECATED &&
179 str.
Get() == originalInitialValue)
183 <<
" was not saved because it is DEPRECATED and its value has not "
184 "changed from the original initial value");
188 *m_os <<
"value " << GetCurrentPath() <<
" \"" << str.
Get() <<
"\"" << std::endl;
220 m_is =
new std::ifstream();
228 std::string::size_type start =
value.find(
'\"');
229 std::string::size_type end =
value.find(
'\"', 1);
232 return value.substr(start + 1, end - start - 1);
244 for (std::string line; std::getline(*
m_is, line);)
253 if (type ==
"default")
272 for (std::string line; std::getline(*
m_is, line);)
281 if (type ==
"global")
300 for (std::string line; std::getline(*
m_is, line);)
329 std::istringstream
iss(line);
337 if (line.front() ==
'#')
343 if (type.empty() && name.empty())
345 std::istringstream
iss(line);
346 iss >> type >> name >> std::ws;
357 return std::count(
value.begin(),
value.end(),
'"') == 2;
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.
void SetFilename(std::string filename) override
Set the file name.
void Attributes() override
Load or save the attributes values.
RawTextConfigLoad()
default constructor
virtual bool ParseLine(const std::string &line, std::string &type, std::string &name, std::string &value)
Parse (potentially multi-) line configs into type, name, and values.
void Global() override
Load or save the global values.
std::ifstream * m_is
Config store input stream.
std::string Strip(std::string value)
Strip out attribute value.
void Default() override
Load or save the default values.
~RawTextConfigLoad() override
destructor
std::ofstream * m_os
Config store output stream.
void Attributes() override
Load or save the attributes values.
void Global() override
Load or save the global values.
RawTextConfigSave()
default constructor
~RawTextConfigSave() override
destructor
void SetFilename(std::string filename) override
Set the file name.
void Default() override
Load or save the default values.
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 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_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#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_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#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)