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