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

Greg Clayton gclayton at apple.com
Thu Apr 21 10:46:10 PDT 2011


Author: gclayton
Date: Thu Apr 21 12:46:10 2011
New Revision: 129920

URL: http://llvm.org/viewvc/llvm-project?rev=129920&view=rev
Log:
Made the constructors public for all OptionValue classes
so we can instantiate them, and also moved the code that
can get the specific subclass for a OptionValue into the 
OptionValue class.


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=129920&r1=129919&r2=129920&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/NamedOptionValue.h (original)
+++ lldb/trunk/include/lldb/Interpreter/NamedOptionValue.h Thu Apr 21 12:46:10 2011
@@ -22,6 +22,13 @@
 
 namespace lldb_private {
 
+    class OptionValueBoolean;
+    class OptionValueSInt64;
+    class OptionValueUInt64;
+    class OptionValueString;
+    class OptionValueFileSpec;
+    class OptionValueArray;
+    class OptionValueDictionary;
 
     //---------------------------------------------------------------------
     // OptionValue
@@ -68,6 +75,27 @@
         {
             return 1u << GetType();
         }
+        
+        OptionValueBoolean *
+        GetAsBooleanValue ();
+        
+        OptionValueSInt64 *
+        GetAsSInt64Value ();
+        
+        OptionValueUInt64 *
+        GetAsUInt64Value ();        
+        
+        OptionValueString *
+        GetAsStringValue ();
+        
+        OptionValueFileSpec *
+        GetAsFileSpecValue() ;
+        
+        OptionValueArray *
+        GetAsArrayValue() ;
+        
+        OptionValueDictionary *
+        GetAsDictionaryValue() ;
     };
     
     
@@ -77,6 +105,7 @@
     //---------------------------------------------------------------------
     class OptionValueBoolean : public OptionValue
     {
+    public:
         OptionValueBoolean (bool current_value, 
                             bool default_value) :
             m_current_value (current_value),
@@ -150,6 +179,7 @@
     //---------------------------------------------------------------------
     class OptionValueSInt64 : public OptionValue
     {
+    public:
         OptionValueSInt64 (int64_t current_value, 
                            int64_t default_value) :
         m_current_value (current_value),
@@ -223,6 +253,7 @@
     //---------------------------------------------------------------------
     class OptionValueUInt64 : public OptionValue
     {
+    public:
         OptionValueUInt64 (uint64_t current_value, 
                            uint64_t default_value) :
         m_current_value (current_value),
@@ -296,8 +327,15 @@
     //---------------------------------------------------------------------
     class OptionValueString : public OptionValue
     {
+    public:
+        OptionValueString () :
+            m_current_value (),
+            m_default_value ()
+        {
+        }
+
         OptionValueString (const char *current_value, 
-                           const char *default_value) :
+                           const char *default_value = NULL) :
             m_current_value (),
             m_default_value ()
         {
@@ -379,6 +417,19 @@
     //---------------------------------------------------------------------
     class OptionValueFileSpec : public OptionValue
     {
+    public:
+        OptionValueFileSpec () :
+            m_current_value (),
+            m_default_value ()
+        {
+        }
+
+        OptionValueFileSpec (const FileSpec &current_value) :
+            m_current_value (current_value),
+            m_default_value ()
+        {
+        }
+
         OptionValueFileSpec (const FileSpec &current_value, 
                              const FileSpec &default_value) :
             m_current_value (current_value),
@@ -452,6 +503,7 @@
     //---------------------------------------------------------------------
     class OptionValueArray : public OptionValue
     {
+    public:
         OptionValueArray (uint32_t type_mask = UINT32_MAX) :
             m_type_mask (type_mask),
             m_values ()
@@ -575,6 +627,7 @@
     //---------------------------------------------------------------------
     class OptionValueDictionary : public OptionValue
     {
+    public:
         OptionValueDictionary (uint32_t type_mask = UINT32_MAX) :
             m_type_mask (type_mask),
             m_values ()
@@ -620,47 +673,27 @@
         }
         
         lldb::OptionValueSP
-        GetValueForKey (const ConstString &key) const
-        {
-            lldb::OptionValueSP value_sp;
-            collection::const_iterator pos = m_values.find (key);
-            if (pos != m_values.end())
-                value_sp = pos->second;
-            return value_sp;
-        }
+        GetValueForKey (const ConstString &key) const;
+        
+        //---------------------------------------------------------------------
+        // String value getters and setters
+        //---------------------------------------------------------------------
+        const char *
+        GetStringValueForKey (const ConstString &key);
+
+        bool
+        SetStringValueForKey (const ConstString &key, 
+                              const char *value,
+                              bool can_replace = true);
+
         
         bool
         SetValueForKey (const ConstString &key, 
                         const lldb::OptionValueSP &value_sp, 
-                        bool can_replace)
-        {
-            // Make sure the value_sp object is allowed to contain
-            // values of the type passed in...
-            if (value_sp && (m_type_mask & value_sp->GetTypeAsMask()))
-            {
-                if (!can_replace)
-                {
-                    collection::const_iterator pos = m_values.find (key);
-                    if (pos != m_values.end())
-                        return false;
-                }
-                m_values[key] = value_sp;
-                return true;
-            }
-            return false;
-        }
+                        bool can_replace = true);
         
         bool
-        DeleteValueForKey (const ConstString &key)
-        {
-            collection::iterator pos = m_values.find (key);
-            if (pos != m_values.end())
-            {
-                m_values.erase(pos);
-                return true;
-            }
-            return false;
-        }
+        DeleteValueForKey (const ConstString &key);
         
     protected:
         typedef std::map<ConstString, lldb::OptionValueSP> collection;
@@ -746,27 +779,6 @@
         bool
         ResetValueToDefault ();
         
-        OptionValueBoolean *
-        GetBooleanValue ();
-
-        OptionValueSInt64 *
-        GetSInt64Value ();
-        
-        OptionValueUInt64 *
-        GetUInt64Value ();        
-
-        OptionValueString *
-        GetStringValue ();
-
-        OptionValueFileSpec *
-        GetFileSpecValue() ;
-
-        OptionValueArray *
-        GetArrayValue() ;
-
-        OptionValueDictionary *
-        GetDictionaryValue() ;
-
     protected:
         NamedOptionValue *m_parent;      // NULL if this is a root object
         ConstString m_name;         // Name for this setting

Modified: lldb/trunk/source/Interpreter/NamedOptionValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/NamedOptionValue.cpp?rev=129920&r1=129919&r2=129920&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/NamedOptionValue.cpp (original)
+++ lldb/trunk/source/Interpreter/NamedOptionValue.cpp Thu Apr 21 12:46:10 2011
@@ -19,6 +19,67 @@
 using namespace lldb;
 using namespace lldb_private;
 
+
+//-------------------------------------------------------------------------
+// OptionValue
+//-------------------------------------------------------------------------
+OptionValueBoolean *
+OptionValue::GetAsBooleanValue ()
+{
+    if (GetType () == OptionValue::eTypeBoolean)
+        return static_cast<OptionValueBoolean *>(this);
+    return NULL;
+}
+
+OptionValueSInt64 *
+OptionValue::GetAsSInt64Value ()
+{
+    if (GetType () == OptionValue::eTypeSInt64)
+        return static_cast<OptionValueSInt64 *>(this);
+    return NULL;
+}
+
+OptionValueUInt64 *
+OptionValue::GetAsUInt64Value ()
+{
+    if (GetType () == OptionValue::eTypeUInt64)
+        return static_cast<OptionValueUInt64 *>(this);
+    return NULL;
+}
+
+OptionValueString *
+OptionValue::GetAsStringValue ()
+{
+    if (GetType () == OptionValue::eTypeString)
+        return static_cast<OptionValueString *>(this);
+    return NULL;
+}
+
+OptionValueFileSpec *
+OptionValue::GetAsFileSpecValue ()
+{
+    if (GetType () == OptionValue::eTypeFileSpec)
+        return static_cast<OptionValueFileSpec *>(this);
+    return NULL;
+}
+
+OptionValueArray *
+OptionValue::GetAsArrayValue ()
+{
+    if (GetType () == OptionValue::eTypeArray)
+        return static_cast<OptionValueArray *>(this);
+    return NULL;
+}
+
+OptionValueDictionary *
+OptionValue::GetAsDictionaryValue ()
+{
+    if (GetType () == OptionValue::eTypeDictionary)
+        return static_cast<OptionValueDictionary *>(this);
+    return NULL;
+}
+
+
 //-------------------------------------------------------------------------
 // NamedOptionValue
 //-------------------------------------------------------------------------
@@ -70,62 +131,6 @@
 }
 
 
-OptionValueBoolean *
-NamedOptionValue::GetBooleanValue ()
-{
-    if (GetValueType() == OptionValue::eTypeBoolean)
-        return static_cast<OptionValueBoolean *>(m_value_sp.get());
-    return NULL;
-}
-
-OptionValueSInt64 *
-NamedOptionValue::GetSInt64Value ()
-{
-    if (GetValueType() == OptionValue::eTypeSInt64)
-        return static_cast<OptionValueSInt64 *>(m_value_sp.get());
-    return NULL;
-}
-
-OptionValueUInt64 *
-NamedOptionValue::GetUInt64Value ()
-{
-    if (GetValueType() == OptionValue::eTypeUInt64)
-        return static_cast<OptionValueUInt64 *>(m_value_sp.get());
-    return NULL;
-}
-
-OptionValueString *
-NamedOptionValue::GetStringValue ()
-{
-    if (GetValueType() == OptionValue::eTypeString)
-        return static_cast<OptionValueString *>(m_value_sp.get());
-    return NULL;
-}
-
-OptionValueFileSpec *
-NamedOptionValue::GetFileSpecValue ()
-{
-    if (GetValueType() == OptionValue::eTypeFileSpec)
-        return static_cast<OptionValueFileSpec *>(m_value_sp.get());
-    return NULL;
-}
-
-OptionValueArray *
-NamedOptionValue::GetArrayValue ()
-{
-    if (GetValueType() == OptionValue::eTypeArray)
-        return static_cast<OptionValueArray *>(m_value_sp.get());
-    return NULL;
-}
-
-OptionValueDictionary *
-NamedOptionValue::GetDictionaryValue ()
-{
-    if (GetValueType() == OptionValue::eTypeDictionary)
-        return static_cast<OptionValueDictionary *>(m_value_sp.get());
-    return NULL;
-}
-
 //-------------------------------------------------------------------------
 // OptionValueBoolean
 //-------------------------------------------------------------------------
@@ -286,4 +291,81 @@
     return false;
 }
 
+lldb::OptionValueSP
+OptionValueDictionary::GetValueForKey (const ConstString &key) const
+{
+    lldb::OptionValueSP value_sp;
+    collection::const_iterator pos = m_values.find (key);
+    if (pos != m_values.end())
+        value_sp = pos->second;
+    return value_sp;
+}
+
+const char *
+OptionValueDictionary::GetStringValueForKey (const ConstString &key)
+{
+    collection::const_iterator pos = m_values.find (key);
+    if (pos != m_values.end())
+    {
+        if (pos->second->GetType() == OptionValue::eTypeString)
+            return static_cast<OptionValueString *>(pos->second.get())->GetCurrentValue();
+    }
+    return NULL;
+}
+
+
+bool
+OptionValueDictionary::SetStringValueForKey (const ConstString &key, 
+                                             const char *value, 
+                                             bool can_replace)
+{
+    collection::const_iterator pos = m_values.find (key);
+    if (pos != m_values.end())
+    {
+        if (!can_replace)
+            return false;
+        if (pos->second->GetType() == OptionValue::eTypeString)
+        {
+            pos->second->SetValueFromCString(value);
+            return true;
+        }
+    }
+    m_values[key] = OptionValueSP (new OptionValueString (value));
+    return true;
+
+}
+
+bool
+OptionValueDictionary::SetValueForKey (const ConstString &key, 
+                                       const lldb::OptionValueSP &value_sp, 
+                                       bool can_replace)
+{
+    // Make sure the value_sp object is allowed to contain
+    // values of the type passed in...
+    if (value_sp && (m_type_mask & value_sp->GetTypeAsMask()))
+    {
+        if (!can_replace)
+        {
+            collection::const_iterator pos = m_values.find (key);
+            if (pos != m_values.end())
+                return false;
+        }
+        m_values[key] = value_sp;
+        return true;
+    }
+    return false;
+}
+
+bool
+OptionValueDictionary::DeleteValueForKey (const ConstString &key)
+{
+    collection::iterator pos = m_values.find (key);
+    if (pos != m_values.end())
+    {
+        m_values.erase(pos);
+        return true;
+    }
+    return false;
+}
+
 





More information about the lldb-commits mailing list