summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2011-04-21 19:21:29 +0000
committerGreg Clayton <gclayton@apple.com>2011-04-21 19:21:29 +0000
commit020b717f6aaad4fdd11897d27a82309af2b8fa16 (patch)
tree04b2c367e6c6d724384c70a8bf5bd4bb4f1779ad
parent6a663b8dc8ed475c5d441c87887478e709a781ff (diff)
downloadbcm5719-llvm-020b717f6aaad4fdd11897d27a82309af2b8fa16.tar.gz
bcm5719-llvm-020b717f6aaad4fdd11897d27a82309af2b8fa16.zip
More iteration on the new option value stuff. We now define an
OptionValueCollection class that can be subclassed to provide access to internal settings that are stored as ObjectValue subclasses. llvm-svn: 129926
-rw-r--r--lldb/include/lldb/Interpreter/NamedOptionValue.h158
-rw-r--r--lldb/source/Interpreter/NamedOptionValue.cpp39
2 files changed, 108 insertions, 89 deletions
diff --git a/lldb/include/lldb/Interpreter/NamedOptionValue.h b/lldb/include/lldb/Interpreter/NamedOptionValue.h
index 5d75d91ff7f..d3001e63bed 100644
--- a/lldb/include/lldb/Interpreter/NamedOptionValue.h
+++ b/lldb/include/lldb/Interpreter/NamedOptionValue.h
@@ -702,91 +702,145 @@ namespace lldb_private {
};
-
+
//---------------------------------------------------------------------
- // NamedOptionValue
+ // OptionValueCollection
+ //
+ // The option value collection is a class that must be subclassed in
+ // order to provide a collection of named OptionValue objects. The
+ // collection is immutable (use OptionValueDictionary for mutable key
+ // value pair collection). This allows classes to have some member
+ // variables that are OptionValue subclasses, and still provide access
+ // to setting and modifying these values from textual commands:
+ //
+ //
+ // class Car : public OptionValueCollection
+ // {
+ // public:
+ //
+ // Car () : OptionValueCollection (NULL, "car"),
+ // m_is_running_name ("running"),
+ // m_license_number_name ("license"),
+ // m_is_running (false, false),
+ // m_license_number ()
+ // {
+ // }
+ //
+ //
+ // bool
+ // GetIsRunning () const
+ // {
+ // return m_is_running.GetCurrentValue();
+ // }
+ //
+ // const char *
+ // GetLicense () const
+ // {
+ // return m_license_number.GetCurrentValue();
+ // }
+ //
+ // virtual uint32_t
+ // GetNumValues() const
+ // {
+ // return 2;
+ // }
+ //
+ // virtual ConstString
+ // GetKeyAtIndex (uint32_t idx) const
+ // {
+ // switch (idx)
+ // {
+ // case 0: return m_is_running_name;
+ // case 1: return m_license_number_name;
+ // }
+ // return ConstString();
+ // }
+ //
+ // virtual OptionValue*
+ // GetValueForKey (const ConstString &key)
+ // {
+ // if (key == m_is_running_name)
+ // return &m_is_running;
+ // else if (key == m_license_number_name)
+ // return &m_license_number;
+ // return NULL;
+ // }
+ //
+ // protected:
+ // ConstString m_is_running_name;
+ // ConstString m_license_number_name;
+ // OptionValueBoolean m_is_running;
+ // OptionValueString m_license_number;
+ //
+ // };
+ //
+ // As we can see above, this allows the Car class to have direct access
+ // to its member variables settings m_is_running and m_license_number,
+ // yet it allows them to also be available by name to our command
+ // interpreter.
//---------------------------------------------------------------------
- class NamedOptionValue
+ class OptionValueCollection
{
public:
-
- NamedOptionValue (NamedOptionValue *parent, const ConstString &name) :
+ OptionValueCollection (OptionValueCollection *parent, const ConstString &name) :
m_parent (parent),
- m_name (name),
- m_user_data (0)
+ m_name (name)
{
}
- virtual
- ~NamedOptionValue ()
+ OptionValueCollection (OptionValueCollection *parent, const char *name) :
+ m_parent (parent),
+ m_name (name)
{
}
+
+ virtual
+ ~OptionValueCollection()
+ {
+ }
+
- NamedOptionValue *
+ OptionValueCollection *
GetParent ()
{
return m_parent;
}
-
- const NamedOptionValue *
+
+ const OptionValueCollection *
GetParent () const
{
return m_parent;
}
-
+
const ConstString &
GetName () const
{
return m_name;
}
-
- uint32_t
- GetUserData () const
- {
- return m_user_data;
- }
-
- void
- SetUserData (uint32_t user_data)
- {
- m_user_data = user_data;
- }
void
GetQualifiedName (Stream &strm);
- lldb::OptionValueSP
- GetValue ()
- {
- return m_value_sp;
- }
-
- void
- SetValue (const lldb::OptionValueSP &value_sp)
- {
- m_value_sp = value_sp;
- }
-
- OptionValue::Type
- GetValueType ();
-
- bool
- DumpValue (Stream &strm);
-
- bool
- SetValueFromCString (const char *value);
+ //---------------------------------------------------------------------
+ // Subclass specific functions
+ //---------------------------------------------------------------------
- bool
- ResetValueToDefault ();
+ virtual uint32_t
+ GetNumValues() const = 0;
+ virtual ConstString
+ GetKeyAtIndex (uint32_t idx) const = 0;
+
+ virtual OptionValue*
+ GetValueForKey (const ConstString &key) = 0;
+
protected:
- NamedOptionValue *m_parent; // NULL if this is a root object
- ConstString m_name; // Name for this setting
- uint32_t m_user_data; // User data that can be used for anything.
- lldb::OptionValueSP m_value_sp; // Abstract option value
+ OptionValueCollection *m_parent; // NULL if this is a root object
+ ConstString m_name; // Name for this collection setting (if any)
};
-
+
+
} // namespace lldb_private
#endif // liblldb_NamedOptionValue_h_
diff --git a/lldb/source/Interpreter/NamedOptionValue.cpp b/lldb/source/Interpreter/NamedOptionValue.cpp
index fec7905108c..987ab472aaa 100644
--- a/lldb/source/Interpreter/NamedOptionValue.cpp
+++ b/lldb/source/Interpreter/NamedOptionValue.cpp
@@ -81,11 +81,11 @@ OptionValue::GetAsDictionaryValue ()
//-------------------------------------------------------------------------
-// NamedOptionValue
+// OptionValueCollection
//-------------------------------------------------------------------------
void
-NamedOptionValue::GetQualifiedName (Stream &strm)
+OptionValueCollection::GetQualifiedName (Stream &strm)
{
if (m_parent)
{
@@ -95,41 +95,6 @@ NamedOptionValue::GetQualifiedName (Stream &strm)
strm << m_name;
}
-OptionValue::Type
-NamedOptionValue::GetValueType ()
-{
- if (m_value_sp)
- return m_value_sp->GetType();
- return OptionValue::eTypeInvalid;
-}
-
-bool
-NamedOptionValue::DumpValue (Stream &strm)
-{
- if (m_value_sp)
- {
- m_value_sp->DumpValue (strm);
- return true;
- }
- return false;
-}
-
-bool
-NamedOptionValue::SetValueFromCString (const char *value_cstr)
-{
- if (m_value_sp)
- return m_value_sp->SetValueFromCString (value_cstr);
- return false;
-}
-
-bool
-NamedOptionValue::ResetValueToDefault ()
-{
- if (m_value_sp)
- return m_value_sp->ResetValueToDefault ();
- return false;
-}
-
//-------------------------------------------------------------------------
// OptionValueBoolean
OpenPOWER on IntegriCloud