|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
24 #include "ns3/global-value.h"
25 #include "ns3/string.h"
27 #include "ns3/config.h"
57 m_os =
new std::ofstream ();
58 m_os->open (filename.c_str (), std::ios::out);
67 RawTextDefaultIterator (std::ostream *os) {
75 virtual void StartVisitTypeId (std::string name) {
78 virtual void DoVisitAttribute (std::string name, std::string defaultValue) {
91 if (supportLevel == TypeId::SupportLevel::OBSOLETE)
94 << m_typeId <<
"::" << name
95 <<
" was not saved because it is OBSOLETE");
97 else if ((supportLevel == TypeId::SupportLevel::DEPRECATED) && (
m_saveDeprecated ==
false))
99 NS_LOG_WARN (
"Global attribute " << m_typeId <<
"::" << name
100 <<
" was not saved because it is DEPRECATED");
104 *
m_os <<
"default " << m_typeId <<
"::" << name <<
" \"" << defaultValue <<
"\""
108 std::string m_typeId;
113 RawTextDefaultIterator iterator = RawTextDefaultIterator (
m_os);
124 (*i)->GetValue (value);
126 *
m_os <<
"global " << (*i)->GetName () <<
" \"" << value.
Get () <<
"\"" << std::endl;
136 RawTextAttributeIterator (std::ostream *os)
144 virtual void DoVisitAttribute (
Ptr<Object> object, std::string name) {
148 TypeId tid =
object->GetInstanceTypeId ();
153 if (tmp.
name == name)
159 if (supportLevel == TypeId::SupportLevel::OBSOLETE)
162 <<
" was not saved because it is OBSOLETE");
164 else if ((supportLevel == TypeId::SupportLevel::DEPRECATED) && (
m_saveDeprecated ==
false))
167 <<
" was not saved because it is DEPRECATED");
171 object->GetAttribute (name, str);
173 *
m_os <<
"value " << GetCurrentPath () <<
" \"" << str.
Get () <<
"\"" << std::endl;
180 RawTextAttributeIterator iter = RawTextAttributeIterator (
m_os);
204 m_is =
new std::ifstream ();
205 m_is->open (filename.c_str (), std::ios::in);
211 std::string::size_type
start = value.find (
"\"");
212 std::string::size_type end = value.find (
"\"", 1);
214 NS_ABORT_MSG_IF (end != value.size () - 1,
"Ill-formed attribute value: " << value);
224 std::string type, name, value;
225 for (std::string line; std::getline (*
m_is, line);)
227 if (!
ParseLine (line, type, name, value))
232 NS_LOG_DEBUG (
"type=" << type <<
", name=" << name <<
", value=" << value);
233 value =
Strip (value);
234 if (type ==
"default")
249 std::string type, name, value;
250 for (std::string line; std::getline (*
m_is, line);)
252 if (!
ParseLine (line, type, name, value))
257 NS_LOG_DEBUG (
"type=" << type <<
", name=" << name <<
", value=" << value);
258 value =
Strip (value);
259 if (type ==
"global")
274 std::string type, name, value;
275 for (std::string line; std::getline (*
m_is, line);)
277 if (!
ParseLine (line, type, name, value))
282 NS_LOG_DEBUG (
"type=" << type <<
", name=" << name <<
", value=" << value);
283 value =
Strip (value);
301 std::istringstream iss (line);
309 if (line.front () ==
'#')
315 if (type.empty () && name.empty ())
317 std::istringstream iss (line);
318 iss >> type >> name >> std::ws;
319 std::getline (iss, value);
329 return std::count (value.begin (), value.end (),
'"') == 2;
a unique identifier for an interface.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
RawTextConfigLoad()
default constructor
void Set(std::string path, const AttributeValue &value)
virtual void Global(void)
Load or save the global values.
Iterator to iterate on the default values of attributes of an ns3::Object.
virtual void Global(void)
Load or save the global values.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void Attributes(void)
Load or save the attributes values.
std::ofstream * m_os
Config store output stream.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
SupportLevel
The level of support or deprecation for attributes or trace sources.
std::size_t GetAttributeN(void) const
Get the number of attributes.
virtual void SetFilename(std::string filename)
Set the file name.
virtual void SetFilename(std::string filename)
Set the file name.
static Iterator Begin(void)
The Begin iterator.
virtual void Attributes(void)
Load or save the attributes values.
Iterator to iterate on the values of attributes of an ns3::Object.
static Iterator End(void)
The End iterator.
virtual ~RawTextConfigSave()
destructor
std::string Get(void) const
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
std::ifstream * m_is
Config store input stream.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Hold variables of type string.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
virtual ~RawTextConfigLoad()
destructor
virtual void Default(void)
Load or save the default values.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
void SetGlobal(std::string name, const AttributeValue &value)
RawTextConfigSave()
default constructor
void SetSaveDeprecated(bool saveDeprecated)
Set if to save deprecated attributes.
void SetDefault(std::string name, const AttributeValue &value)
virtual void Default(void)
Load or save the default values.
Vector::const_iterator Iterator
Iterator type for the list of all global values.
std::string Strip(std::string value)
Strip out attribute value.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
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.
struct TypeId::AttributeInformation GetAttribute(std::size_t i) const
Get Attribute information by index.
bool m_saveDeprecated
save deprecated attributes