1 // Copyright 2015 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include <brillo/value_conversion.h> 16 17 #include <string> 18 #include <vector> 19 20 namespace brillo { 21 FromValue(const base::Value & in_value,std::unique_ptr<base::ListValue> * out_value)22bool FromValue(const base::Value& in_value, 23 std::unique_ptr<base::ListValue>* out_value) { 24 const base::ListValue* list = nullptr; 25 if (!in_value.GetAsList(&list)) 26 return false; 27 out_value->reset(list->DeepCopy()); 28 return true; 29 } 30 FromValue(const base::Value & in_value,std::unique_ptr<base::DictionaryValue> * out_value)31bool FromValue(const base::Value& in_value, 32 std::unique_ptr<base::DictionaryValue>* out_value) { 33 const base::DictionaryValue* dict = nullptr; 34 if (!in_value.GetAsDictionary(&dict)) 35 return false; 36 out_value->reset(dict->DeepCopy()); 37 return true; 38 } 39 ToValue(int value)40std::unique_ptr<base::Value> ToValue(int value) { 41 return std::unique_ptr<base::Value>{new base::FundamentalValue{value}}; 42 } 43 ToValue(bool value)44std::unique_ptr<base::Value> ToValue(bool value) { 45 return std::unique_ptr<base::Value>{new base::FundamentalValue{value}}; 46 } 47 ToValue(double value)48std::unique_ptr<base::Value> ToValue(double value) { 49 return std::unique_ptr<base::Value>{new base::FundamentalValue{value}}; 50 } 51 ToValue(const char * value)52std::unique_ptr<base::Value> ToValue(const char* value) { 53 return std::unique_ptr<base::Value>{new base::StringValue{value}}; 54 } 55 ToValue(const std::string & value)56std::unique_ptr<base::Value> ToValue(const std::string& value) { 57 return std::unique_ptr<base::Value>{new base::StringValue{value}}; 58 } 59 60 } // namespace brillo 61