-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcommon.h
85 lines (70 loc) · 1.71 KB
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// Copyright RIME Developers
// Distributed under the BSD License
//
// 2011-03-14 GONG Chen <[email protected]>
//
#ifndef RIME_COMMON_H_
#define RIME_COMMON_H_
#include <functional>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <boost/optional.hpp>
#define BOOST_BIND_NO_PLACEHOLDERS
#include <boost/signals2/connection.hpp>
#include <boost/signals2/signal.hpp>
#ifdef RIME_ENABLE_LOGGING
#include <glog/logging.h>
#else
#include "no_logging.h"
#endif // RIME_ENABLE_LOGGING
// call a pointer to member function on this
#define RIME_THIS_CALL(f) (this->*(f))
#define RIME_THIS_CALL_AS(T, f) ((T*)this->*(f))
#define RIME_API
namespace rime {
using std::function;
using std::list;
using std::make_pair;
using std::map;
using std::pair;
using std::set;
using std::string;
using std::vector;
using boost::optional;
template <class Key, class T>
using hash_map = std::unordered_map<Key, T>;
template <class T>
using hash_set = std::unordered_set<T>;
template <class T>
using the = std::unique_ptr<T>;
template <class T>
using an = std::shared_ptr<T>;
template <class T>
using of = an<T>;
template <class T>
using weak = std::weak_ptr<T>;
template <class X, class Y>
inline an<X> As(const an<Y>& ptr) {
return std::dynamic_pointer_cast<X>(ptr);
}
template <class X, class Y>
inline bool Is(const an<Y>& ptr) {
return bool(As<X, Y>(ptr));
}
template <class T, class... Args>
inline an<T> New(Args&&... args) {
return std::make_shared<T>(std::forward<Args>(args)...);
}
using boost::signals2::connection;
using boost::signals2::signal;
} // namespace rime
#endif // RIME_COMMON_H_