OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 #ifndef CHROME_TEST_AUTOMATION_VALUE_CONVERSION_TRAITS_H_ |
| 6 #define CHROME_TEST_AUTOMATION_VALUE_CONVERSION_TRAITS_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 |
| 11 namespace base { |
| 12 class DictionaryValue; |
| 13 class ListValue; |
| 14 class Value; |
| 15 } |
| 16 |
| 17 // ValueConversionTraits contains functions for converting between a base::Value |
| 18 // and a particular type. See particular function descriptions below. |
| 19 template <typename T> |
| 20 struct ValueConversionTraits { |
| 21 // Create a value from |t|. Will not return NULL. |
| 22 // static base::Value* CreateValueFrom(const T& t); |
| 23 |
| 24 // Attempts to set |t| from the given value. Returns true on success. |
| 25 // |t| will not be modified unless successful. |
| 26 // static bool SetFromValue(const base::Value* value, T* t); |
| 27 |
| 28 // Returns whether |value| can be converted to type |T|. |
| 29 // If true, |SetFromValue| will succeed. |
| 30 // static bool CanConvert(const base::Value* value); |
| 31 }; |
| 32 |
| 33 template <> |
| 34 struct ValueConversionTraits<int> { |
| 35 static base::Value* CreateValueFrom(int t); |
| 36 static bool SetFromValue(const base::Value* value, int* t); |
| 37 static bool CanConvert(const base::Value* value); |
| 38 }; |
| 39 |
| 40 template <> |
| 41 struct ValueConversionTraits<bool> { |
| 42 static base::Value* CreateValueFrom(bool t); |
| 43 static bool SetFromValue(const base::Value* value, bool* t); |
| 44 static bool CanConvert(const base::Value* value); |
| 45 }; |
| 46 |
| 47 template <> |
| 48 struct ValueConversionTraits<std::string> { |
| 49 static base::Value* CreateValueFrom(const std::string& t); |
| 50 static bool SetFromValue(const base::Value* value, std::string* t); |
| 51 static bool CanConvert(const base::Value* value); |
| 52 }; |
| 53 |
| 54 // The conversion will involve deep copying, not just casting. |
| 55 template <> |
| 56 struct ValueConversionTraits<base::Value*> { |
| 57 static base::Value* CreateValueFrom(const base::Value* t); |
| 58 static bool SetFromValue(const base::Value* value, base::Value** t); |
| 59 static bool CanConvert(const base::Value* value); |
| 60 }; |
| 61 |
| 62 // The conversion will involve deep copying, not just casting. |
| 63 template <> |
| 64 struct ValueConversionTraits<base::ListValue*> { |
| 65 static base::Value* CreateValueFrom(const base::ListValue* t); |
| 66 static bool SetFromValue(const base::Value* value, base::ListValue** t); |
| 67 static bool CanConvert(const base::Value* value); |
| 68 }; |
| 69 |
| 70 // The conversion will involve deep copying, not just casting. |
| 71 template <> |
| 72 struct ValueConversionTraits<base::DictionaryValue*> { |
| 73 static base::Value* CreateValueFrom(const base::DictionaryValue* t); |
| 74 static bool SetFromValue(const base::Value* value, base::DictionaryValue** t); |
| 75 static bool CanConvert(const base::Value* value); |
| 76 }; |
| 77 |
| 78 #endif // CHROME_TEST_AUTOMATION_VALUE_CONVERSION_TRAITS_H_ |
OLD | NEW |