OptionValueProperties.h revision 3b1afc6cc5689b749a48a1506f17ca593b1cda42
1//===-- OptionValueProperties.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_OptionValueProperties_h_
11#define liblldb_OptionValueProperties_h_
12
13// C Includes
14// C++ Includes
15// Other libraries and framework includes
16// Project includes
17#include "lldb/Core/ConstString.h"
18#include "lldb/Core/UniqueCStringMap.h"
19#include "lldb/Interpreter/OptionValue.h"
20#include "lldb/Interpreter/Property.h"
21
22namespace lldb_private {
23
24class OptionValueProperties : public OptionValue, public STD_ENABLE_SHARED_FROM_THIS(OptionValueProperties)
25{
26public:
27
28    //---------------------------------------------------------------------
29    // OptionValueProperties
30    //---------------------------------------------------------------------
31    OptionValueProperties () :
32        OptionValue(),
33        m_name ()
34    {
35    }
36
37    OptionValueProperties (const ConstString &name);
38
39    OptionValueProperties (const OptionValueProperties &global_properties);
40
41    virtual
42    ~OptionValueProperties()
43    {
44    }
45
46    virtual Type
47    GetType () const
48    {
49        return eTypeProperties;
50    }
51
52    virtual bool
53    Clear ();
54
55    virtual lldb::OptionValueSP
56    DeepCopy () const;
57
58    virtual Error
59    SetValueFromCString (const char *value, VarSetOperationType op = eVarSetOperationAssign);
60
61    virtual void
62    DumpValue (const ExecutionContext *exe_ctx,
63               Stream &strm,
64               uint32_t dump_mask);
65
66    virtual ConstString
67    GetName () const
68    {
69        return m_name;
70    }
71
72    virtual Error
73    DumpPropertyValue (const ExecutionContext *exe_ctx,
74                       Stream &strm,
75                       const char *property_path,
76                       uint32_t dump_mask);
77
78    virtual void
79    DumpAllDescriptions (CommandInterpreter &interpreter,
80                         Stream &strm) const;
81
82    void
83    Apropos (const char *keyword,
84             std::vector<const Property *> &matching_properties) const;
85
86    void
87    Initialize (const PropertyDefinition *setting_definitions);
88
89//    bool
90//    GetQualifiedName (Stream &strm);
91
92    //---------------------------------------------------------------------
93    // Subclass specific functions
94    //---------------------------------------------------------------------
95
96    virtual size_t
97    GetNumProperties() const;
98
99    virtual ConstString
100    GetPropertyNameAtIndex (uint32_t idx) const;
101
102    virtual const char *
103    GetPropertyDescriptionAtIndex (uint32_t idx) const;
104
105    //---------------------------------------------------------------------
106    // Get the index of a property given its exact name in this property
107    // collection, "name" can't be a path to a property path that refers
108    // to a property within a property
109    //---------------------------------------------------------------------
110    virtual uint32_t
111    GetPropertyIndex (const ConstString &name) const;
112
113    //---------------------------------------------------------------------
114    // Get a property by exact name exists in this property collection, name
115    // can not be a path to a property path that refers to a property within
116    // a property
117    //---------------------------------------------------------------------
118    virtual const Property *
119    GetProperty (const ExecutionContext *exe_ctx,
120                 bool will_modify,
121                 const ConstString &name) const;
122
123    virtual const Property *
124    GetPropertyAtIndex (const ExecutionContext *exe_ctx,
125                        bool will_modify,
126                        uint32_t idx) const;
127
128    //---------------------------------------------------------------------
129    // Property can be be a property path like "target.process.extra-startup-command"
130    //---------------------------------------------------------------------
131    virtual const Property *
132    GetPropertyAtPath (const ExecutionContext *exe_ctx,
133                       bool will_modify,
134                       const char *property_path) const;
135
136    virtual lldb::OptionValueSP
137    GetPropertyValueAtIndex (const ExecutionContext *exe_ctx,
138                             bool will_modify,
139                             uint32_t idx) const;
140
141    virtual lldb::OptionValueSP
142    GetValueForKey  (const ExecutionContext *exe_ctx,
143                     const ConstString &key,
144                     bool value_will_be_modified) const;
145
146    lldb::OptionValueSP
147    GetSubValue (const ExecutionContext *exe_ctx,
148                 const char *name,
149                 bool value_will_be_modified,
150                 Error &error) const;
151
152    virtual Error
153    SetSubValue (const ExecutionContext *exe_ctx,
154                 VarSetOperationType op,
155                 const char *path,
156                 const char *value);
157
158    virtual bool
159    PredicateMatches (const ExecutionContext *exe_ctx,
160                      const char *predicate) const
161    {
162        return false;
163    }
164
165
166    OptionValueArch *
167    GetPropertyAtIndexAsOptionValueArch (const ExecutionContext *exe_ctx, uint32_t idx) const;
168
169    bool
170    GetPropertyAtIndexAsArgs (const ExecutionContext *exe_ctx, uint32_t idx, Args &args) const;
171
172    bool
173    SetPropertyAtIndexFromArgs (const ExecutionContext *exe_ctx, uint32_t idx, const Args &args);
174
175    bool
176    GetPropertyAtIndexAsBoolean (const ExecutionContext *exe_ctx, uint32_t idx, bool fail_value) const;
177
178    bool
179    SetPropertyAtIndexAsBoolean (const ExecutionContext *exe_ctx, uint32_t idx, bool new_value);
180
181    OptionValueDictionary *
182    GetPropertyAtIndexAsOptionValueDictionary (const ExecutionContext *exe_ctx, uint32_t idx) const;
183
184    int64_t
185    GetPropertyAtIndexAsEnumeration (const ExecutionContext *exe_ctx, uint32_t idx, int64_t fail_value) const;
186
187    bool
188    SetPropertyAtIndexAsEnumeration (const ExecutionContext *exe_ctx, uint32_t idx, int64_t new_value);
189
190    const RegularExpression *
191    GetPropertyAtIndexAsOptionValueRegex (const ExecutionContext *exe_ctx, uint32_t idx) const;
192
193    OptionValueSInt64 *
194    GetPropertyAtIndexAsOptionValueSInt64 (const ExecutionContext *exe_ctx, uint32_t idx) const;
195
196    int64_t
197    GetPropertyAtIndexAsSInt64 (const ExecutionContext *exe_ctx, uint32_t idx, int64_t fail_value) const;
198
199    bool
200    SetPropertyAtIndexAsSInt64 (const ExecutionContext *exe_ctx, uint32_t idx, int64_t new_value);
201
202    uint64_t
203    GetPropertyAtIndexAsUInt64 (const ExecutionContext *exe_ctx, uint32_t idx, uint64_t fail_value) const;
204
205    bool
206    SetPropertyAtIndexAsUInt64 (const ExecutionContext *exe_ctx, uint32_t idx, uint64_t new_value);
207
208    const char *
209    GetPropertyAtIndexAsString (const ExecutionContext *exe_ctx, uint32_t idx, const char *fail_value) const;
210
211    bool
212    SetPropertyAtIndexAsString (const ExecutionContext *exe_ctx, uint32_t idx, const char *new_value);
213
214    OptionValueString *
215    GetPropertyAtIndexAsOptionValueString (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const;
216
217    OptionValueFileSpec *
218    GetPropertyAtIndexAsOptionValueFileSpec (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const;
219
220    FileSpec
221    GetPropertyAtIndexAsFileSpec (const ExecutionContext *exe_ctx, uint32_t idx) const;
222
223    bool
224    SetPropertyAtIndexAsFileSpec (const ExecutionContext *exe_ctx, uint32_t idx, const FileSpec &file_spec);
225
226    OptionValuePathMappings *
227    GetPropertyAtIndexAsOptionValuePathMappings (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const;
228
229    OptionValueFileSpecList *
230    GetPropertyAtIndexAsOptionValueFileSpecList (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const;
231
232    void
233    AppendProperty(const ConstString &name,
234                   const ConstString &desc,
235                   bool is_global,
236                   const lldb::OptionValueSP &value_sp);
237
238
239protected:
240
241    const Property *
242    ProtectedGetPropertyAtIndex (uint32_t idx) const
243    {
244        if (idx < m_properties.size())
245            return &m_properties[idx];
246        return NULL;
247    }
248
249    typedef UniqueCStringMap<size_t> NameToIndex;
250
251    ConstString m_name;
252    std::vector<Property> m_properties;
253    NameToIndex m_name_to_index;
254};
255
256} // namespace lldb_private
257
258#endif  // liblldb_OptionValueProperties_h_
259