[Lldb-commits] [lldb] r129926 - in /lldb/trunk: include/lldb/Interpreter/NamedOptionValue.h source/Interpreter/NamedOptionValue.cpp

Greg Clayton gclayton at apple.com
Thu Apr 21 12:21:29 PDT 2011


Author: gclayton
Date: Thu Apr 21 14:21:29 2011
New Revision: 129926

URL: http://llvm.org/viewvc/llvm-project?rev=129926&view=rev
Log:
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.


Modified:
    lldb/trunk/include/lldb/Interpreter/NamedOptionValue.h
    lldb/trunk/source/Interpreter/NamedOptionValue.cpp

Modified: lldb/trunk/include/lldb/Interpreter/NamedOptionValue.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/NamedOptionValue.h?rev=129926&r1=129925&r2=129926&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/NamedOptionValue.h (original)
+++ lldb/trunk/include/lldb/Interpreter/NamedOptionValue.h Thu Apr 21 14:21:29 2011
@@ -702,91 +702,145 @@
     };
     
 
-
+    
     //---------------------------------------------------------------------
-    // 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;
-        }
+        //---------------------------------------------------------------------
+        // Subclass specific functions
+        //---------------------------------------------------------------------
         
-        OptionValue::Type
-        GetValueType ();
-        
-        bool
-        DumpValue (Stream &strm);
-        
-        bool
-        SetValueFromCString (const char *value);
-        
-        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_

Modified: lldb/trunk/source/Interpreter/NamedOptionValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/NamedOptionValue.cpp?rev=129926&r1=129925&r2=129926&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/NamedOptionValue.cpp (original)
+++ lldb/trunk/source/Interpreter/NamedOptionValue.cpp Thu Apr 21 14:21:29 2011
@@ -81,11 +81,11 @@
 
 
 //-------------------------------------------------------------------------
-// NamedOptionValue
+// OptionValueCollection
 //-------------------------------------------------------------------------
 
 void
-NamedOptionValue::GetQualifiedName (Stream &strm)
+OptionValueCollection::GetQualifiedName (Stream &strm)
 {
     if (m_parent)
     {
@@ -95,41 +95,6 @@
     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





More information about the lldb-commits mailing list