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

Side by Side Diff: base/tuple.h

Issue 10621: Adds the ability for save dialogs to take a default extension.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 // A Tuple is a generic templatized container, similar in concept to std::pair. 5 // A Tuple is a generic templatized container, similar in concept to std::pair.
6 // There are classes Tuple0 to Tuple6, cooresponding to the number of elements 6 // There are classes Tuple0 to Tuple6, cooresponding to the number of elements
7 // it contains. The convenient MakeTuple() function takes 0 to 6 arguments, 7 // it contains. The convenient MakeTuple() function takes 0 to 6 arguments,
8 // and will construct and return the appropriate Tuple object. The functions 8 // and will construct and return the appropriate Tuple object. The functions
9 // DispatchToMethod and DispatchToFunction take a function pointer or instance 9 // DispatchToMethod and DispatchToFunction take a function pointer or instance
10 // and method pointer, and unpack a tuple into arguments to the call. 10 // and method pointer, and unpack a tuple into arguments to the call.
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 } 226 }
227 227
228 A a; 228 A a;
229 B b; 229 B b;
230 C c; 230 C c;
231 D d; 231 D d;
232 E e; 232 E e;
233 F f; 233 F f;
234 }; 234 };
235 235
236 template <class A, class B, class C, class D, class E, class F, class G>
237 struct Tuple7 {
238 public:
239 typedef A TypeA;
240 typedef B TypeB;
241 typedef C TypeC;
242 typedef D TypeD;
243 typedef E TypeE;
244 typedef F TypeF;
245 typedef G TypeG;
246 typedef Tuple7<typename TupleTraits<A>::ValueType,
247 typename TupleTraits<B>::ValueType,
248 typename TupleTraits<C>::ValueType,
249 typename TupleTraits<D>::ValueType,
250 typename TupleTraits<E>::ValueType,
251 typename TupleTraits<F>::ValueType,
252 typename TupleTraits<G>::ValueType> ValueTuple;
253 typedef Tuple7<typename TupleTraits<A>::RefType,
254 typename TupleTraits<B>::RefType,
255 typename TupleTraits<C>::RefType,
256 typename TupleTraits<D>::RefType,
257 typename TupleTraits<E>::RefType,
258 typename TupleTraits<F>::RefType,
259 typename TupleTraits<G>::RefType> RefTuple;
260
261 Tuple7() {}
262 Tuple7(typename TupleTraits<A>::ParamType a,
263 typename TupleTraits<B>::ParamType b,
264 typename TupleTraits<C>::ParamType c,
265 typename TupleTraits<D>::ParamType d,
266 typename TupleTraits<E>::ParamType e,
267 typename TupleTraits<F>::ParamType f,
268 typename TupleTraits<G>::ParamType g)
269 : a(a), b(b), c(c), d(d), e(e), f(f), g(g) {
270 }
271
272 A a;
273 B b;
274 C c;
275 D d;
276 E e;
277 F f;
278 G g;
279 };
280
236 // Tuple creators ------------------------------------------------------------- 281 // Tuple creators -------------------------------------------------------------
237 // 282 //
238 // Helper functions for constructing tuples while inferring the template 283 // Helper functions for constructing tuples while inferring the template
239 // argument types. 284 // argument types.
240 285
241 inline Tuple0 MakeTuple() { 286 inline Tuple0 MakeTuple() {
242 return Tuple0(); 287 return Tuple0();
243 } 288 }
244 289
245 template <class A> 290 template <class A>
(...skipping 22 matching lines...) Expand all
268 const D& d, const E& e) { 313 const D& d, const E& e) {
269 return Tuple5<A, B, C, D, E>(a, b, c, d, e); 314 return Tuple5<A, B, C, D, E>(a, b, c, d, e);
270 } 315 }
271 316
272 template <class A, class B, class C, class D, class E, class F> 317 template <class A, class B, class C, class D, class E, class F>
273 inline Tuple6<A, B, C, D, E, F> MakeTuple(const A& a, const B& b, const C& c, 318 inline Tuple6<A, B, C, D, E, F> MakeTuple(const A& a, const B& b, const C& c,
274 const D& d, const E& e, const F& f) { 319 const D& d, const E& e, const F& f) {
275 return Tuple6<A, B, C, D, E, F>(a, b, c, d, e, f); 320 return Tuple6<A, B, C, D, E, F>(a, b, c, d, e, f);
276 } 321 }
277 322
323 template <class A, class B, class C, class D, class E, class F, class G>
324 inline Tuple7<A, B, C, D, E, F, G> MakeTuple(const A& a, const B& b, const C& c,
325 const D& d, const E& e, const F& f,
326 const G& g) {
327 return Tuple7<A, B, C, D, E, F, G>(a, b, c, d, e, f, g);
328 }
329
278 // The following set of helpers make what Boost refers to as "Tiers" - a tuple 330 // The following set of helpers make what Boost refers to as "Tiers" - a tuple
279 // of references. 331 // of references.
280 332
281 template <class A> 333 template <class A>
282 inline Tuple1<A&> MakeRefTuple(A& a) { 334 inline Tuple1<A&> MakeRefTuple(A& a) {
283 return Tuple1<A&>(a); 335 return Tuple1<A&>(a);
284 } 336 }
285 337
286 template <class A, class B> 338 template <class A, class B>
287 inline Tuple2<A&, B&> MakeRefTuple(A& a, B& b) { 339 inline Tuple2<A&, B&> MakeRefTuple(A& a, B& b) {
(...skipping 14 matching lines...) Expand all
302 inline Tuple5<A&, B&, C&, D&, E&> MakeRefTuple(A& a, B& b, C& c, D& d, E& e) { 354 inline Tuple5<A&, B&, C&, D&, E&> MakeRefTuple(A& a, B& b, C& c, D& d, E& e) {
303 return Tuple5<A&, B&, C&, D&, E&>(a, b, c, d, e); 355 return Tuple5<A&, B&, C&, D&, E&>(a, b, c, d, e);
304 } 356 }
305 357
306 template <class A, class B, class C, class D, class E, class F> 358 template <class A, class B, class C, class D, class E, class F>
307 inline Tuple6<A&, B&, C&, D&, E&, F&> MakeRefTuple(A& a, B& b, C& c, D& d, E& e, 359 inline Tuple6<A&, B&, C&, D&, E&, F&> MakeRefTuple(A& a, B& b, C& c, D& d, E& e,
308 F& f) { 360 F& f) {
309 return Tuple6<A&, B&, C&, D&, E&, F&>(a, b, c, d, e, f); 361 return Tuple6<A&, B&, C&, D&, E&, F&>(a, b, c, d, e, f);
310 } 362 }
311 363
364 template <class A, class B, class C, class D, class E, class F, class G>
365 inline Tuple7<A&, B&, C&, D&, E&, F&, G&> MakeRefTuple(A& a, B& b, C& c, D& d,
366 E& e, F& f, G& g) {
367 return Tuple7<A&, B&, C&, D&, E&, F&, G&>(a, b, c, d, e, f, g);
368 }
369
312 // Dispatchers ---------------------------------------------------------------- 370 // Dispatchers ----------------------------------------------------------------
313 // 371 //
314 // Helper functions that call the given method on an object, with the unpacked 372 // Helper functions that call the given method on an object, with the unpacked
315 // tuple arguments. Notice that they all have the same number of arguments, 373 // tuple arguments. Notice that they all have the same number of arguments,
316 // so you need only write: 374 // so you need only write:
317 // DispatchToMethod(object, &Object::method, args); 375 // DispatchToMethod(object, &Object::method, args);
318 // This is very useful for templated dispatchers, since they don't need to know 376 // This is very useful for templated dispatchers, since they don't need to know
319 // what type |args| is. 377 // what type |args| is.
320 378
321 // Non-Static Dispatchers with no out params. 379 // Non-Static Dispatchers with no out params.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e); 416 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e);
359 } 417 }
360 418
361 template<class ObjT, class Method, class A, class B, class C, class D, class E, 419 template<class ObjT, class Method, class A, class B, class C, class D, class E,
362 class F> 420 class F>
363 inline void DispatchToMethod(ObjT* obj, Method method, 421 inline void DispatchToMethod(ObjT* obj, Method method,
364 const Tuple6<A, B, C, D, E, F>& arg) { 422 const Tuple6<A, B, C, D, E, F>& arg) {
365 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f); 423 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f);
366 } 424 }
367 425
426 template<class ObjT, class Method, class A, class B, class C, class D, class E,
427 class F, class G>
428 inline void DispatchToMethod(ObjT* obj, Method method,
429 const Tuple7<A, B, C, D, E, F, G>& arg) {
430 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f, arg.g);
431 }
432
368 // Static Dispatchers with no out params. 433 // Static Dispatchers with no out params.
369 434
370 template <class Function> 435 template <class Function>
371 inline void DispatchToFunction(Function function, const Tuple0& arg) { 436 inline void DispatchToFunction(Function function, const Tuple0& arg) {
372 (*function)(); 437 (*function)();
373 } 438 }
374 439
375 template <class Function, class A> 440 template <class Function, class A>
376 inline void DispatchToFunction(Function function, const A& arg) { 441 inline void DispatchToFunction(Function function, const A& arg) {
377 (*function)(arg); 442 (*function)(arg);
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 class OutA, class OutB, class OutC, class OutD, class OutE> 862 class OutA, class OutB, class OutC, class OutD, class OutE>
798 inline void DispatchToMethod(ObjT* obj, Method method, 863 inline void DispatchToMethod(ObjT* obj, Method method,
799 const Tuple6<InA, InB, InC, InD, InE, InF>& in, 864 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
800 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { 865 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
801 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, 866 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f,
802 &out->a, &out->b, &out->c, &out->d, &out->e); 867 &out->a, &out->b, &out->c, &out->d, &out->e);
803 } 868 }
804 869
805 #endif // BASE_TUPLE_H__ 870 #endif // BASE_TUPLE_H__
806 871
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698