OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_MUS_PUBLIC_CPP_VIEW_PROPERTY_H_ | 5 #ifndef COMPONENTS_MUS_PUBLIC_CPP_VIEW_PROPERTY_H_ |
6 #define COMPONENTS_MUS_PUBLIC_CPP_VIEW_PROPERTY_H_ | 6 #define COMPONENTS_MUS_PUBLIC_CPP_VIEW_PROPERTY_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 // This header should be included by code that defines ViewProperties. It | 10 // This header should be included by code that defines ViewProperties. It |
(...skipping 22 matching lines...) Expand all Loading... |
33 // } // foo namespace | 33 // } // foo namespace |
34 // | 34 // |
35 // To define a new type used for ViewProperty. | 35 // To define a new type used for ViewProperty. |
36 // | 36 // |
37 // // outside all namespaces: | 37 // // outside all namespaces: |
38 // DECLARE_EXPORTED_VIEW_PROPERTY_TYPE(FOO_EXPORT, MyType) | 38 // DECLARE_EXPORTED_VIEW_PROPERTY_TYPE(FOO_EXPORT, MyType) |
39 // | 39 // |
40 // If a property type is not exported, use DECLARE_VIEW_PROPERTY_TYPE(MyType) | 40 // If a property type is not exported, use DECLARE_VIEW_PROPERTY_TYPE(MyType) |
41 // which is a shorthand for DECLARE_EXPORTED_VIEW_PROPERTY_TYPE(, MyType). | 41 // which is a shorthand for DECLARE_EXPORTED_VIEW_PROPERTY_TYPE(, MyType). |
42 | 42 |
43 namespace mus { | 43 namespace mojo { |
44 namespace { | 44 namespace { |
45 | 45 |
46 // No single new-style cast works for every conversion to/from int64_t, so we | 46 // No single new-style cast works for every conversion to/from int64_t, so we |
47 // need this helper class. A third specialization is needed for bool because | 47 // need this helper class. A third specialization is needed for bool because |
48 // MSVC warning C4800 (forcing value to bool) is not suppressed by an explicit | 48 // MSVC warning C4800 (forcing value to bool) is not suppressed by an explicit |
49 // cast (!). | 49 // cast (!). |
50 template <typename T> | 50 template <typename T> |
51 class ViewPropertyCaster { | 51 class ViewPropertyCaster { |
52 public: | 52 public: |
53 static int64_t ToInt64(T x) { return static_cast<int64_t>(x); } | 53 static int64_t ToInt64(T x) { return static_cast<int64_t>(x); } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 T View::GetLocalProperty(const ViewProperty<T>* property) const { | 92 T View::GetLocalProperty(const ViewProperty<T>* property) const { |
93 return ViewPropertyCaster<T>::FromInt64(GetLocalPropertyInternal( | 93 return ViewPropertyCaster<T>::FromInt64(GetLocalPropertyInternal( |
94 property, ViewPropertyCaster<T>::ToInt64(property->default_value))); | 94 property, ViewPropertyCaster<T>::ToInt64(property->default_value))); |
95 } | 95 } |
96 | 96 |
97 template <typename T> | 97 template <typename T> |
98 void View::ClearLocalProperty(const ViewProperty<T>* property) { | 98 void View::ClearLocalProperty(const ViewProperty<T>* property) { |
99 SetLocalProperty(property, property->default_value); | 99 SetLocalProperty(property, property->default_value); |
100 } | 100 } |
101 | 101 |
102 } // namespace mus | 102 } // namespace mojo |
103 | 103 |
104 // Macros to instantiate the property getter/setter template functions. | 104 // Macros to instantiate the property getter/setter template functions. |
105 #define DECLARE_EXPORTED_VIEW_PROPERTY_TYPE(EXPORT, T) \ | 105 #define DECLARE_EXPORTED_VIEW_PROPERTY_TYPE(EXPORT, T) \ |
106 template EXPORT void mus::View::SetLocalProperty( \ | 106 template EXPORT void mojo::View::SetLocalProperty( \ |
107 const mus::ViewProperty<T>*, T); \ | 107 const mojo::ViewProperty<T>*, T); \ |
108 template EXPORT T mus::View::GetLocalProperty(const mus::ViewProperty<T>*) \ | 108 template EXPORT T mojo::View::GetLocalProperty(const mojo::ViewProperty<T>*) \ |
109 const; \ | 109 const; \ |
110 template EXPORT void mus::View::ClearLocalProperty( \ | 110 template EXPORT void mojo::View::ClearLocalProperty( \ |
111 const mus::ViewProperty<T>*); | 111 const mojo::ViewProperty<T>*); |
112 #define DECLARE_VIEW_PROPERTY_TYPE(T) DECLARE_EXPORTED_VIEW_PROPERTY_TYPE(, T) | 112 #define DECLARE_VIEW_PROPERTY_TYPE(T) DECLARE_EXPORTED_VIEW_PROPERTY_TYPE(, T) |
113 | 113 |
114 #define DEFINE_VIEW_PROPERTY_KEY(TYPE, NAME, DEFAULT) \ | 114 #define DEFINE_VIEW_PROPERTY_KEY(TYPE, NAME, DEFAULT) \ |
115 COMPILE_ASSERT(sizeof(TYPE) <= sizeof(int64_t), property_type_too_large); \ | 115 COMPILE_ASSERT(sizeof(TYPE) <= sizeof(int64_t), property_type_too_large); \ |
116 namespace { \ | 116 namespace { \ |
117 const mus::ViewProperty<TYPE> NAME##_Value = {DEFAULT, #NAME, nullptr}; \ | 117 const mojo::ViewProperty<TYPE> NAME##_Value = {DEFAULT, #NAME, nullptr}; \ |
118 } \ | 118 } \ |
119 const mus::ViewProperty<TYPE>* const NAME = &NAME##_Value; | 119 const mojo::ViewProperty<TYPE>* const NAME = &NAME##_Value; |
120 | 120 |
121 #define DEFINE_LOCAL_VIEW_PROPERTY_KEY(TYPE, NAME, DEFAULT) \ | 121 #define DEFINE_LOCAL_VIEW_PROPERTY_KEY(TYPE, NAME, DEFAULT) \ |
122 COMPILE_ASSERT(sizeof(TYPE) <= sizeof(int64_t), property_type_too_large); \ | 122 COMPILE_ASSERT(sizeof(TYPE) <= sizeof(int64_t), property_type_too_large); \ |
123 namespace { \ | 123 namespace { \ |
124 const mus::ViewProperty<TYPE> NAME##_Value = {DEFAULT, #NAME, nullptr}; \ | 124 const mojo::ViewProperty<TYPE> NAME##_Value = {DEFAULT, #NAME, nullptr}; \ |
125 const mus::ViewProperty<TYPE>* const NAME = &NAME##_Value; \ | 125 const mojo::ViewProperty<TYPE>* const NAME = &NAME##_Value; \ |
126 } | 126 } |
127 | 127 |
128 #define DEFINE_OWNED_VIEW_PROPERTY_KEY(TYPE, NAME, DEFAULT) \ | 128 #define DEFINE_OWNED_VIEW_PROPERTY_KEY(TYPE, NAME, DEFAULT) \ |
129 namespace { \ | 129 namespace { \ |
130 void Deallocator##NAME(int64_t p) { \ | 130 void Deallocator##NAME(int64_t p) { \ |
131 enum { type_must_be_complete = sizeof(TYPE) }; \ | 131 enum { type_must_be_complete = sizeof(TYPE) }; \ |
132 delete mus::ViewPropertyCaster<TYPE*>::FromInt64(p); \ | 132 delete mojo::ViewPropertyCaster<TYPE*>::FromInt64(p); \ |
133 } \ | 133 } \ |
134 const mus::ViewProperty<TYPE*> NAME##_Value = {DEFAULT, #NAME, \ | 134 const mojo::ViewProperty<TYPE*> NAME##_Value = {DEFAULT, #NAME, \ |
135 &Deallocator##NAME}; \ | 135 &Deallocator##NAME}; \ |
136 } \ | 136 } \ |
137 const mus::ViewProperty<TYPE*>* const NAME = &NAME##_Value; | 137 const mojo::ViewProperty<TYPE*>* const NAME = &NAME##_Value; |
138 | 138 |
139 #endif // COMPONENTS_MUS_PUBLIC_CPP_VIEW_PROPERTY_H_ | 139 #endif // COMPONENTS_MUS_PUBLIC_CPP_VIEW_PROPERTY_H_ |
OLD | NEW |