25 #include "ns3/config.h"
26 #include "ns3/global-value.h"
28 #include "ns3/string.h"
61 m_os =
new std::ofstream();
62 m_os->open(filename, std::ios::out);
73 RawTextDefaultIterator(std::ostream* os)
84 void StartVisitTypeId(std::string name)
override
89 void DoVisitAttribute(std::string name, std::string defaultValue)
override
103 if (supportLevel == TypeId::SupportLevel::OBSOLETE)
105 NS_LOG_WARN(
"Global attribute " << m_typeId <<
"::" << name
106 <<
" was not saved because it is OBSOLETE");
108 else if (supportLevel == TypeId::SupportLevel::DEPRECATED && !
m_saveDeprecated)
110 NS_LOG_WARN(
"Global attribute " << m_typeId <<
"::" << name
111 <<
" was not saved because it is DEPRECATED");
115 *
m_os <<
"default " << m_typeId <<
"::" << name <<
" \"" << defaultValue <<
"\""
120 std::string m_typeId;
125 RawTextDefaultIterator iterator = RawTextDefaultIterator(
m_os);
137 (*i)->GetValue(value);
139 *
m_os <<
"global " << (*i)->GetName() <<
" \"" << value.Get() <<
"\"" << std::endl;
151 RawTextAttributeIterator(std::ostream* os)
162 void DoVisitAttribute(
Ptr<Object> object, std::string name)
override
167 TypeId tid =
object->GetInstanceTypeId();
172 if (tmp.
name == name)
178 if (supportLevel == TypeId::SupportLevel::OBSOLETE)
181 <<
" was not saved because it is OBSOLETE");
183 else if (supportLevel == TypeId::SupportLevel::DEPRECATED && !
m_saveDeprecated)
186 <<
" was not saved because it is DEPRECATED");
190 object->GetAttribute(name, str);
192 *
m_os <<
"value " << GetCurrentPath() <<
" \"" << str.
Get() <<
"\"" << std::endl;
200 RawTextAttributeIterator iter = RawTextAttributeIterator(
m_os);
226 m_is =
new std::ifstream();
227 m_is->open(filename, std::ios::in);
234 std::string::size_type
start = value.find(
'\"');
235 std::string::size_type end = value.find(
'\"', 1);
237 NS_ABORT_MSG_IF(end != value.size() - 1,
"Ill-formed attribute value: " << value);
238 return value.substr(
start + 1, end -
start - 1);
250 for (std::string line; std::getline(*
m_is, line);)
258 value =
Strip(value);
259 if (
type ==
"default")
278 for (std::string line; std::getline(*
m_is, line);)
286 value =
Strip(value);
287 if (
type ==
"global")
306 for (std::string line; std::getline(*
m_is, line);)
314 value =
Strip(value);
335 std::istringstream iss(line);
343 if (line.front() ==
'#')
349 if (
type.empty() && name.empty())
351 std::istringstream iss(line);
352 iss >>
type >> name >> std::ws;
353 std::getline(iss, value);
363 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.
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.
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.
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 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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.