jieba-rb 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +19 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +85 -0
  8. data/Rakefile +15 -0
  9. data/ext/cppjieba/.gitignore +17 -0
  10. data/ext/cppjieba/.travis.yml +22 -0
  11. data/ext/cppjieba/CMakeLists.txt +28 -0
  12. data/ext/cppjieba/ChangeLog.md +236 -0
  13. data/ext/cppjieba/README.md +285 -0
  14. data/ext/cppjieba/README_EN.md +111 -0
  15. data/ext/cppjieba/appveyor.yml +32 -0
  16. data/ext/cppjieba/deps/CMakeLists.txt +1 -0
  17. data/ext/cppjieba/deps/gtest/CMakeLists.txt +5 -0
  18. data/ext/cppjieba/deps/gtest/include/gtest/gtest-death-test.h +283 -0
  19. data/ext/cppjieba/deps/gtest/include/gtest/gtest-message.h +230 -0
  20. data/ext/cppjieba/deps/gtest/include/gtest/gtest-param-test.h +1421 -0
  21. data/ext/cppjieba/deps/gtest/include/gtest/gtest-param-test.h.pump +487 -0
  22. data/ext/cppjieba/deps/gtest/include/gtest/gtest-printers.h +796 -0
  23. data/ext/cppjieba/deps/gtest/include/gtest/gtest-spi.h +232 -0
  24. data/ext/cppjieba/deps/gtest/include/gtest/gtest-test-part.h +176 -0
  25. data/ext/cppjieba/deps/gtest/include/gtest/gtest-typed-test.h +259 -0
  26. data/ext/cppjieba/deps/gtest/include/gtest/gtest.h +2155 -0
  27. data/ext/cppjieba/deps/gtest/include/gtest/gtest_pred_impl.h +358 -0
  28. data/ext/cppjieba/deps/gtest/include/gtest/gtest_prod.h +58 -0
  29. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-death-test-internal.h +308 -0
  30. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-filepath.h +210 -0
  31. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-internal.h +1226 -0
  32. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-linked_ptr.h +233 -0
  33. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-param-util-generated.h +4822 -0
  34. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-param-util-generated.h.pump +301 -0
  35. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-param-util.h +619 -0
  36. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-port.h +1788 -0
  37. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-string.h +350 -0
  38. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-tuple.h +968 -0
  39. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-tuple.h.pump +336 -0
  40. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-type-util.h +3330 -0
  41. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-type-util.h.pump +296 -0
  42. data/ext/cppjieba/deps/gtest/src/.deps/.dirstamp +0 -0
  43. data/ext/cppjieba/deps/gtest/src/.deps/gtest-all.Plo +681 -0
  44. data/ext/cppjieba/deps/gtest/src/.deps/gtest_main.Plo +509 -0
  45. data/ext/cppjieba/deps/gtest/src/.dirstamp +0 -0
  46. data/ext/cppjieba/deps/gtest/src/gtest-all.cc +48 -0
  47. data/ext/cppjieba/deps/gtest/src/gtest-death-test.cc +1234 -0
  48. data/ext/cppjieba/deps/gtest/src/gtest-filepath.cc +380 -0
  49. data/ext/cppjieba/deps/gtest/src/gtest-internal-inl.h +1038 -0
  50. data/ext/cppjieba/deps/gtest/src/gtest-port.cc +746 -0
  51. data/ext/cppjieba/deps/gtest/src/gtest-printers.cc +356 -0
  52. data/ext/cppjieba/deps/gtest/src/gtest-test-part.cc +110 -0
  53. data/ext/cppjieba/deps/gtest/src/gtest-typed-test.cc +110 -0
  54. data/ext/cppjieba/deps/gtest/src/gtest.cc +4898 -0
  55. data/ext/cppjieba/deps/gtest/src/gtest_main.cc +39 -0
  56. data/ext/cppjieba/deps/limonp/ArgvContext.hpp +70 -0
  57. data/ext/cppjieba/deps/limonp/BlockingQueue.hpp +49 -0
  58. data/ext/cppjieba/deps/limonp/BoundedBlockingQueue.hpp +67 -0
  59. data/ext/cppjieba/deps/limonp/BoundedQueue.hpp +65 -0
  60. data/ext/cppjieba/deps/limonp/Closure.hpp +206 -0
  61. data/ext/cppjieba/deps/limonp/Colors.hpp +31 -0
  62. data/ext/cppjieba/deps/limonp/Condition.hpp +38 -0
  63. data/ext/cppjieba/deps/limonp/Config.hpp +103 -0
  64. data/ext/cppjieba/deps/limonp/FileLock.hpp +74 -0
  65. data/ext/cppjieba/deps/limonp/ForcePublic.hpp +7 -0
  66. data/ext/cppjieba/deps/limonp/LocalVector.hpp +139 -0
  67. data/ext/cppjieba/deps/limonp/Logging.hpp +76 -0
  68. data/ext/cppjieba/deps/limonp/Md5.hpp +411 -0
  69. data/ext/cppjieba/deps/limonp/MutexLock.hpp +51 -0
  70. data/ext/cppjieba/deps/limonp/NonCopyable.hpp +21 -0
  71. data/ext/cppjieba/deps/limonp/StdExtension.hpp +159 -0
  72. data/ext/cppjieba/deps/limonp/StringUtil.hpp +365 -0
  73. data/ext/cppjieba/deps/limonp/Thread.hpp +44 -0
  74. data/ext/cppjieba/deps/limonp/ThreadPool.hpp +86 -0
  75. data/ext/cppjieba/dict/README.md +31 -0
  76. data/ext/cppjieba/dict/hmm_model.utf8 +34 -0
  77. data/ext/cppjieba/dict/idf.utf8 +258826 -0
  78. data/ext/cppjieba/dict/jieba.dict.utf8 +348982 -0
  79. data/ext/cppjieba/dict/pos_dict/char_state_tab.utf8 +6653 -0
  80. data/ext/cppjieba/dict/pos_dict/prob_emit.utf8 +166 -0
  81. data/ext/cppjieba/dict/pos_dict/prob_start.utf8 +259 -0
  82. data/ext/cppjieba/dict/pos_dict/prob_trans.utf8 +5222 -0
  83. data/ext/cppjieba/dict/stop_words.utf8 +1534 -0
  84. data/ext/cppjieba/dict/user.dict.utf8 +4 -0
  85. data/ext/cppjieba/include/cppjieba/DictTrie.hpp +227 -0
  86. data/ext/cppjieba/include/cppjieba/FullSegment.hpp +93 -0
  87. data/ext/cppjieba/include/cppjieba/HMMModel.hpp +129 -0
  88. data/ext/cppjieba/include/cppjieba/HMMSegment.hpp +190 -0
  89. data/ext/cppjieba/include/cppjieba/Jieba.hpp +108 -0
  90. data/ext/cppjieba/include/cppjieba/KeywordExtractor.hpp +153 -0
  91. data/ext/cppjieba/include/cppjieba/MPSegment.hpp +137 -0
  92. data/ext/cppjieba/include/cppjieba/MixSegment.hpp +109 -0
  93. data/ext/cppjieba/include/cppjieba/PosTagger.hpp +77 -0
  94. data/ext/cppjieba/include/cppjieba/PreFilter.hpp +54 -0
  95. data/ext/cppjieba/include/cppjieba/QuerySegment.hpp +90 -0
  96. data/ext/cppjieba/include/cppjieba/SegmentBase.hpp +46 -0
  97. data/ext/cppjieba/include/cppjieba/SegmentTagged.hpp +24 -0
  98. data/ext/cppjieba/include/cppjieba/TextRankExtractor.hpp +190 -0
  99. data/ext/cppjieba/include/cppjieba/Trie.hpp +174 -0
  100. data/ext/cppjieba/include/cppjieba/Unicode.hpp +215 -0
  101. data/ext/jieba/extconf.rb +28 -0
  102. data/ext/jieba/jieba.c +11 -0
  103. data/ext/jieba/jieba.h +11 -0
  104. data/ext/jieba/keyword.cc +92 -0
  105. data/ext/jieba/keyword.h +17 -0
  106. data/ext/jieba/segment.cc +107 -0
  107. data/ext/jieba/segment.h +17 -0
  108. data/ext/jieba/tagging.cc +76 -0
  109. data/ext/jieba/tagging.h +17 -0
  110. data/jieba_rb.gemspec +51 -0
  111. data/lib/jieba-rb.rb +66 -0
  112. data/lib/jieba_rb/version.rb +3 -0
  113. data/test/test_keyword.rb +17 -0
  114. data/test/test_segment.rb +32 -0
  115. data/test/test_tagging.rb +22 -0
  116. data/test/user.dict.utf8 +23 -0
  117. metadata +219 -0
@@ -0,0 +1,39 @@
1
+ // Copyright 2006, Google Inc.
2
+ // All rights reserved.
3
+ //
4
+ // Redistribution and use in source and binary forms, with or without
5
+ // modification, are permitted provided that the following conditions are
6
+ // met:
7
+ //
8
+ // * Redistributions of source code must retain the above copyright
9
+ // notice, this list of conditions and the following disclaimer.
10
+ // * Redistributions in binary form must reproduce the above
11
+ // copyright notice, this list of conditions and the following disclaimer
12
+ // in the documentation and/or other materials provided with the
13
+ // distribution.
14
+ // * Neither the name of Google Inc. nor the names of its
15
+ // contributors may be used to endorse or promote products derived from
16
+ // this software without specific prior written permission.
17
+ //
18
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+
30
+ #include <iostream>
31
+
32
+ #include "gtest/gtest.h"
33
+
34
+ GTEST_API_ int main(int argc, char **argv) {
35
+ std::cout << "Running main() from gtest_main.cc\n";
36
+
37
+ testing::InitGoogleTest(&argc, argv);
38
+ return RUN_ALL_TESTS();
39
+ }
@@ -0,0 +1,70 @@
1
+ /************************************
2
+ * file enc : ascii
3
+ * author : wuyanyi09@gmail.com
4
+ ************************************/
5
+
6
+ #ifndef LIMONP_ARGV_FUNCTS_H
7
+ #define LIMONP_ARGV_FUNCTS_H
8
+
9
+ #include <set>
10
+ #include <sstream>
11
+ #include "StringUtil.hpp"
12
+
13
+ namespace limonp {
14
+
15
+ using namespace std;
16
+
17
+ class ArgvContext {
18
+ public :
19
+ ArgvContext(int argc, const char* const * argv) {
20
+ for(int i = 0; i < argc; i++) {
21
+ if(StartsWith(argv[i], "-")) {
22
+ if(i + 1 < argc && !StartsWith(argv[i + 1], "-")) {
23
+ mpss_[argv[i]] = argv[i+1];
24
+ i++;
25
+ } else {
26
+ sset_.insert(argv[i]);
27
+ }
28
+ } else {
29
+ args_.push_back(argv[i]);
30
+ }
31
+ }
32
+ }
33
+ ~ArgvContext() {
34
+ }
35
+
36
+ friend ostream& operator << (ostream& os, const ArgvContext& args);
37
+ string operator [](size_t i) const {
38
+ if(i < args_.size()) {
39
+ return args_[i];
40
+ }
41
+ return "";
42
+ }
43
+ string operator [](const string& key) const {
44
+ map<string, string>::const_iterator it = mpss_.find(key);
45
+ if(it != mpss_.end()) {
46
+ return it->second;
47
+ }
48
+ return "";
49
+ }
50
+
51
+ bool HasKey(const string& key) const {
52
+ if(mpss_.find(key) != mpss_.end() || sset_.find(key) != sset_.end()) {
53
+ return true;
54
+ }
55
+ return false;
56
+ }
57
+
58
+ private:
59
+ vector<string> args_;
60
+ map<string, string> mpss_;
61
+ set<string> sset_;
62
+ }; // class ArgvContext
63
+
64
+ inline ostream& operator << (ostream& os, const ArgvContext& args) {
65
+ return os<<args.args_<<args.mpss_<<args.sset_;
66
+ }
67
+
68
+ } // namespace limonp
69
+
70
+ #endif
@@ -0,0 +1,49 @@
1
+ #ifndef LIMONP_BLOCKINGQUEUE_HPP
2
+ #define LIMONP_BLOCKINGQUEUE_HPP
3
+
4
+ #include <queue>
5
+ #include "Condition.hpp"
6
+
7
+ namespace limonp {
8
+ template<class T>
9
+ class BlockingQueue: NonCopyable {
10
+ public:
11
+ BlockingQueue()
12
+ : mutex_(), notEmpty_(mutex_), queue_() {
13
+ }
14
+
15
+ void Push(const T& x) {
16
+ MutexLockGuard lock(mutex_);
17
+ queue_.push(x);
18
+ notEmpty_.Notify(); // Wait morphing saves us
19
+ }
20
+
21
+ T Pop() {
22
+ MutexLockGuard lock(mutex_);
23
+ // always use a while-loop, due to spurious wakeup
24
+ while (queue_.empty()) {
25
+ notEmpty_.Wait();
26
+ }
27
+ assert(!queue_.empty());
28
+ T front(queue_.front());
29
+ queue_.pop();
30
+ return front;
31
+ }
32
+
33
+ size_t Size() const {
34
+ MutexLockGuard lock(mutex_);
35
+ return queue_.size();
36
+ }
37
+ bool Empty() const {
38
+ return Size() == 0;
39
+ }
40
+
41
+ private:
42
+ mutable MutexLock mutex_;
43
+ Condition notEmpty_;
44
+ std::queue<T> queue_;
45
+ }; // class BlockingQueue
46
+
47
+ } // namespace limonp
48
+
49
+ #endif // LIMONP_BLOCKINGQUEUE_HPP
@@ -0,0 +1,67 @@
1
+ #ifndef LIMONP_BOUNDED_BLOCKING_QUEUE_HPP
2
+ #define LIMONP_BOUNDED_BLOCKING_QUEUE_HPP
3
+
4
+ #include "BoundedQueue.hpp"
5
+
6
+ namespace limonp {
7
+
8
+ template<typename T>
9
+ class BoundedBlockingQueue : NonCopyable {
10
+ public:
11
+ explicit BoundedBlockingQueue(size_t maxSize)
12
+ : mutex_(),
13
+ notEmpty_(mutex_),
14
+ notFull_(mutex_),
15
+ queue_(maxSize) {
16
+ }
17
+
18
+ void Push(const T& x) {
19
+ MutexLockGuard lock(mutex_);
20
+ while (queue_.Full()) {
21
+ notFull_.Wait();
22
+ }
23
+ assert(!queue_.Full());
24
+ queue_.Push(x);
25
+ notEmpty_.Notify();
26
+ }
27
+
28
+ T Pop() {
29
+ MutexLockGuard lock(mutex_);
30
+ while (queue_.Empty()) {
31
+ notEmpty_.Wait();
32
+ }
33
+ assert(!queue_.Empty());
34
+ T res = queue_.Pop();
35
+ notFull_.Notify();
36
+ return res;
37
+ }
38
+
39
+ bool Empty() const {
40
+ MutexLockGuard lock(mutex_);
41
+ return queue_.Empty();
42
+ }
43
+
44
+ bool Full() const {
45
+ MutexLockGuard lock(mutex_);
46
+ return queue_.Full();
47
+ }
48
+
49
+ size_t size() const {
50
+ MutexLockGuard lock(mutex_);
51
+ return queue_.size();
52
+ }
53
+
54
+ size_t capacity() const {
55
+ return queue_.capacity();
56
+ }
57
+
58
+ private:
59
+ mutable MutexLock mutex_;
60
+ Condition notEmpty_;
61
+ Condition notFull_;
62
+ BoundedQueue<T> queue_;
63
+ }; // class BoundedBlockingQueue
64
+
65
+ } // namespace limonp
66
+
67
+ #endif // LIMONP_BOUNDED_BLOCKING_QUEUE_HPP
@@ -0,0 +1,65 @@
1
+ #ifndef LIMONP_BOUNDED_QUEUE_HPP
2
+ #define LIMONP_BOUNDED_QUEUE_HPP
3
+
4
+ #include <vector>
5
+ #include <fstream>
6
+ #include <cassert>
7
+
8
+ namespace limonp {
9
+ using namespace std;
10
+ template<class T>
11
+ class BoundedQueue {
12
+ public:
13
+ explicit BoundedQueue(size_t capacity): capacity_(capacity), circular_buffer_(capacity) {
14
+ head_ = 0;
15
+ tail_ = 0;
16
+ size_ = 0;
17
+ assert(capacity_);
18
+ }
19
+ ~BoundedQueue() {
20
+ }
21
+
22
+ void Clear() {
23
+ head_ = 0;
24
+ tail_ = 0;
25
+ size_ = 0;
26
+ }
27
+ bool Empty() const {
28
+ return !size_;
29
+ }
30
+ bool Full() const {
31
+ return capacity_ == size_;
32
+ }
33
+ size_t Size() const {
34
+ return size_;
35
+ }
36
+ size_t Capacity() const {
37
+ return capacity_;
38
+ }
39
+
40
+ void Push(const T& t) {
41
+ assert(!Full());
42
+ circular_buffer_[tail_] = t;
43
+ tail_ = (tail_ + 1) % capacity_;
44
+ size_ ++;
45
+ }
46
+
47
+ T Pop() {
48
+ assert(!Empty());
49
+ size_t oldPos = head_;
50
+ head_ = (head_ + 1) % capacity_;
51
+ size_ --;
52
+ return circular_buffer_[oldPos];
53
+ }
54
+
55
+ private:
56
+ size_t head_;
57
+ size_t tail_;
58
+ size_t size_;
59
+ const size_t capacity_;
60
+ vector<T> circular_buffer_;
61
+
62
+ }; // class BoundedQueue
63
+ } // namespace limonp
64
+
65
+ #endif
@@ -0,0 +1,206 @@
1
+ #ifndef LIMONP_CLOSURE_HPP
2
+ #define LIMONP_CLOSURE_HPP
3
+
4
+ namespace limonp {
5
+
6
+ class ClosureInterface {
7
+ public:
8
+ virtual ~ClosureInterface() {
9
+ }
10
+ virtual void Run() = 0;
11
+ };
12
+
13
+ template <class Funct>
14
+ class Closure0: public ClosureInterface {
15
+ public:
16
+ Closure0(Funct fun) {
17
+ fun_ = fun;
18
+ }
19
+ virtual ~Closure0() {
20
+ }
21
+ virtual void Run() {
22
+ (*fun_)();
23
+ }
24
+ private:
25
+ Funct fun_;
26
+ };
27
+
28
+ template <class Funct, class Arg1>
29
+ class Closure1: public ClosureInterface {
30
+ public:
31
+ Closure1(Funct fun, Arg1 arg1) {
32
+ fun_ = fun;
33
+ arg1_ = arg1;
34
+ }
35
+ virtual ~Closure1() {
36
+ }
37
+ virtual void Run() {
38
+ (*fun_)(arg1_);
39
+ }
40
+ private:
41
+ Funct fun_;
42
+ Arg1 arg1_;
43
+ };
44
+
45
+ template <class Funct, class Arg1, class Arg2>
46
+ class Closure2: public ClosureInterface {
47
+ public:
48
+ Closure2(Funct fun, Arg1 arg1, Arg2 arg2) {
49
+ fun_ = fun;
50
+ arg1_ = arg1;
51
+ arg2_ = arg2;
52
+ }
53
+ virtual ~Closure2() {
54
+ }
55
+ virtual void Run() {
56
+ (*fun_)(arg1_, arg2_);
57
+ }
58
+ private:
59
+ Funct fun_;
60
+ Arg1 arg1_;
61
+ Arg2 arg2_;
62
+ };
63
+
64
+ template <class Funct, class Arg1, class Arg2, class Arg3>
65
+ class Closure3: public ClosureInterface {
66
+ public:
67
+ Closure3(Funct fun, Arg1 arg1, Arg2 arg2, Arg3 arg3) {
68
+ fun_ = fun;
69
+ arg1_ = arg1;
70
+ arg2_ = arg2;
71
+ arg3_ = arg3;
72
+ }
73
+ virtual ~Closure3() {
74
+ }
75
+ virtual void Run() {
76
+ (*fun_)(arg1_, arg2_, arg3_);
77
+ }
78
+ private:
79
+ Funct fun_;
80
+ Arg1 arg1_;
81
+ Arg2 arg2_;
82
+ Arg3 arg3_;
83
+ };
84
+
85
+ template <class Obj, class Funct>
86
+ class ObjClosure0: public ClosureInterface {
87
+ public:
88
+ ObjClosure0(Obj* p, Funct fun) {
89
+ p_ = p;
90
+ fun_ = fun;
91
+ }
92
+ virtual ~ObjClosure0() {
93
+ }
94
+ virtual void Run() {
95
+ (p_->*fun_)();
96
+ }
97
+ private:
98
+ Obj* p_;
99
+ Funct fun_;
100
+ };
101
+
102
+ template <class Obj, class Funct, class Arg1>
103
+ class ObjClosure1: public ClosureInterface {
104
+ public:
105
+ ObjClosure1(Obj* p, Funct fun, Arg1 arg1) {
106
+ p_ = p;
107
+ fun_ = fun;
108
+ arg1_ = arg1;
109
+ }
110
+ virtual ~ObjClosure1() {
111
+ }
112
+ virtual void Run() {
113
+ (p_->*fun_)(arg1_);
114
+ }
115
+ private:
116
+ Obj* p_;
117
+ Funct fun_;
118
+ Arg1 arg1_;
119
+ };
120
+
121
+ template <class Obj, class Funct, class Arg1, class Arg2>
122
+ class ObjClosure2: public ClosureInterface {
123
+ public:
124
+ ObjClosure2(Obj* p, Funct fun, Arg1 arg1, Arg2 arg2) {
125
+ p_ = p;
126
+ fun_ = fun;
127
+ arg1_ = arg1;
128
+ arg2_ = arg2;
129
+ }
130
+ virtual ~ObjClosure2() {
131
+ }
132
+ virtual void Run() {
133
+ (p_->*fun_)(arg1_, arg2_);
134
+ }
135
+ private:
136
+ Obj* p_;
137
+ Funct fun_;
138
+ Arg1 arg1_;
139
+ Arg2 arg2_;
140
+ };
141
+ template <class Obj, class Funct, class Arg1, class Arg2, class Arg3>
142
+ class ObjClosure3: public ClosureInterface {
143
+ public:
144
+ ObjClosure3(Obj* p, Funct fun, Arg1 arg1, Arg2 arg2, Arg3 arg3) {
145
+ p_ = p;
146
+ fun_ = fun;
147
+ arg1_ = arg1;
148
+ arg2_ = arg2;
149
+ arg3_ = arg3;
150
+ }
151
+ virtual ~ObjClosure3() {
152
+ }
153
+ virtual void Run() {
154
+ (p_->*fun_)(arg1_, arg2_, arg3_);
155
+ }
156
+ private:
157
+ Obj* p_;
158
+ Funct fun_;
159
+ Arg1 arg1_;
160
+ Arg2 arg2_;
161
+ Arg3 arg3_;
162
+ };
163
+
164
+ template<class R>
165
+ ClosureInterface* NewClosure(R (*fun)()) {
166
+ return new Closure0<R (*)()>(fun);
167
+ }
168
+
169
+ template<class R, class Arg1>
170
+ ClosureInterface* NewClosure(R (*fun)(Arg1), Arg1 arg1) {
171
+ return new Closure1<R (*)(Arg1), Arg1>(fun, arg1);
172
+ }
173
+
174
+ template<class R, class Arg1, class Arg2>
175
+ ClosureInterface* NewClosure(R (*fun)(Arg1, Arg2), Arg1 arg1, Arg2 arg2) {
176
+ return new Closure2<R (*)(Arg1, Arg2), Arg1, Arg2>(fun, arg1, arg2);
177
+ }
178
+
179
+ template<class R, class Arg1, class Arg2, class Arg3>
180
+ ClosureInterface* NewClosure(R (*fun)(Arg1, Arg2, Arg3), Arg1 arg1, Arg2 arg2, Arg3 arg3) {
181
+ return new Closure3<R (*)(Arg1, Arg2, Arg3), Arg1, Arg2, Arg3>(fun, arg1, arg2, arg3);
182
+ }
183
+
184
+ template<class R, class Obj>
185
+ ClosureInterface* NewClosure(Obj* obj, R (Obj::* fun)()) {
186
+ return new ObjClosure0<Obj, R (Obj::* )()>(obj, fun);
187
+ }
188
+
189
+ template<class R, class Obj, class Arg1>
190
+ ClosureInterface* NewClosure(Obj* obj, R (Obj::* fun)(Arg1), Arg1 arg1) {
191
+ return new ObjClosure1<Obj, R (Obj::* )(Arg1), Arg1>(obj, fun, arg1);
192
+ }
193
+
194
+ template<class R, class Obj, class Arg1, class Arg2>
195
+ ClosureInterface* NewClosure(Obj* obj, R (Obj::* fun)(Arg1, Arg2), Arg1 arg1, Arg2 arg2) {
196
+ return new ObjClosure2<Obj, R (Obj::*)(Arg1, Arg2), Arg1, Arg2>(obj, fun, arg1, arg2);
197
+ }
198
+
199
+ template<class R, class Obj, class Arg1, class Arg2, class Arg3>
200
+ ClosureInterface* NewClosure(Obj* obj, R (Obj::* fun)(Arg1, Arg2, Arg3), Arg1 arg1, Arg2 arg2, Arg3 arg3) {
201
+ return new ObjClosure3<Obj, R (Obj::*)(Arg1, Arg2, Arg3), Arg1, Arg2, Arg3>(obj, fun, arg1, arg2, arg3);
202
+ }
203
+
204
+ } // namespace limonp
205
+
206
+ #endif // LIMONP_CLOSURE_HPP