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