chromium之tuple
// A Tuple is a generic templatized container, similar in concept to std::pair.
// There are classes Tuple0 to Tuple6, cooresponding to the number of elements
// it contains. The convenient MakeTuple() function takes 0 to 6 arguments,
// and will construct and return the appropriate Tuple object. The functions
// DispatchToMethod and DispatchToFunction take a function pointer or instance
// and method pointer, and unpack a tuple into arguments to the call.
//
// Tuple elements are copied by value, and stored in the tuple. See the unit
// tests for more details of how/when the values are copied.
//
// Example usage:
// // These two methods of creating a Tuple are identical.
// Tuple2<int, const char*> tuple_a(1, "wee");
// Tuple2<int, const char*> tuple_b = MakeTuple(1, "wee");
//
// void SomeFunc(int a, const char* b) { }
// DispatchToFunction(&SomeFunc, tuple_a); // SomeFunc(1, "wee")
// DispatchToFunction(
// &SomeFunc, MakeTuple(10, "foo")); // SomeFunc(10, "foo")
//
// struct { void SomeMeth(int a, int b, int c) { } } foo;
// DispatchToMethod(&foo, &Foo::SomeMeth, MakeTuple(1, 2, 3));
// // foo->SomeMeth(1, 2, 3);
Tuple是一个通用的模板化容器,类似std::pair的概念。
转换函数MakeTuple接收0-6个参数,并返回一个Tuple对象
DispatchToFunction 接收一个函数指针,并解压一个tuple作为函数指针的参数,并调用
// void SomeFunc(int a, const char* b) { }
// DispatchToFunction(&SomeFunc, tuple_a); // SomeFunc(1, "wee")
DispatchToMethod 接收一个实例、实例的方法指针,并解压一个tuple作为函数指针的参数,并调用
// struct { void SomeMeth(int a, int b, int c) { } } foo;
// DispatchToMethod(&foo, &Foo::SomeMeth, MakeTuple(1, 2, 3));
看看代码
template <class P>
struct TupleTraits {
typedef P ValueType;
typedef P& RefType;
typedef const P& ParamType;
}; template <class P>
struct TupleTraits<P&> {
typedef P ValueType;
typedef P& RefType;
typedef P& ParamType;
}; template <class A>
struct Tuple1 {
public:
typedef A TypeA;
typedef Tuple1<typename TupleTraits<A>::ValueType> ValueTuple;
typedef Tuple1<typename TupleTraits<A>::RefType> RefTuple;
typedef Tuple1<typename TupleTraits<A>::ParamType> ParamTuple; Tuple1() {}
explicit Tuple1(typename TupleTraits<A>::ParamType a) : a(a) {} A a;
}; template <class Function, class A>
inline void DispatchToFunction(Function function, const Tuple1<A>& arg) {
(*function)(arg.a);
}
chromium之tuple的更多相关文章
- chromium之task
// A task is a generic runnable thingy, usually used for running code on a // different thread or fo ...
- [原创]chromium源码阅读-进程间通信IPC.消息的接收与应答
chromium源码阅读-进程间通信IPC.消息的接收与应答 chromium源码阅读-进程间通信IPC.消息的接收与应答 介绍 chromium进程间通信在win32下是通过命名管道的方式实现的 ...
- QT5利用chromium内核与HTML页面交互
在QT5.4之前,做QT开发浏览器只能选择QWebkit,但是有过使用的都会发现,这个webkit不是出奇的慢,简直是慢的令人发指,Release模式下还行,debug下你就无语了,但是webkit毕 ...
- 【.NET深呼吸】元组数据(Tuple)
各位观众,大家好,欢迎收看由火星电视台直播的<老周吹牛>节目,注意:本节目没有任何技术含量,如果您没有兴趣,请砸掉电视机. 今天说一下System命名空间下的一个数据类型——Tuple,翻 ...
- python之最强王者(7)——元组(tuple)
1.序列(sequence): 说明:在前面的字符串列表中其实我们已经用到了序列,之所以放到这篇来讲主要是为了承上启下,方便理解和记忆. python的数据访问模型:直接存取 ,序列 ,映射 对非容器 ...
- tuple放入dict中
tuple放入dict中是否可以正常运行 # 将tuple放入dict中 a = ('AI','Kobe','Yao') b = ('AI',['Kobe','Yao']) dict1 = {'a': ...
- list,tuple,dict,set常用方法
Python中list,tuple,dict,set常用方法 collections模块提供的其它有用扩展类型 from collections import Counter from collect ...
- Python中内置数据类型list,tuple,dict,set的区别和用法
Python中内置数据类型list,tuple,dict,set的区别和用法 Python语言简洁明了,可以用较少的代码实现同样的功能.这其中Python的四个内置数据类型功不可没,他们即是list, ...
- Google之Chromium浏览器源码学习——base公共通用库(一)
Google的优秀C++开源项目繁多,其中的Chromium浏览器项目可以说是很具有代表性的,此外还包括其第三开发开源库或是自己的优秀开源库,可以根据需要抽取自己感兴趣的部分.在研究.学习该项目前的时 ...
随机推荐
- JS中绑定事件顺序(事件冒泡与事件捕获区别)
在JS中,绑定的事件默认的执行时间是在冒泡阶段执行,而非在捕获阶段(重要),这也是为什么当父类和子类都绑定了某个事件,会先调用子类绑定的事件,后调用父类的事件.直接看下面实例 <!Doctype ...
- C# ObjectArx cad二次开发
1 环境搭建:安装CAD 和objectArx库,这里安装的是cad2012和objectArx2010 ,vs是2010 2 新建一个类库项目,引用objectArx安装目录下inc文件夹下的AcD ...
- IO流之序列化流与反序列化流
序列化流与反序列化流 用于从流中读取对象的 操作流 ObjectInputStream 称为 反序列化流 用于向流中写入对象的操作流 ObjectOutputStream 称为 序列化流 l ...
- Strom入门
Worker.Executor.Task详解: Storm在集群上运行一个Topology时,主要通过以下3个实体来完成Topology的执行工作:1. Worker Process(工作进程)——S ...
- 《O2O实战:二维码全渠道营销》读书笔记思维导图(530KB)
- Linux --Apache服务搭建
Apache网站服务 1.基本配置 安装 [root@localhost /]# rpm -e httpd --nodeps --卸载rpm方式安装的httpd [root@localhost qwe ...
- 林锐书:写一个hello world by seasoned professional
#include <iostream> #include <string.h> using namespace std; class String { private: int ...
- Python爬虫利器之Beautiful Soup,Requests,正则的用法(转)
https://cuiqingcai.com/1319.html https://cuiqingcai.com/2556.html https://cuiqingcai.com/977.html
- Python 用多线程上传和下载文件
# -*- coding: utf-8 -*- __author__ = 'louis' from ftplib import FTP import multiprocessing import ti ...
- NYOJ298 点的变换 【矩阵乘法经典】
任意门:http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=298 点的变换 时间限制:2000 ms | 内存限制:65535 KB 难度:5 ...