Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: ppapi/cpp/output_traits.h

Issue 60173003: Draft: apps APIs in Pepper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/cpp/extensions/dev/alarms_dev_old.cc ('k') | ppapi/examples/extensions/extensions.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 PPAPI_CPP_OUTPUT_TRAITS_H_ 5 #ifndef PPAPI_CPP_OUTPUT_TRAITS_H_
6 #define PPAPI_CPP_OUTPUT_TRAITS_H_ 6 #define PPAPI_CPP_OUTPUT_TRAITS_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "ppapi/c/pp_resource.h" 10 #include "ppapi/c/pp_resource.h"
11 #include "ppapi/cpp/array_output.h" 11 #include "ppapi/cpp/array_output.h"
12 #include "ppapi/cpp/dev/array_dev.h"
13 #include "ppapi/cpp/dev/from_c_type_converter_dev.h"
14 #include "ppapi/cpp/dev/struct_wrapper_base_dev.h"
12 #include "ppapi/cpp/resource.h" 15 #include "ppapi/cpp/resource.h"
13 16
14 /// @file 17 /// @file
15 /// This file defines internal templates for defining how data is passed to the 18 /// This file defines internal templates for defining how data is passed to the
16 /// browser via output parameters and how to convert that data to the 19 /// browser via output parameters and how to convert that data to the
17 /// corresponding C++ object types. 20 /// corresponding C++ object types.
18 /// 21 ///
19 /// It is used by the callback system, it should not be necessary for end-users 22 /// It is used by the callback system, it should not be necessary for end-users
20 /// to use these templates directly. 23 /// to use these templates directly.
21 24
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // resource object type. 119 // resource object type.
117 static inline T StorageToPluginArg(StorageType& t) { 120 static inline T StorageToPluginArg(StorageType& t) {
118 return T(PASS_REF, t); 121 return T(PASS_REF, t);
119 } 122 }
120 123
121 static inline void Initialize(StorageType* t) { 124 static inline void Initialize(StorageType* t) {
122 *t = 0; 125 *t = 0;
123 } 126 }
124 }; 127 };
125 128
129 template<typename T>
130 struct StructWrapperCallbackOutputTraits {
131 typedef typename T::COutputType APIArgType;
132 typedef FromCTypeConverter<T> StorageType;
133
134 static inline APIArgType StorageToAPIArg(StorageType& t) {
135 return t.StartRawUpdate();
136 }
137
138 static inline T& StorageToPluginArg(StorageType& t) {
139 t.EndRawUpdate();
140 return t.value();
141 }
142
143 static inline void Initialize(StorageType* /* t */) {}
144 };
145
126 // The general templatized base class for all CallbackOutputTraits. This class 146 // The general templatized base class for all CallbackOutputTraits. This class
127 // covers both resources and POD (ints, structs, etc.) by inheriting from the 147 // covers resources, struct wrapper objects and POD (ints, structs, etc.)
128 // appropriate base class depending on whether the given type derives from 148 // by inheriting from the appropriate base class depending on whether the given
129 // pp::Resource. This trick allows us to do this once rather than writing 149 // type derives from pp::Resource or StructWrapperIdentifier. This trick
130 // specializations for every resource object type. 150 // allows us to do this once rather than writing specializations for every
151 // object type.
152 // TODO(yzshen): I will need to add specializtion for Optional<T>. Other than
153 // that I think it should be fine.
131 template<typename T> 154 template<typename T>
132 struct CallbackOutputTraits 155 struct CallbackOutputTraits
133 : public InheritIf<GenericCallbackOutputTraits<T>, 156 : public InheritIf<ResourceCallbackOutputTraits<T>,
134 !IsBaseOf<Resource, T>::value>, 157 IsBaseOf<Resource, T>::value>,
135 public InheritIf<ResourceCallbackOutputTraits<T>, 158 public InheritIf<StructWrapperCallbackOutputTraits<T>,
136 IsBaseOf<Resource, T>::value> { 159 IsBaseOf<StructWrapperIdentifier, T>::value>,
160 public InheritIf<GenericCallbackOutputTraits<T>,
161 !IsBaseOf<Resource, T>::value &&
162 !IsBaseOf<StructWrapperIdentifier, T>::value> {
137 }; 163 };
138 164
139 // A specialization of CallbackOutputTraits for pp::Var output parameters. 165 // A specialization of CallbackOutputTraits for pp::Var output parameters.
140 // It passes a PP_Var* to the browser and converts to a pp::Var when passing 166 // It passes a PP_Var* to the browser and converts to a pp::Var when passing
141 // to the plugin. 167 // to the plugin.
142 template<> 168 template<>
143 struct CallbackOutputTraits<Var> { 169 struct CallbackOutputTraits<Var> {
144 // To call the browser, we just pass a PP_Var* as an output param. 170 // To call the browser, we just pass a PP_Var* as an output param.
145 typedef PP_Var* APIArgType; 171 typedef PP_Var* APIArgType;
146 typedef PP_Var StorageType; 172 typedef PP_Var StorageType;
(...skipping 30 matching lines...) Expand all
177 // Converts the PP_Bool to a bool object. 203 // Converts the PP_Bool to a bool object.
178 static inline bool StorageToPluginArg(StorageType& t) { 204 static inline bool StorageToPluginArg(StorageType& t) {
179 return PP_ToBool(t); 205 return PP_ToBool(t);
180 } 206 }
181 207
182 static inline void Initialize(StorageType* t) { 208 static inline void Initialize(StorageType* t) {
183 *t = PP_FALSE; 209 *t = PP_FALSE;
184 } 210 }
185 }; 211 };
186 212
213 template<typename T>
214 struct CallbackOutputTraits<Array<T> > {
215 typedef typename Array<T>::COutputType APIArgType;
216 typedef Array<T> StorageType;
217
218 static inline APIArgType StorageToAPIArg(StorageType& t) {
219 return t.StartRawUpdate();
220 }
221
222 static inline Array<T>& StorageToPluginArg(StorageType& t) {
223 t.EndRawUpdate();
224 return t;
225 }
226
227 static inline void Initialize(StorageType* t) {
228 }
229 };
230
187 // Array output parameters ----------------------------------------------------- 231 // Array output parameters -----------------------------------------------------
188 232
189 // Output traits for vectors of all "plain old data" (POD) types. It is 233 // Output traits for vectors of all "plain old data" (POD) types. It is
190 // implemented to pass a pointer to the browser as an output parameter. 234 // implemented to pass a pointer to the browser as an output parameter.
191 // 235 //
192 // This is used as a base class for the general vector CallbackOutputTraits 236 // This is used as a base class for the general vector CallbackOutputTraits
193 // below in the case where T is not a resource. 237 // below in the case where T is not a resource.
194 template<typename T> 238 template<typename T>
195 struct GenericVectorCallbackOutputTraits { 239 struct GenericVectorCallbackOutputTraits {
196 // All arrays are output via a PP_ArrayOutput type. 240 // All arrays are output via a PP_ArrayOutput type.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 return t.output(); 317 return t.output();
274 } 318 }
275 319
276 static inline void Initialize(StorageType* /* t */) {} 320 static inline void Initialize(StorageType* /* t */) {}
277 }; 321 };
278 322
279 } // namespace internal 323 } // namespace internal
280 } // namespace pp 324 } // namespace pp
281 325
282 #endif // PPAPI_CPP_OUTPUT_TRAITS_H_ 326 #endif // PPAPI_CPP_OUTPUT_TRAITS_H_
OLDNEW
« no previous file with comments | « ppapi/cpp/extensions/dev/alarms_dev_old.cc ('k') | ppapi/examples/extensions/extensions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698