OptionValueProperties.h revision c6e82e4a323d7a7168b05365c53c9bc2e0d418e3
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    OptionValueFileSpec *
215    GetPropertyAtIndexAsOptionValueFileSpec (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const;
216
217    FileSpec
218    GetPropertyAtIndexAsFileSpec (const ExecutionContext *exe_ctx, uint32_t idx) const;
219
220    bool
221    SetPropertyAtIndexAsFileSpec (const ExecutionContext *exe_ctx, uint32_t idx, const FileSpec &file_spec);
222
223    OptionValuePathMappings *
224    GetPropertyAtIndexAsOptionValuePathMappings (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const;
225
226    OptionValueFileSpecList *
227    GetPropertyAtIndexAsOptionValueFileSpecList (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const;
228
229    void
230    AppendProperty(const ConstString &name,
231                   const ConstString &desc,
232                   bool is_global,
233                   const lldb::OptionValueSP &value_sp);
234
235
236protected:
237
238    const Property *
239    ProtectedGetPropertyAtIndex (uint32_t idx) const
240    {
241        if (idx < m_properties.size())
242            return &m_properties[idx];
243        return NULL;
244    }
245
246    typedef UniqueCStringMap<size_t> NameToIndex;
247
248    ConstString m_name;
249    std::vector<Property> m_properties;
250    NameToIndex m_name_to_index;
251};
252
253} // namespace lldb_private
254
255#endif  // liblldb_OptionValueProperties_h_
256