config-store coding style changes
This commit is contained in:
@@ -30,24 +30,24 @@ ConfigStore::GetTypeId (void)
|
||||
static TypeId tid = TypeId ("ns3::ConfigStore")
|
||||
.SetParent<ObjectBase> ()
|
||||
.AddAttribute ("Mode",
|
||||
"Configuration mode",
|
||||
EnumValue (ConfigStore::NONE),
|
||||
MakeEnumAccessor (&ConfigStore::SetMode),
|
||||
MakeEnumChecker (ConfigStore::NONE, "None",
|
||||
ConfigStore::LOAD, "Load",
|
||||
ConfigStore::SAVE, "Save"))
|
||||
"Configuration mode",
|
||||
EnumValue (ConfigStore::NONE),
|
||||
MakeEnumAccessor (&ConfigStore::SetMode),
|
||||
MakeEnumChecker (ConfigStore::NONE, "None",
|
||||
ConfigStore::LOAD, "Load",
|
||||
ConfigStore::SAVE, "Save"))
|
||||
.AddAttribute ("Filename",
|
||||
"The file where the configuration should be saved to or loaded from.",
|
||||
StringValue (""),
|
||||
MakeStringAccessor (&ConfigStore::SetFilename),
|
||||
MakeStringChecker ())
|
||||
"The file where the configuration should be saved to or loaded from.",
|
||||
StringValue (""),
|
||||
MakeStringAccessor (&ConfigStore::SetFilename),
|
||||
MakeStringChecker ())
|
||||
.AddAttribute ("FileFormat",
|
||||
"Type of file format",
|
||||
EnumValue (ConfigStore::RAW_TEXT),
|
||||
MakeEnumAccessor (&ConfigStore::SetFileFormat),
|
||||
MakeEnumChecker (ConfigStore::RAW_TEXT, "RawText",
|
||||
ConfigStore::XML, "Xml"))
|
||||
;
|
||||
"Type of file format",
|
||||
EnumValue (ConfigStore::RAW_TEXT),
|
||||
MakeEnumAccessor (&ConfigStore::SetFileFormat),
|
||||
MakeEnumChecker (ConfigStore::RAW_TEXT, "RawText",
|
||||
ConfigStore::XML, "Xml"))
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
TypeId
|
||||
@@ -65,34 +65,34 @@ ConfigStore::ConfigStore ()
|
||||
if (m_fileFormat == ConfigStore::XML)
|
||||
{
|
||||
if (m_mode == ConfigStore::SAVE)
|
||||
{
|
||||
m_file = new XmlConfigSave ();
|
||||
}
|
||||
{
|
||||
m_file = new XmlConfigSave ();
|
||||
}
|
||||
else if (m_mode == ConfigStore::LOAD)
|
||||
{
|
||||
m_file = new XmlConfigLoad ();
|
||||
}
|
||||
{
|
||||
m_file = new XmlConfigLoad ();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_file = new NoneFileConfig ();
|
||||
}
|
||||
{
|
||||
m_file = new NoneFileConfig ();
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif /* HAVE_LIBXML2 */
|
||||
if (m_fileFormat == ConfigStore::RAW_TEXT)
|
||||
{
|
||||
if (m_mode == ConfigStore::SAVE)
|
||||
{
|
||||
m_file = new RawTextConfigSave ();
|
||||
}
|
||||
{
|
||||
m_file = new RawTextConfigSave ();
|
||||
}
|
||||
else if (m_mode == ConfigStore::LOAD)
|
||||
{
|
||||
m_file = new RawTextConfigLoad ();
|
||||
}
|
||||
{
|
||||
m_file = new RawTextConfigLoad ();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_file = new NoneFileConfig ();
|
||||
}
|
||||
{
|
||||
m_file = new NoneFileConfig ();
|
||||
}
|
||||
}
|
||||
m_file->SetFilename (m_filename);
|
||||
}
|
||||
|
||||
@@ -590,5 +590,5 @@ clean_model_callback_config_default (GtkTreeModel *model, GtkTreePath *path,
|
||||
}
|
||||
|
||||
|
||||
}//end ns3 namespace
|
||||
} //end ns3 namespace
|
||||
|
||||
|
||||
@@ -145,6 +145,6 @@ create_view_config_default (GtkTreeStore *model);
|
||||
gboolean
|
||||
clean_model_callback_config_default (GtkTreeModel *model, GtkTreePath *path,
|
||||
GtkTreeIter *iter, gpointer data);
|
||||
}//end namespace ns3
|
||||
} //end namespace ns3
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,12 +3,15 @@
|
||||
namespace ns3 {
|
||||
|
||||
FileConfig::~FileConfig ()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
NoneFileConfig::NoneFileConfig ()
|
||||
{}
|
||||
{
|
||||
}
|
||||
NoneFileConfig::~NoneFileConfig ()
|
||||
{}
|
||||
{
|
||||
}
|
||||
void
|
||||
NoneFileConfig::SetFilename (std::string filename)
|
||||
{}
|
||||
@@ -18,7 +21,7 @@ NoneFileConfig::Default (void)
|
||||
void
|
||||
NoneFileConfig::Global (void)
|
||||
{}
|
||||
void
|
||||
void
|
||||
NoneFileConfig::Attributes (void)
|
||||
{}
|
||||
|
||||
|
||||
@@ -116,8 +116,8 @@ ModelCreator::DoStartVisitArrayItem (const ObjectVectorValue &vector, uint32_t i
|
||||
node->index = index;
|
||||
gtk_tree_store_append (m_treestore, current, parent);
|
||||
gtk_tree_store_set (m_treestore, current,
|
||||
COL_NODE, node,
|
||||
-1);
|
||||
COL_NODE, node,
|
||||
-1);
|
||||
m_iters.push_back (current);
|
||||
}
|
||||
void
|
||||
@@ -125,6 +125,6 @@ ModelCreator::DoEndVisitArrayItem (void)
|
||||
{
|
||||
GtkTreeIter *iter = m_iters.back ();
|
||||
g_free (iter);
|
||||
m_iters.pop_back ();
|
||||
m_iters.pop_back ();
|
||||
}
|
||||
}//end namespace ns3
|
||||
} //end namespace ns3
|
||||
|
||||
@@ -78,4 +78,4 @@ ModelTypeidCreator::EndVisitTypeId (void)
|
||||
{
|
||||
Remove ();
|
||||
}
|
||||
}//end namespace ns3
|
||||
} //end namespace ns3
|
||||
|
||||
@@ -12,7 +12,8 @@ namespace ns3 {
|
||||
|
||||
RawTextConfigSave::RawTextConfigSave ()
|
||||
: m_os (0)
|
||||
{}
|
||||
{
|
||||
}
|
||||
RawTextConfigSave::~RawTextConfigSave ()
|
||||
{
|
||||
if (m_os != 0)
|
||||
@@ -33,11 +34,11 @@ RawTextConfigSave::Default (void)
|
||||
{
|
||||
class RawTextDefaultIterator : public AttributeDefaultIterator
|
||||
{
|
||||
public:
|
||||
public:
|
||||
RawTextDefaultIterator (std::ostream *os) {
|
||||
m_os = os;
|
||||
}
|
||||
private:
|
||||
private:
|
||||
virtual void StartVisitTypeId (std::string name) {
|
||||
m_typeId = name;
|
||||
}
|
||||
@@ -66,10 +67,10 @@ RawTextConfigSave::Attributes (void)
|
||||
{
|
||||
class RawTextAttributeIterator : public AttributeIterator
|
||||
{
|
||||
public:
|
||||
public:
|
||||
RawTextAttributeIterator (std::ostream *os)
|
||||
: m_os (os) {}
|
||||
private:
|
||||
private:
|
||||
virtual void DoVisitAttribute (Ptr<Object> object, std::string name) {
|
||||
StringValue str;
|
||||
object->GetAttribute (name, str);
|
||||
@@ -84,7 +85,8 @@ RawTextConfigSave::Attributes (void)
|
||||
|
||||
RawTextConfigLoad::RawTextConfigLoad ()
|
||||
: m_is (0)
|
||||
{}
|
||||
{
|
||||
}
|
||||
RawTextConfigLoad::~RawTextConfigLoad ()
|
||||
{
|
||||
if (m_is != 0)
|
||||
@@ -121,9 +123,9 @@ RawTextConfigLoad::Default (void)
|
||||
NS_LOG_DEBUG ("type=" << type << ", name=" << name << ", value=" << value);
|
||||
value = Strip (value);
|
||||
if (type == "default")
|
||||
{
|
||||
Config::SetDefault (name, StringValue (value));
|
||||
}
|
||||
{
|
||||
Config::SetDefault (name, StringValue (value));
|
||||
}
|
||||
*m_is >> type >> name >> value;
|
||||
}
|
||||
}
|
||||
@@ -138,9 +140,9 @@ RawTextConfigLoad::Global (void)
|
||||
NS_LOG_DEBUG ("type=" << type << ", name=" << name << ", value=" << value);
|
||||
value = Strip (value);
|
||||
if (type == "global")
|
||||
{
|
||||
Config::SetGlobal (name, StringValue (value));
|
||||
}
|
||||
{
|
||||
Config::SetGlobal (name, StringValue (value));
|
||||
}
|
||||
*m_is >> type >> name >> value;
|
||||
}
|
||||
}
|
||||
@@ -155,9 +157,9 @@ RawTextConfigLoad::Attributes (void)
|
||||
NS_LOG_DEBUG ("type=" << type << ", path=" << path << ", value=" << value);
|
||||
value = Strip (value);
|
||||
if (type == "value")
|
||||
{
|
||||
Config::Set (path, StringValue (value));
|
||||
}
|
||||
{
|
||||
Config::Set (path, StringValue (value));
|
||||
}
|
||||
*m_is >> type >> path >> value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,39 +82,39 @@ XmlConfigSave::Default (void)
|
||||
{
|
||||
class XmlDefaultIterator : public AttributeDefaultIterator
|
||||
{
|
||||
public:
|
||||
public:
|
||||
XmlDefaultIterator (xmlTextWriterPtr writer) {
|
||||
m_writer = writer;
|
||||
}
|
||||
private:
|
||||
private:
|
||||
virtual void StartVisitTypeId (std::string name) {
|
||||
m_typeid = name;
|
||||
}
|
||||
virtual void DoVisitAttribute (std::string name, std::string defaultValue) {
|
||||
int rc;
|
||||
rc = xmlTextWriterStartElement(m_writer, BAD_CAST "default");
|
||||
if (rc < 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterStartElement");
|
||||
}
|
||||
std::string fullname = m_typeid + "::" + name;
|
||||
rc = xmlTextWriterWriteAttribute(m_writer, BAD_CAST "name",
|
||||
BAD_CAST fullname.c_str ());
|
||||
if (rc < 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterWriteAttribute");
|
||||
}
|
||||
rc = xmlTextWriterWriteAttribute(m_writer, BAD_CAST "value",
|
||||
BAD_CAST defaultValue.c_str ());
|
||||
if (rc < 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterWriteAttribute");
|
||||
}
|
||||
if (rc < 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterStartElement");
|
||||
}
|
||||
std::string fullname = m_typeid + "::" + name;
|
||||
rc = xmlTextWriterWriteAttribute(m_writer, BAD_CAST "name",
|
||||
BAD_CAST fullname.c_str ());
|
||||
if (rc < 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterWriteAttribute");
|
||||
}
|
||||
rc = xmlTextWriterWriteAttribute(m_writer, BAD_CAST "value",
|
||||
BAD_CAST defaultValue.c_str ());
|
||||
if (rc < 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterWriteAttribute");
|
||||
}
|
||||
rc = xmlTextWriterEndElement(m_writer);
|
||||
if (rc < 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterEndElement");
|
||||
}
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterEndElement");
|
||||
}
|
||||
}
|
||||
xmlTextWriterPtr m_writer;
|
||||
std::string m_typeid;
|
||||
@@ -128,36 +128,36 @@ XmlConfigSave::Attributes (void)
|
||||
{
|
||||
class XmlTextAttributeIterator : public AttributeIterator
|
||||
{
|
||||
public:
|
||||
public:
|
||||
XmlTextAttributeIterator (xmlTextWriterPtr writer)
|
||||
: m_writer (writer) {}
|
||||
private:
|
||||
private:
|
||||
virtual void DoVisitAttribute (Ptr<Object> object, std::string name) {
|
||||
StringValue str;
|
||||
object->GetAttribute (name, str);
|
||||
int rc;
|
||||
rc = xmlTextWriterStartElement(m_writer, BAD_CAST "value");
|
||||
if (rc < 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterStartElement");
|
||||
}
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterStartElement");
|
||||
}
|
||||
rc = xmlTextWriterWriteAttribute(m_writer, BAD_CAST "path",
|
||||
BAD_CAST GetCurrentPath ().c_str ());
|
||||
BAD_CAST GetCurrentPath ().c_str ());
|
||||
if (rc < 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterWriteAttribute");
|
||||
}
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterWriteAttribute");
|
||||
}
|
||||
rc = xmlTextWriterWriteAttribute(m_writer, BAD_CAST "value",
|
||||
BAD_CAST str.Get ().c_str ());
|
||||
BAD_CAST str.Get ().c_str ());
|
||||
if (rc < 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterWriteAttribute");
|
||||
}
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterWriteAttribute");
|
||||
}
|
||||
rc = xmlTextWriterEndElement(m_writer);
|
||||
if (rc < 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterEndElement");
|
||||
}
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterEndElement");
|
||||
}
|
||||
}
|
||||
xmlTextWriterPtr m_writer;
|
||||
};
|
||||
@@ -176,27 +176,27 @@ XmlConfigSave::Global (void)
|
||||
(*i)->GetValue (value);
|
||||
|
||||
rc = xmlTextWriterStartElement(m_writer, BAD_CAST "global");
|
||||
if (rc < 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterStartElement");
|
||||
}
|
||||
rc = xmlTextWriterWriteAttribute(m_writer, BAD_CAST "name",
|
||||
BAD_CAST (*i)->GetName ().c_str ());
|
||||
if (rc < 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterWriteAttribute");
|
||||
}
|
||||
rc = xmlTextWriterWriteAttribute(m_writer, BAD_CAST "value",
|
||||
BAD_CAST value.Get ().c_str ());
|
||||
if (rc < 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterWriteAttribute");
|
||||
}
|
||||
if (rc < 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterStartElement");
|
||||
}
|
||||
rc = xmlTextWriterWriteAttribute(m_writer, BAD_CAST "name",
|
||||
BAD_CAST (*i)->GetName ().c_str ());
|
||||
if (rc < 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterWriteAttribute");
|
||||
}
|
||||
rc = xmlTextWriterWriteAttribute(m_writer, BAD_CAST "value",
|
||||
BAD_CAST value.Get ().c_str ());
|
||||
if (rc < 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterWriteAttribute");
|
||||
}
|
||||
rc = xmlTextWriterEndElement(m_writer);
|
||||
if (rc < 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterEndElement");
|
||||
}
|
||||
if (rc < 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error at xmlTextWriterEndElement");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,26 +229,26 @@ XmlConfigLoad::Default (void)
|
||||
{
|
||||
const xmlChar *type = xmlTextReaderConstName(reader);
|
||||
if (type == 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Invalid value");
|
||||
}
|
||||
{
|
||||
NS_FATAL_ERROR ("Invalid value");
|
||||
}
|
||||
if (std::string ((char*)type) == "default")
|
||||
{
|
||||
xmlChar *name = xmlTextReaderGetAttribute (reader, BAD_CAST "name");
|
||||
if (name == 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error getting attribute 'name'");
|
||||
}
|
||||
xmlChar *value = xmlTextReaderGetAttribute (reader, BAD_CAST "value");
|
||||
if (value == 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error getting attribute 'value'");
|
||||
}
|
||||
NS_LOG_DEBUG ("default="<<(char*)name<<", value=" <<value);
|
||||
Config::SetDefault ((char*)name, StringValue ((char*)value));
|
||||
xmlFree (name);
|
||||
xmlFree (value);
|
||||
}
|
||||
{
|
||||
xmlChar *name = xmlTextReaderGetAttribute (reader, BAD_CAST "name");
|
||||
if (name == 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error getting attribute 'name'");
|
||||
}
|
||||
xmlChar *value = xmlTextReaderGetAttribute (reader, BAD_CAST "value");
|
||||
if (value == 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error getting attribute 'value'");
|
||||
}
|
||||
NS_LOG_DEBUG ("default="<<(char*)name<<", value=" <<value);
|
||||
Config::SetDefault ((char*)name, StringValue ((char*)value));
|
||||
xmlFree (name);
|
||||
xmlFree (value);
|
||||
}
|
||||
rc = xmlTextReaderRead (reader);
|
||||
}
|
||||
xmlFreeTextReader (reader);
|
||||
@@ -267,26 +267,26 @@ XmlConfigLoad::Global (void)
|
||||
{
|
||||
const xmlChar *type = xmlTextReaderConstName(reader);
|
||||
if (type == 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Invalid value");
|
||||
}
|
||||
{
|
||||
NS_FATAL_ERROR ("Invalid value");
|
||||
}
|
||||
if (std::string ((char*)type) == "global")
|
||||
{
|
||||
xmlChar *name = xmlTextReaderGetAttribute (reader, BAD_CAST "name");
|
||||
if (name == 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error getting attribute 'name'");
|
||||
}
|
||||
xmlChar *value = xmlTextReaderGetAttribute (reader, BAD_CAST "value");
|
||||
if (value == 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error getting attribute 'value'");
|
||||
}
|
||||
NS_LOG_DEBUG ("global="<<(char*)name<<", value=" <<value);
|
||||
Config::SetGlobal ((char*)name, StringValue ((char*)value));
|
||||
xmlFree (name);
|
||||
xmlFree (value);
|
||||
}
|
||||
{
|
||||
xmlChar *name = xmlTextReaderGetAttribute (reader, BAD_CAST "name");
|
||||
if (name == 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error getting attribute 'name'");
|
||||
}
|
||||
xmlChar *value = xmlTextReaderGetAttribute (reader, BAD_CAST "value");
|
||||
if (value == 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error getting attribute 'value'");
|
||||
}
|
||||
NS_LOG_DEBUG ("global="<<(char*)name<<", value=" <<value);
|
||||
Config::SetGlobal ((char*)name, StringValue ((char*)value));
|
||||
xmlFree (name);
|
||||
xmlFree (value);
|
||||
}
|
||||
rc = xmlTextReaderRead (reader);
|
||||
}
|
||||
xmlFreeTextReader (reader);
|
||||
@@ -305,26 +305,26 @@ XmlConfigLoad::Attributes (void)
|
||||
{
|
||||
const xmlChar *type = xmlTextReaderConstName(reader);
|
||||
if (type == 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Invalid value");
|
||||
}
|
||||
{
|
||||
NS_FATAL_ERROR ("Invalid value");
|
||||
}
|
||||
if (std::string ((char*)type) == "value")
|
||||
{
|
||||
xmlChar *path = xmlTextReaderGetAttribute (reader, BAD_CAST "path");
|
||||
if (path == 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error getting attribute 'path'");
|
||||
}
|
||||
xmlChar *value = xmlTextReaderGetAttribute (reader, BAD_CAST "value");
|
||||
if (value == 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error getting attribute 'value'");
|
||||
}
|
||||
NS_LOG_DEBUG ("path="<<(char*)path << ", value=" << (char*)value);
|
||||
Config::Set ((char*)path, StringValue ((char*)value));
|
||||
xmlFree (path);
|
||||
xmlFree (value);
|
||||
}
|
||||
{
|
||||
xmlChar *path = xmlTextReaderGetAttribute (reader, BAD_CAST "path");
|
||||
if (path == 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error getting attribute 'path'");
|
||||
}
|
||||
xmlChar *value = xmlTextReaderGetAttribute (reader, BAD_CAST "value");
|
||||
if (value == 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Error getting attribute 'value'");
|
||||
}
|
||||
NS_LOG_DEBUG ("path="<<(char*)path << ", value=" << (char*)value);
|
||||
Config::Set ((char*)path, StringValue ((char*)value));
|
||||
xmlFree (path);
|
||||
xmlFree (value);
|
||||
}
|
||||
rc = xmlTextReaderRead (reader);
|
||||
}
|
||||
xmlFreeTextReader (reader);
|
||||
|
||||
Reference in New Issue
Block a user