1254721Semaste//====-- UserSettingsController.cpp ------------------------------*- C++ -*-===//
2254721Semaste//
3254721Semaste//                     The LLVM Compiler Infrastructure
4254721Semaste//
5254721Semaste// This file is distributed under the University of Illinois Open Source
6254721Semaste// License. See LICENSE.TXT for details.
7254721Semaste//
8254721Semaste//===----------------------------------------------------------------------===//
9254721Semaste
10254721Semaste#include "lldb/lldb-python.h"
11254721Semaste
12254721Semaste#include <string.h>
13254721Semaste#include <algorithm>
14254721Semaste
15254721Semaste#include "lldb/Core/UserSettingsController.h"
16254721Semaste#include "lldb/Core/Error.h"
17254721Semaste#include "lldb/Core/RegularExpression.h"
18254721Semaste#include "lldb/Core/Stream.h"
19254721Semaste#include "lldb/Core/StreamString.h"
20254721Semaste#include "lldb/Interpreter/CommandInterpreter.h"
21254721Semaste#include "lldb/Interpreter/OptionValueString.h"
22254721Semaste
23254721Semasteusing namespace lldb;
24254721Semasteusing namespace lldb_private;
25254721Semaste
26254721Semaste
27254721Semastelldb::OptionValueSP
28254721SemasteProperties::GetPropertyValue (const ExecutionContext *exe_ctx,
29254721Semaste                              const char *path,
30254721Semaste                              bool will_modify,
31254721Semaste                              Error &error) const
32254721Semaste{
33254721Semaste    OptionValuePropertiesSP properties_sp (GetValueProperties ());
34254721Semaste    if (properties_sp)
35254721Semaste        return properties_sp->GetSubValue(exe_ctx, path, will_modify, error);
36254721Semaste    return lldb::OptionValueSP();
37254721Semaste}
38254721Semaste
39254721SemasteError
40254721SemasteProperties::SetPropertyValue (const ExecutionContext *exe_ctx,
41254721Semaste                              VarSetOperationType op,
42254721Semaste                              const char *path,
43254721Semaste                              const char *value)
44254721Semaste{
45254721Semaste    OptionValuePropertiesSP properties_sp (GetValueProperties ());
46254721Semaste    if (properties_sp)
47254721Semaste        return properties_sp->SetSubValue(exe_ctx, op, path, value);
48254721Semaste    Error error;
49254721Semaste    error.SetErrorString ("no properties");
50254721Semaste    return error;
51254721Semaste}
52254721Semaste
53254721Semastevoid
54254721SemasteProperties::DumpAllPropertyValues (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
55254721Semaste{
56254721Semaste    OptionValuePropertiesSP properties_sp (GetValueProperties ());
57254721Semaste    if (properties_sp)
58254721Semaste        return properties_sp->DumpValue (exe_ctx, strm, dump_mask);
59254721Semaste}
60254721Semaste
61254721Semastevoid
62254721SemasteProperties::DumpAllDescriptions (CommandInterpreter &interpreter,
63254721Semaste                                 Stream &strm) const
64254721Semaste{
65254721Semaste    strm.PutCString("Top level variables:\n\n");
66254721Semaste
67254721Semaste    OptionValuePropertiesSP properties_sp (GetValueProperties ());
68254721Semaste    if (properties_sp)
69254721Semaste        return properties_sp->DumpAllDescriptions (interpreter, strm);
70254721Semaste}
71254721Semaste
72254721Semaste
73254721Semaste
74254721SemasteError
75254721SemasteProperties::DumpPropertyValue (const ExecutionContext *exe_ctx, Stream &strm, const char *property_path, uint32_t dump_mask)
76254721Semaste{
77254721Semaste    OptionValuePropertiesSP properties_sp (GetValueProperties ());
78254721Semaste    if (properties_sp)
79254721Semaste    {
80254721Semaste        return properties_sp->DumpPropertyValue (exe_ctx,
81254721Semaste                                                 strm,
82254721Semaste                                                 property_path,
83254721Semaste                                                 dump_mask);
84254721Semaste    }
85254721Semaste    Error error;
86254721Semaste    error.SetErrorString("empty property list");
87254721Semaste    return error;
88254721Semaste}
89254721Semaste
90254721Semastesize_t
91254721SemasteProperties::Apropos (const char *keyword, std::vector<const Property *> &matching_properties) const
92254721Semaste{
93254721Semaste    OptionValuePropertiesSP properties_sp (GetValueProperties ());
94254721Semaste    if (properties_sp)
95254721Semaste    {
96254721Semaste        properties_sp->Apropos (keyword, matching_properties);
97254721Semaste    }
98254721Semaste    return matching_properties.size();
99254721Semaste}
100254721Semaste
101254721Semaste
102254721Semastelldb::OptionValuePropertiesSP
103254721SemasteProperties::GetSubProperty (const ExecutionContext *exe_ctx,
104254721Semaste                            const ConstString &name)
105254721Semaste{
106254721Semaste    OptionValuePropertiesSP properties_sp (GetValueProperties ());
107254721Semaste    if (properties_sp)
108254721Semaste        return properties_sp->GetSubProperty (exe_ctx, name);
109254721Semaste    return lldb::OptionValuePropertiesSP();
110254721Semaste}
111254721Semaste
112