1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "extensions/common/value_builder.h"
#include <utility>
#include "base/json/json_writer.h"
#include "base/values.h"
namespace extensions {
// DictionaryBuilder
DictionaryBuilder::DictionaryBuilder() : dict_(new base::DictionaryValue) {}
DictionaryBuilder::DictionaryBuilder(const base::DictionaryValue& init)
: dict_(init.DeepCopy()) {}
DictionaryBuilder::~DictionaryBuilder() {}
DictionaryBuilder::DictionaryBuilder(DictionaryBuilder&& other)
: dict_(other.Build()) {}
DictionaryBuilder& DictionaryBuilder::operator=(DictionaryBuilder&& other) {
dict_ = other.Build();
return *this;
}
std::string DictionaryBuilder::ToJSON() const {
std::string json;
base::JSONWriter::WriteWithOptions(
*dict_, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json);
return json;
}
DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
int in_value) {
dict_->SetWithoutPathExpansion(path, new base::FundamentalValue(in_value));
return *this;
}
DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
double in_value) {
dict_->SetWithoutPathExpansion(path, new base::FundamentalValue(in_value));
return *this;
}
DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
const std::string& in_value) {
dict_->SetWithoutPathExpansion(path, new base::StringValue(in_value));
return *this;
}
DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
const base::string16& in_value) {
dict_->SetWithoutPathExpansion(path, new base::StringValue(in_value));
return *this;
}
DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
DictionaryBuilder in_value) {
dict_->SetWithoutPathExpansion(path, in_value.Build());
return *this;
}
DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
ListBuilder in_value) {
dict_->SetWithoutPathExpansion(path, in_value.Build());
return *this;
}
DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
scoped_ptr<base::Value> in_value) {
dict_->SetWithoutPathExpansion(path, std::move(in_value));
return *this;
}
DictionaryBuilder& DictionaryBuilder::SetBoolean(
const std::string& path, bool in_value) {
dict_->SetWithoutPathExpansion(path, new base::FundamentalValue(in_value));
return *this;
}
// ListBuilder
ListBuilder::ListBuilder() : list_(new base::ListValue) {}
ListBuilder::ListBuilder(const base::ListValue& init) : list_(init.DeepCopy()) {
}
ListBuilder::~ListBuilder() {}
ListBuilder::ListBuilder(ListBuilder&& other)
: list_(other.Build()) {}
ListBuilder& ListBuilder::operator=(ListBuilder&& other) {
list_ = other.Build();
return *this;
}
ListBuilder& ListBuilder::Append(int in_value) {
list_->Append(new base::FundamentalValue(in_value));
return *this;
}
ListBuilder& ListBuilder::Append(double in_value) {
list_->Append(new base::FundamentalValue(in_value));
return *this;
}
ListBuilder& ListBuilder::Append(const std::string& in_value) {
list_->Append(new base::StringValue(in_value));
return *this;
}
ListBuilder& ListBuilder::Append(const base::string16& in_value) {
list_->Append(new base::StringValue(in_value));
return *this;
}
ListBuilder& ListBuilder::Append(DictionaryBuilder in_value) {
list_->Append(in_value.Build());
return *this;
}
ListBuilder& ListBuilder::Append(ListBuilder in_value) {
list_->Append(in_value.Build());
return *this;
}
ListBuilder& ListBuilder::AppendBoolean(bool in_value) {
list_->Append(new base::FundamentalValue(in_value));
return *this;
}
} // namespace extensions
|