OptionValueBoolean.h revision 9f282851b07ff6daee37cd3b1a3fbc43ef11da29
1//===-- OptionValueBoolean.h ------------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_OptionValueBoolean_h_
11#define liblldb_OptionValueBoolean_h_
12
13// C Includes
14// C++ Includes
15// Other libraries and framework includes
16// Project includes
17#include "lldb/Interpreter/OptionValue.h"
18
19namespace lldb_private {
20
21class OptionValueBoolean : public OptionValue
22{
23public:
24    OptionValueBoolean (bool value) :
25        OptionValue(),
26        m_current_value (value),
27        m_default_value (value)
28    {
29    }
30    OptionValueBoolean (bool current_value,
31                        bool default_value) :
32        OptionValue(),
33        m_current_value (current_value),
34        m_default_value (default_value)
35    {
36    }
37
38    virtual
39    ~OptionValueBoolean()
40    {
41    }
42
43    //---------------------------------------------------------------------
44    // Virtual subclass pure virtual overrides
45    //---------------------------------------------------------------------
46
47    virtual OptionValue::Type
48    GetType () const
49    {
50        return eTypeBoolean;
51    }
52
53    virtual void
54    DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask);
55
56    virtual Error
57    SetValueFromCString (const char *value,
58                         VarSetOperationType op = eVarSetOperationAssign);
59
60    virtual bool
61    Clear ()
62    {
63        m_current_value = m_default_value;
64        m_value_was_set = false;
65        return true;
66    }
67
68    virtual size_t
69    AutoComplete (CommandInterpreter &interpreter,
70                  const char *s,
71                  int match_start_point,
72                  int max_return_elements,
73                  bool &word_complete,
74                  StringList &matches);
75
76    //---------------------------------------------------------------------
77    // Subclass specific functions
78    //---------------------------------------------------------------------
79
80    //------------------------------------------------------------------
81    /// Convert to bool operator.
82    ///
83    /// This allows code to check a OptionValueBoolean in conditions.
84    ///
85    /// @code
86    /// OptionValueBoolean bool_value(...);
87    /// if (bool_value)
88    /// { ...
89    /// @endcode
90    ///
91    /// @return
92    ///     /b True this object contains a valid namespace decl, \b
93    ///     false otherwise.
94    //------------------------------------------------------------------
95    operator bool() const
96    {
97        return m_current_value;
98    }
99
100    const bool &
101    operator = (bool b)
102    {
103        m_current_value = b;
104        return m_current_value;
105    }
106
107    bool
108    GetCurrentValue() const
109    {
110        return m_current_value;
111    }
112
113    bool
114    GetDefaultValue() const
115    {
116        return m_default_value;
117    }
118
119    void
120    SetCurrentValue (bool value)
121    {
122        m_current_value = value;
123    }
124
125    void
126    SetDefaultValue (bool value)
127    {
128        m_default_value = value;
129    }
130
131    virtual lldb::OptionValueSP
132    DeepCopy () const;
133
134protected:
135    bool m_current_value;
136    bool m_default_value;
137};
138
139} // namespace lldb_private
140
141#endif  // liblldb_OptionValueBoolean_h_
142