1// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "extensions/common/value_builder.h"
6
7namespace extensions {
8
9// DictionaryBuilder
10
11DictionaryBuilder::DictionaryBuilder() : dict_(new base::DictionaryValue) {}
12
13DictionaryBuilder::DictionaryBuilder(const base::DictionaryValue& init)
14    : dict_(init.DeepCopy()) {}
15
16DictionaryBuilder::~DictionaryBuilder() {}
17
18DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
19                                          int in_value) {
20  dict_->SetWithoutPathExpansion(path, new base::FundamentalValue(in_value));
21  return *this;
22}
23
24DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
25                                          double in_value) {
26  dict_->SetWithoutPathExpansion(path, new base::FundamentalValue(in_value));
27  return *this;
28}
29
30DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
31                                          const std::string& in_value) {
32  dict_->SetWithoutPathExpansion(path, new base::StringValue(in_value));
33  return *this;
34}
35
36DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
37                                          const base::string16& in_value) {
38  dict_->SetWithoutPathExpansion(path, new base::StringValue(in_value));
39  return *this;
40}
41
42DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
43                                          DictionaryBuilder& in_value) {
44  dict_->SetWithoutPathExpansion(path, in_value.Build().release());
45  return *this;
46}
47
48DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
49                                          ListBuilder& in_value) {
50  dict_->SetWithoutPathExpansion(path, in_value.Build().release());
51  return *this;
52}
53
54DictionaryBuilder& DictionaryBuilder::SetBoolean(
55    const std::string& path, bool in_value) {
56  dict_->SetWithoutPathExpansion(path, new base::FundamentalValue(in_value));
57  return *this;
58}
59
60// ListBuilder
61
62ListBuilder::ListBuilder() : list_(new base::ListValue) {}
63ListBuilder::ListBuilder(const base::ListValue& init) : list_(init.DeepCopy()) {
64}
65ListBuilder::~ListBuilder() {}
66
67ListBuilder& ListBuilder::Append(int in_value) {
68  list_->Append(new base::FundamentalValue(in_value));
69  return *this;
70}
71
72ListBuilder& ListBuilder::Append(double in_value) {
73  list_->Append(new base::FundamentalValue(in_value));
74  return *this;
75}
76
77ListBuilder& ListBuilder::Append(const std::string& in_value) {
78  list_->Append(new base::StringValue(in_value));
79  return *this;
80}
81
82ListBuilder& ListBuilder::Append(const base::string16& in_value) {
83  list_->Append(new base::StringValue(in_value));
84  return *this;
85}
86
87ListBuilder& ListBuilder::Append(DictionaryBuilder& in_value) {
88  list_->Append(in_value.Build().release());
89  return *this;
90}
91
92ListBuilder& ListBuilder::Append(ListBuilder& in_value) {
93  list_->Append(in_value.Build().release());
94  return *this;
95}
96
97ListBuilder& ListBuilder::AppendBoolean(bool in_value) {
98  list_->Append(new base::FundamentalValue(in_value));
99  return *this;
100}
101
102}  // namespace extensions
103