add dirtyness tracking to DefaultValueBase
This commit is contained in:
@@ -26,7 +26,8 @@ namespace ns3 {
|
||||
DefaultValueBase::DefaultValueBase (const std::string &name,
|
||||
const std::string &help)
|
||||
: m_name (name),
|
||||
m_help (help)
|
||||
m_help (help),
|
||||
m_dirty (false)
|
||||
{}
|
||||
DefaultValueBase::~DefaultValueBase ()
|
||||
{}
|
||||
@@ -41,9 +42,24 @@ DefaultValueBase::GetHelp (void) const
|
||||
return m_help;
|
||||
}
|
||||
bool
|
||||
DefaultValueBase::IsDirty (void) const
|
||||
{
|
||||
return m_dirty;
|
||||
}
|
||||
void
|
||||
DefaultValueBase::ClearDirtyFlag (void)
|
||||
{
|
||||
m_dirty = false;
|
||||
}
|
||||
bool
|
||||
DefaultValueBase::ParseValue (const std::string &value)
|
||||
{
|
||||
return DoParseValue (value);
|
||||
bool ok = DoParseValue (value);
|
||||
if (ok)
|
||||
{
|
||||
m_dirty = true;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
std::string
|
||||
DefaultValueBase::GetType (void) const
|
||||
@@ -406,7 +422,7 @@ DefaultValueTest::RunTests (void)
|
||||
Bind ("test-c", "257");
|
||||
NumericDefaultValue<float> x ("test-x", "help-x", 10.0);
|
||||
NumericDefaultValue<double> y ("test-y", "help-y", 10.0);
|
||||
|
||||
|
||||
|
||||
EnumDefaultValue<enum MyEnum> e ("test-e", "help-e",
|
||||
MY_ENUM_C, "C",
|
||||
|
||||
@@ -37,6 +37,19 @@ public:
|
||||
virtual ~DefaultValueBase ();
|
||||
std::string GetName (void) const;
|
||||
std::string GetHelp (void) const;
|
||||
|
||||
/**
|
||||
* \returns true if this value is dirty, false otherwise.
|
||||
*
|
||||
* A value becomes dirty when ParseValue is invoked
|
||||
* and it successfully completes. Dirtyness indicates
|
||||
* that the state of the value was changed by a user.
|
||||
*/
|
||||
bool IsDirty (void) const;
|
||||
/**
|
||||
* Clear the dirty state.
|
||||
*/
|
||||
void ClearDirtyFlag (void);
|
||||
// parse a matching parameter
|
||||
// return true in case of success, false otherwise.
|
||||
bool ParseValue (const std::string &value);
|
||||
@@ -45,12 +58,15 @@ public:
|
||||
protected:
|
||||
DefaultValueBase (const std::string &name,
|
||||
const std::string &help);
|
||||
private:
|
||||
DefaultValueBase ();
|
||||
private:
|
||||
virtual bool DoParseValue (const std::string &value) = 0;
|
||||
virtual std::string DoGetType (void) const = 0;
|
||||
virtual std::string DoGetDefaultValue (void) const = 0;
|
||||
std::string m_name;
|
||||
std::string m_help;
|
||||
bool m_dirty;
|
||||
};
|
||||
|
||||
class DefaultValueList
|
||||
|
||||
Reference in New Issue
Block a user