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) {
71 virtual void StartVisitTypeId (std::string name) {
74 virtual void DoVisitAttribute (std::string name, std::string defaultValue) {
76 *
m_os <<
"default " << m_typeId <<
"::" << name <<
" \"" << defaultValue <<
"\"" << std::endl;
82 RawTextDefaultIterator iterator = RawTextDefaultIterator (
m_os);
92 (*i)->GetValue (value);
94 *
m_os <<
"global " << (*i)->GetName () <<
" \"" << value.
Get () <<
"\"" << std::endl;
104 RawTextAttributeIterator (std::ostream *os)
107 virtual void DoVisitAttribute (
Ptr<Object> object, std::string name) {
109 object->GetAttribute (name, str);
111 *
m_os <<
"value " << GetCurrentPath () <<
" \"" << str.
Get () <<
"\"" << std::endl;
116 RawTextAttributeIterator iter = RawTextAttributeIterator (
m_os);
139 m_is =
new std::ifstream ();
140 m_is->open (filename.c_str (), std::ios::in);
146 std::string::size_type
start = value.find (
"\"");
147 std::string::size_type end = value.find (
"\"", 1);
149 NS_ABORT_MSG_IF (end != value.size () - 1,
"Ill-formed attribute value: " << value);
159 std::string type, name, value;
160 for (std::string line; std::getline (*
m_is, line);)
162 if (!
ParseLine (line, type, name, value))
167 NS_LOG_DEBUG (
"type=" << type <<
", name=" << name <<
", value=" << value);
168 value =
Strip (value);
169 if (type ==
"default")
184 std::string type, name, value;
185 for (std::string line; std::getline (*
m_is, line);)
187 if (!
ParseLine (line, type, name, value))
192 NS_LOG_DEBUG (
"type=" << type <<
", name=" << name <<
", value=" << value);
193 value =
Strip (value);
194 if (type ==
"global")
209 std::string type, name, value;
210 for (std::string line; std::getline (*
m_is, line);)
212 if (!
ParseLine (line, type, name, value))
217 NS_LOG_DEBUG (
"type=" << type <<
", name=" << name <<
", value=" << value);
218 value =
Strip (value);
236 std::istringstream iss (line);
244 if (line.front () ==
'#')
250 if (type.empty () && name.empty ())
252 std::istringstream iss (line);
253 iss >> type >> name >> std::ws;
254 std::getline (iss, value);
264 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.
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
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 ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.