Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: tools/json_schema_compiler/util.cc

Issue 9114036: Code generation for extensions api (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: added generated files, removed trailing whitespace Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "tools/json_schema_compiler/util.h"
6
7 #include "base/values.h"
8
9 namespace extensions {
10 namespace api_util {
11
12 bool GetStrings(
13 const base::DictionaryValue& from,
14 const std::string& name,
15 std::vector<std::string>* out) {
16 base::ListValue* list = NULL;
17 //TODO(calamity): need to check is list?
not at google - send to devlin 2012/01/12 06:01:05 nah, not unnecessary here.
calamity 2012/01/16 04:01:06 Removed.
18 if (!from.GetListWithoutPathExpansion(name, &list))
19 return false;
20
21 std::string string;
22 for (size_t i = 0; i < list->GetSize(); ++i) {
23 if (!list->GetString(i, &string))
24 return false;
25 out->push_back(string);
26 }
27
28 return true;
29 }
30
31 bool GetOptionalStrings(
32 const base::DictionaryValue& from,
33 const std::string& name,
34 scoped_ptr<std::vector<std::string> >* out) {
35 base::ListValue* list = NULL;
36 {
37 base::Value* maybe_list = NULL;
38 if (!from.GetWithoutPathExpansion(name, &maybe_list))
39 return true;
40 if (!maybe_list->IsType(base::Value::TYPE_LIST))
41 return false;
42 list = static_cast<base::ListValue*>(maybe_list);
not at google - send to devlin 2012/01/12 06:01:05 explain why you're doing this.
calamity 2012/01/16 04:01:06 Done.
43 }
44
45 out->reset(new std::vector<std::string>());
46 std::string string;
47 for (size_t i = 0; i < list->GetSize(); ++i) {
48 if (!list->GetString(i, &string)) {
49 out->reset();
50 return false;
51 }
52 (*out)->push_back(string);
53 }
54
55 return true;
56 }
57
58 void SetStrings(
59 const std::vector<std::string>& from,
60 const std::string& name,
61 base::DictionaryValue* out) {
62 base::ListValue* list = new base::ListValue();
63 out->SetWithoutPathExpansion(name, list);
64 for (std::vector<std::string>::const_iterator it = from.begin();
65 it != from.end(); ++it) {
66 list->Append(base::Value::CreateStringValue(*it));
67 }
68 }
69
70 void SetOptionalStrings(
71 const scoped_ptr<std::vector<std::string> >& from,
72 const std::string& name,
73 base::DictionaryValue* out) {
74 if (!from.get())
75 return;
76
77 base::ListValue* list = new base::ListValue();
78 out->SetWithoutPathExpansion(name, list);
79 for (std::vector<std::string>::const_iterator it = from->begin();
80 it != from->end(); ++it) {
81 list->Append(base::Value::CreateStringValue(*it));
82 }
not at google - send to devlin 2012/01/12 06:01:05 all of this can be SetStrings(*from, name, out);
calamity 2012/01/12 22:59:20 Done.
83 }
84
85 template<class T>
86 bool GetTypes(
87 const base::DictionaryValue& from,
88 const std::string& name,
89 std::vector<T>* out) {
90
not at google - send to devlin 2012/01/12 06:01:05 ..? you probably want to remove this method
calamity 2012/01/12 22:59:20 Done.
91 }
92
93 } // namespace api_util
94 } // namespace extensions
OLDNEW
« tools/json_schema_compiler/util.h ('K') | « tools/json_schema_compiler/util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698