OLD | NEW |
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 "ppapi/c/pp_resource.h" | 8 #include "ppapi/c/pp_resource.h" |
9 #include "ppapi/cpp/array_output.h" | 9 #include "ppapi/cpp/array_output.h" |
10 | 10 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 return t.pp_array_output(); | 161 return t.pp_array_output(); |
162 } | 162 } |
163 | 163 |
164 // Retrieves the underlying vector that can be passed to the plugin. | 164 // Retrieves the underlying vector that can be passed to the plugin. |
165 static inline std::vector<T>& StorageToPluginArg(StorageType& t) { | 165 static inline std::vector<T>& StorageToPluginArg(StorageType& t) { |
166 return t.output(); | 166 return t.output(); |
167 } | 167 } |
168 }; | 168 }; |
169 | 169 |
170 // Output traits for all vectors of resource types. It is implemented to pass | 170 // Output traits for all vectors of resource types. It is implemented to pass |
171 // a PP_Resource* as an output parameter to the browser, and convert to the | 171 // a PP_ArrayOutput parameter to the browser, and convert the returned resources |
172 // given resource object type T when passing to the plugin. | 172 // to a vector of the given resource object type T when passing to the plugin. |
173 // | 173 // |
174 // Note that this class is parameterized by the resource object, for example | 174 // Note that this class is parameterized by the resource object, for example |
175 // ResourceVectorCallbackOutputTraits<pp::FileRef>. This is used as a base | 175 // ResourceVectorCallbackOutputTraits<pp::FileRef>. This is used as a base |
176 // class for CallbackOutputTraits below for the case where T is a derived | 176 // class for CallbackOutputTraits below for the case where T is a derived |
177 // class of pp::Resource. | 177 // class of pp::Resource. |
178 template<typename T> | 178 template<typename T> |
179 struct ResourceVectorCallbackOutputTraits { | 179 struct ResourceVectorCallbackOutputTraits { |
180 typedef PP_ArrayOutput APIArgType; | 180 typedef PP_ArrayOutput APIArgType; |
181 typedef ResourceArrayOutputAdapterWithStorage<T> StorageType; | 181 typedef ResourceArrayOutputAdapterWithStorage<T> StorageType; |
182 | 182 |
183 static inline APIArgType StorageToAPIArg(StorageType& t) { | 183 static inline APIArgType StorageToAPIArg(StorageType& t) { |
184 return t.pp_array_output(); | 184 return t.pp_array_output(); |
185 } | 185 } |
186 static inline std::vector<T>& StorageToPluginArg(StorageType& t) { | 186 static inline std::vector<T>& StorageToPluginArg(StorageType& t) { |
187 return t.output(); | 187 return t.output(); |
188 } | 188 } |
189 }; | 189 }; |
190 | 190 |
191 // Specialization of CallbackOutputTraits for vectors. This struct covers both | 191 // Specialization of CallbackOutputTraits for vectors. This struct covers both |
192 // arrays of resources and arrays of POD (ints, structs, etc.) by inheriting | 192 // arrays of resources and arrays of POD (ints, structs, etc.) by inheriting |
193 // from the appropriate base class depending on whether the given type derives | 193 // from the appropriate base class depending on whether the given type derives |
194 // from pp::Resource. This trick allows us to do this once rather than writing | 194 // from pp::Resource. This trick allows us to do this once rather than writing |
195 // specilalizations for every resource object type. | 195 // specializations for every resource object type. |
196 template<typename T> | 196 template<typename T> |
197 struct CallbackOutputTraits< std::vector<T> > | 197 struct CallbackOutputTraits< std::vector<T> > |
198 : public InheritIf<GenericVectorCallbackOutputTraits<T>, | 198 : public InheritIf<GenericVectorCallbackOutputTraits<T>, |
199 !IsBaseOf<Resource, T>::value>, | 199 !IsBaseOf<Resource, T>::value>, |
200 public InheritIf<ResourceVectorCallbackOutputTraits<T>, | 200 public InheritIf<ResourceVectorCallbackOutputTraits<T>, |
201 IsBaseOf<Resource, T>::value> { | 201 IsBaseOf<Resource, T>::value> { |
202 }; | 202 }; |
203 | 203 |
204 // A specialization of CallbackOutputTraits to provide the callback system | 204 // A specialization of CallbackOutputTraits to provide the callback system |
205 // the information on how to handle vectors of pp::Var. Vectors of resources | 205 // the information on how to handle vectors of pp::Var. Vectors of resources |
(...skipping 16 matching lines...) Expand all Loading... |
222 // Retrieves the underlying vector that can be passed to the plugin. | 222 // Retrieves the underlying vector that can be passed to the plugin. |
223 static inline std::vector<pp::Var>& StorageToPluginArg(StorageType& t) { | 223 static inline std::vector<pp::Var>& StorageToPluginArg(StorageType& t) { |
224 return t.output(); | 224 return t.output(); |
225 } | 225 } |
226 }; | 226 }; |
227 | 227 |
228 } // namespace internal | 228 } // namespace internal |
229 } // namespace pp | 229 } // namespace pp |
230 | 230 |
231 #endif // PPAPI_CPP_OUTPUT_TRAITS_H_ | 231 #endif // PPAPI_CPP_OUTPUT_TRAITS_H_ |
OLD | NEW |