From 6e9b3d811bb3b58abc7308fd2b56cfde08f80a43 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 23 Jul 2007 15:22:36 +0200 Subject: [PATCH] add dirtyness tracking to DefaultValueBase --- src/core/default-value.cc | 22 +++++++++++++++++++--- src/core/default-value.h | 16 ++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/core/default-value.cc b/src/core/default-value.cc index e9643ef3c..9fad9b6b2 100644 --- a/src/core/default-value.cc +++ b/src/core/default-value.cc @@ -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 x ("test-x", "help-x", 10.0); NumericDefaultValue y ("test-y", "help-y", 10.0); - + EnumDefaultValue e ("test-e", "help-e", MY_ENUM_C, "C", diff --git a/src/core/default-value.h b/src/core/default-value.h index efa616041..299d21102 100644 --- a/src/core/default-value.h +++ b/src/core/default-value.h @@ -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