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

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

Issue 9728001: Make the file chooser use PP_ArrayOutput (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 months 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
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 "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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // Array output parameters ----------------------------------------------------- 142 // Array output parameters -----------------------------------------------------
143 143
144 // Output traits for vectors of all "plain old data" (POD) types. It is 144 // Output traits for vectors of all "plain old data" (POD) types. It is
145 // implemented to pass a pointer to the browser as an output parameter. 145 // implemented to pass a pointer to the browser as an output parameter.
146 // 146 //
147 // This is used as a base class for the general vector CallbackOutputTraits 147 // This is used as a base class for the general vector CallbackOutputTraits
148 // below in the case where T is not a resource. 148 // below in the case where T is not a resource.
149 template<typename T> 149 template<typename T>
150 struct GenericVectorCallbackOutputTraits { 150 struct GenericVectorCallbackOutputTraits {
151 // All arrays are output via a PP_ArrayOutput type. 151 // All arrays are output via a PP_ArrayOutput type.
152 typedef PP_ArrayOutput* APIArgType; 152 typedef PP_ArrayOutput APIArgType;
153 153
154 // We store the array as this adapter which combines the PP_ArrayOutput 154 // We store the array as this adapter which combines the PP_ArrayOutput
155 // structure with the underlying std::vector that it will write into. 155 // structure with the underlying std::vector that it will write into.
156 typedef ArrayOutputAdapterWithStorage<T> StorageType; 156 typedef ArrayOutputAdapterWithStorage<T> StorageType;
157 157
158 // Retrieves the PP_ArrayOutput interface for our vector object that the 158 // Retrieves the PP_ArrayOutput interface for our vector object that the
159 // browser will use to write into our code. 159 // browser will use to write into our code.
160 static inline APIArgType StorageToAPIArg(StorageType& t) { 160 static inline APIArgType StorageToAPIArg(StorageType& t) {
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_Resource* as an output parameter to the browser, and convert to the
172 // given resource object type T when passing to the plugin. 172 // 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 // specilalizations 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
206 // and plain data are handled separately. See the above definition for more. 206 // and plain data are handled separately. See the above definition for more.
207 template<> 207 template<>
208 struct CallbackOutputTraits< std::vector<pp::Var> > { 208 struct CallbackOutputTraits< std::vector<pp::Var> > {
209 // All arrays are output via a PP_ArrayOutput type. 209 // All arrays are output via a PP_ArrayOutput type.
210 typedef PP_ArrayOutput* APIArgType; 210 typedef PP_ArrayOutput APIArgType;
211 211
212 // We store the array as this adapter which combines the PP_ArrayOutput 212 // We store the array as this adapter which combines the PP_ArrayOutput
213 // structure with the underlying std::vector that it will write into. 213 // structure with the underlying std::vector that it will write into.
214 typedef VarArrayOutputAdapterWithStorage StorageType; 214 typedef VarArrayOutputAdapterWithStorage StorageType;
215 215
216 // Retrieves the PP_ArrayOutput interface for our vector object that the 216 // Retrieves the PP_ArrayOutput interface for our vector object that the
217 // browser will use to write into our code. 217 // browser will use to write into our code.
218 static inline APIArgType StorageToAPIArg(StorageType& t) { 218 static inline APIArgType StorageToAPIArg(StorageType& t) {
219 return t.pp_array_output(); 219 return t.pp_array_output();
220 } 220 }
221 221
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698