diff options
author | calamity@chromium.org <calamity@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-15 14:52:32 +0000 |
---|---|---|
committer | calamity@chromium.org <calamity@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-15 14:52:32 +0000 |
commit | cfe484905085bc55742da39f792a571615cb419b (patch) | |
tree | d655642171deba8dcbb57d5cdbe9693ee2e42dd8 /tools/json_schema_compiler/util.cc | |
parent | 498e0a6eb258f10ad76039c3028d0f7a4ad365e4 (diff) | |
download | chromium_src-cfe484905085bc55742da39f792a571615cb419b.zip chromium_src-cfe484905085bc55742da39f792a571615cb419b.tar.gz chromium_src-cfe484905085bc55742da39f792a571615cb419b.tar.bz2 |
Adds support for the "choices" and "any" types to json_schema_compiler, as well
as miscellaneous improvements to get at least 3 more schema files compiling:
windows, tabs, and the in-progress experimental.declarative.
For description of the generator, see http://codereview.chromium.org/9114036/
BUG=
TEST=
Review URL: http://codereview.chromium.org/9309044
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122082 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/json_schema_compiler/util.cc')
-rw-r--r-- | tools/json_schema_compiler/util.cc | 88 |
1 files changed, 31 insertions, 57 deletions
diff --git a/tools/json_schema_compiler/util.cc b/tools/json_schema_compiler/util.cc index 38e6b30..b0e98f6 100644 --- a/tools/json_schema_compiler/util.cc +++ b/tools/json_schema_compiler/util.cc @@ -9,73 +9,47 @@ namespace json_schema_compiler { namespace util { -bool GetStrings( - const base::DictionaryValue& from, - const std::string& name, - std::vector<std::string>* out) { - base::ListValue* list = NULL; - if (!from.GetListWithoutPathExpansion(name, &list)) - return false; +bool GetItemFromList(const ListValue& from, int index, int* out) { + return from.GetInteger(index, out); +} - std::string string; - for (size_t i = 0; i < list->GetSize(); ++i) { - if (!list->GetString(i, &string)) - return false; - out->push_back(string); - } +bool GetItemFromList(const ListValue& from, int index, bool* out) { + return from.GetBoolean(index, out); +} - return true; +bool GetItemFromList(const ListValue& from, int index, double* out) { + return from.GetDouble(index, out); } -bool GetOptionalStrings( - const base::DictionaryValue& from, - const std::string& name, - scoped_ptr<std::vector<std::string> >* out) { - base::ListValue* list = NULL; - { - base::Value* maybe_list = NULL; - // Since |name| is optional, its absence is acceptable. However, anything - // other than a ListValue is not. - if (!from.GetWithoutPathExpansion(name, &maybe_list)) - return true; - if (!maybe_list->IsType(base::Value::TYPE_LIST)) - return false; - list = static_cast<base::ListValue*>(maybe_list); - } +bool GetItemFromList(const ListValue& from, int index, std::string* out) { + return from.GetString(index, out); +} - out->reset(new std::vector<std::string>()); - std::string string; - for (size_t i = 0; i < list->GetSize(); ++i) { - if (!list->GetString(i, &string)) { - out->reset(); - return false; - } - (*out)->push_back(string); +bool GetItemFromList(const ListValue& from, int index, + linked_ptr<base::DictionaryValue>* out) { + DictionaryValue* dict = NULL; + if (!from.GetDictionary(index, &dict)) { + return false; } - + *out = linked_ptr<DictionaryValue>(dict->DeepCopy()); return true; } -void SetStrings( - const std::vector<std::string>& from, - const std::string& name, - base::DictionaryValue* out) { - base::ListValue* list = new base::ListValue(); - out->SetWithoutPathExpansion(name, list); - for (std::vector<std::string>::const_iterator it = from.begin(); - it != from.end(); ++it) { - list->Append(base::Value::CreateStringValue(*it)); - } +void AddItemToList(const int from, base::ListValue* out) { + out->Append(base::Value::CreateIntegerValue(from)); } - -void SetOptionalStrings( - const scoped_ptr<std::vector<std::string> >& from, - const std::string& name, - base::DictionaryValue* out) { - if (!from.get()) - return; - - SetStrings(*from, name, out); +void AddItemToList(const bool from, base::ListValue* out) { + out->Append(base::Value::CreateBooleanValue(from)); +} +void AddItemToList(const double from, base::ListValue* out) { + out->Append(base::Value::CreateDoubleValue(from)); +} +void AddItemToList(const std::string& from, base::ListValue* out) { + out->Append(base::Value::CreateStringValue(from)); +} +void AddItemToList(const linked_ptr<base::DictionaryValue> from, + base::ListValue* out) { + out->Append(static_cast<Value*>(from->DeepCopy())); } } // namespace api_util |