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;
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.
virtual void Global(void)
Load or save the global values.
virtual void Default(void)
Load or save the default 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.
virtual ~RawTextConfigLoad()
destructor
std::ifstream * m_is
Config store input stream.
std::string Strip(std::string value)
Strip out attribute value.
virtual void SetFilename(std::string filename)
Set the file name.
virtual void Attributes(void)
Load or save the attributes values.
std::ofstream * m_os
Config store output stream.
virtual void Attributes(void)
Load or save the attributes values.
virtual ~RawTextConfigSave()
destructor
virtual void SetFilename(std::string filename)
Set the file name.
RawTextConfigSave()
default constructor
virtual void Default(void)
Load or save the default values.
virtual void Global(void)
Load or save the global values.
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.
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.