nodejieba-plus 3.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/FUNDING.yml +12 -0
- package/.github/workflows/github_release.yml +61 -0
- package/.github/workflows/npm_publish.yml +24 -0
- package/.github/workflows/stale-issues.yml +24 -0
- package/.github/workflows/test.yml +42 -0
- package/.gitmodules +3 -0
- package/.npmignore +15 -0
- package/CHANGELOG.md +360 -0
- package/CONTRIBUTING.md +78 -0
- package/LICENSE +21 -0
- package/README.md +349 -0
- package/binding.gyp +63 -0
- package/index.js +77 -0
- package/lib/index.cpp +3 -0
- package/lib/nodejieba.cpp +218 -0
- package/lib/nodejieba.h +28 -0
- package/lib/utils.h +47 -0
- package/package.json +48 -0
- package/submodules/cppjieba/.github/workflows/cmake.yml +51 -0
- package/submodules/cppjieba/.github/workflows/stale-issues.yml +24 -0
- package/submodules/cppjieba/.gitmodules +3 -0
- package/submodules/cppjieba/CHANGELOG.md +305 -0
- package/submodules/cppjieba/CMakeLists.txt +42 -0
- package/submodules/cppjieba/LICENSE +20 -0
- package/submodules/cppjieba/README.md +280 -0
- package/submodules/cppjieba/deps/limonp/.github/workflows/cmake.yml +43 -0
- package/submodules/cppjieba/deps/limonp/.gitmodules +0 -0
- package/submodules/cppjieba/deps/limonp/CHANGELOG.md +160 -0
- package/submodules/cppjieba/deps/limonp/CMakeLists.txt +61 -0
- package/submodules/cppjieba/deps/limonp/LICENSE +20 -0
- package/submodules/cppjieba/deps/limonp/README.md +38 -0
- package/submodules/cppjieba/deps/limonp/include/limonp/ArgvContext.hpp +70 -0
- package/submodules/cppjieba/deps/limonp/include/limonp/Closure.hpp +206 -0
- package/submodules/cppjieba/deps/limonp/include/limonp/Colors.hpp +31 -0
- package/submodules/cppjieba/deps/limonp/include/limonp/Condition.hpp +38 -0
- package/submodules/cppjieba/deps/limonp/include/limonp/Config.hpp +103 -0
- package/submodules/cppjieba/deps/limonp/include/limonp/ForcePublic.hpp +7 -0
- package/submodules/cppjieba/deps/limonp/include/limonp/LocalVector.hpp +139 -0
- package/submodules/cppjieba/deps/limonp/include/limonp/Logging.hpp +90 -0
- package/submodules/cppjieba/deps/limonp/include/limonp/NonCopyable.hpp +21 -0
- package/submodules/cppjieba/deps/limonp/include/limonp/StdExtension.hpp +157 -0
- package/submodules/cppjieba/deps/limonp/include/limonp/StringUtil.hpp +386 -0
- package/submodules/cppjieba/deps/limonp/test/CMakeLists.txt +8 -0
- package/submodules/cppjieba/deps/limonp/test/demo.cpp +40 -0
- package/submodules/cppjieba/deps/limonp/test/testdata/1.conf +5 -0
- package/submodules/cppjieba/deps/limonp/test/testdata/StdExtension.data +3 -0
- package/submodules/cppjieba/deps/limonp/test/testdata/dict.gbk +50 -0
- package/submodules/cppjieba/deps/limonp/test/testdata/dict.utf8 +50 -0
- package/submodules/cppjieba/deps/limonp/test/testdata/io_testfile +2 -0
- package/submodules/cppjieba/deps/limonp/test/testdata/jieba.dict.0.1.utf8 +93 -0
- package/submodules/cppjieba/deps/limonp/test/testdata/jieba.dict.0.utf8 +93 -0
- package/submodules/cppjieba/deps/limonp/test/testdata/jieba.dict.1.utf8 +67 -0
- package/submodules/cppjieba/deps/limonp/test/testdata/jieba.dict.2.utf8 +64 -0
- package/submodules/cppjieba/deps/limonp/test/unittest/CMakeLists.txt +30 -0
- package/submodules/cppjieba/deps/limonp/test/unittest/TArgvContext.cpp +16 -0
- package/submodules/cppjieba/deps/limonp/test/unittest/TCastFloat.cpp +19 -0
- package/submodules/cppjieba/deps/limonp/test/unittest/TClosure.cpp +85 -0
- package/submodules/cppjieba/deps/limonp/test/unittest/TColorPrint.cpp +20 -0
- package/submodules/cppjieba/deps/limonp/test/unittest/TConfig.cpp +17 -0
- package/submodules/cppjieba/deps/limonp/test/unittest/TLocalVector.cpp +41 -0
- package/submodules/cppjieba/deps/limonp/test/unittest/TLogging.cpp +12 -0
- package/submodules/cppjieba/deps/limonp/test/unittest/TStdExtension.cpp +95 -0
- package/submodules/cppjieba/deps/limonp/test/unittest/TStringUtil.cpp +183 -0
- package/submodules/cppjieba/deps/limonp/test/unittest/gtest_main.cpp +39 -0
- package/submodules/cppjieba/dict/README.md +31 -0
- package/submodules/cppjieba/dict/hmm_model.utf8 +34 -0
- package/submodules/cppjieba/dict/idf.utf8 +258826 -0
- package/submodules/cppjieba/dict/jieba.dict.utf8 +348982 -0
- package/submodules/cppjieba/dict/pos_dict/char_state_tab.utf8 +6653 -0
- package/submodules/cppjieba/dict/pos_dict/prob_emit.utf8 +166 -0
- package/submodules/cppjieba/dict/pos_dict/prob_start.utf8 +259 -0
- package/submodules/cppjieba/dict/pos_dict/prob_trans.utf8 +5222 -0
- package/submodules/cppjieba/dict/stop_words.utf8 +1534 -0
- package/submodules/cppjieba/dict/user.dict.utf8 +4 -0
- package/submodules/cppjieba/include/cppjieba/DictTrie.hpp +381 -0
- package/submodules/cppjieba/include/cppjieba/FullSegment.hpp +93 -0
- package/submodules/cppjieba/include/cppjieba/HMMModel.hpp +129 -0
- package/submodules/cppjieba/include/cppjieba/HMMSegment.hpp +190 -0
- package/submodules/cppjieba/include/cppjieba/Jieba.hpp +169 -0
- package/submodules/cppjieba/include/cppjieba/KeywordExtractor.hpp +153 -0
- package/submodules/cppjieba/include/cppjieba/MPSegment.hpp +137 -0
- package/submodules/cppjieba/include/cppjieba/MixSegment.hpp +109 -0
- package/submodules/cppjieba/include/cppjieba/PosTagger.hpp +77 -0
- package/submodules/cppjieba/include/cppjieba/PreFilter.hpp +54 -0
- package/submodules/cppjieba/include/cppjieba/QuerySegment.hpp +89 -0
- package/submodules/cppjieba/include/cppjieba/SegmentBase.hpp +48 -0
- package/submodules/cppjieba/include/cppjieba/SegmentTagged.hpp +23 -0
- package/submodules/cppjieba/include/cppjieba/TextRankExtractor.hpp +190 -0
- package/submodules/cppjieba/include/cppjieba/Trie.hpp +200 -0
- package/submodules/cppjieba/include/cppjieba/Unicode.hpp +231 -0
- package/submodules/cppjieba/test/CMakeLists.txt +4 -0
- package/submodules/cppjieba/test/load_test.cpp +54 -0
- package/submodules/cppjieba/test/testdata/curl.res +1 -0
- package/submodules/cppjieba/test/testdata/extra_dict/jieba.dict.small.utf8 +109750 -0
- package/submodules/cppjieba/test/testdata/gbk_dict/hmm_model.gbk +34 -0
- package/submodules/cppjieba/test/testdata/gbk_dict/jieba.dict.gbk +348982 -0
- package/submodules/cppjieba/test/testdata/jieba.dict.0.1.utf8 +93 -0
- package/submodules/cppjieba/test/testdata/jieba.dict.0.utf8 +93 -0
- package/submodules/cppjieba/test/testdata/jieba.dict.1.utf8 +67 -0
- package/submodules/cppjieba/test/testdata/jieba.dict.2.utf8 +64 -0
- package/submodules/cppjieba/test/testdata/load_test.urls +2 -0
- package/submodules/cppjieba/test/testdata/review.100 +100 -0
- package/submodules/cppjieba/test/testdata/review.100.res +200 -0
- package/submodules/cppjieba/test/testdata/server.conf +19 -0
- package/submodules/cppjieba/test/testdata/testlines.gbk +9 -0
- package/submodules/cppjieba/test/testdata/testlines.utf8 +8 -0
- package/submodules/cppjieba/test/testdata/userdict.2.utf8 +1 -0
- package/submodules/cppjieba/test/testdata/userdict.english +2 -0
- package/submodules/cppjieba/test/testdata/userdict.utf8 +8 -0
- package/submodules/cppjieba/test/testdata/weicheng.utf8 +247 -0
- package/submodules/cppjieba/test/unittest/CMakeLists.txt +33 -0
- package/submodules/cppjieba/test/unittest/gtest_main.cpp +39 -0
- package/submodules/cppjieba/test/unittest/jieba_test.cpp +166 -0
- package/submodules/cppjieba/test/unittest/keyword_extractor_test.cpp +79 -0
- package/submodules/cppjieba/test/unittest/pos_tagger_test.cpp +41 -0
- package/submodules/cppjieba/test/unittest/pre_filter_test.cpp +43 -0
- package/submodules/cppjieba/test/unittest/segments_test.cpp +256 -0
- package/submodules/cppjieba/test/unittest/textrank_test.cpp +86 -0
- package/submodules/cppjieba/test/unittest/trie_test.cpp +177 -0
- package/submodules/cppjieba/test/unittest/unicode_test.cpp +43 -0
- package/test/debug_split +0 -0
- package/test/debug_split2 +0 -0
- package/test/debug_split3 +0 -0
- package/test/load_dict_test.js +14 -0
- package/test/missing_binding_test.js +42 -0
- package/test/test.js +366 -0
- package/test/testdata/userdict.utf8 +1 -0
- package/tsconfig.json +59 -0
- package/types/index.d.ts +30 -0
- package/typescript_demo.ts +38 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/************************************
|
|
2
|
+
* file enc : utf8
|
|
3
|
+
* author : wuyanyi09@gmail.com
|
|
4
|
+
************************************/
|
|
5
|
+
#ifndef LIMONP_CONFIG_H
|
|
6
|
+
#define LIMONP_CONFIG_H
|
|
7
|
+
|
|
8
|
+
#include <map>
|
|
9
|
+
#include <fstream>
|
|
10
|
+
#include <iostream>
|
|
11
|
+
#include <assert.h>
|
|
12
|
+
#include "StringUtil.hpp"
|
|
13
|
+
|
|
14
|
+
namespace limonp {
|
|
15
|
+
|
|
16
|
+
using namespace std;
|
|
17
|
+
|
|
18
|
+
class Config {
|
|
19
|
+
public:
|
|
20
|
+
explicit Config(const string& filePath) {
|
|
21
|
+
LoadFile(filePath);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
operator bool () {
|
|
25
|
+
return !map_.empty();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
string Get(const string& key, const string& defaultvalue) const {
|
|
29
|
+
map<string, string>::const_iterator it = map_.find(key);
|
|
30
|
+
if(map_.end() != it) {
|
|
31
|
+
return it->second;
|
|
32
|
+
}
|
|
33
|
+
return defaultvalue;
|
|
34
|
+
}
|
|
35
|
+
int Get(const string& key, int defaultvalue) const {
|
|
36
|
+
string str = Get(key, "");
|
|
37
|
+
if("" == str) {
|
|
38
|
+
return defaultvalue;
|
|
39
|
+
}
|
|
40
|
+
return atoi(str.c_str());
|
|
41
|
+
}
|
|
42
|
+
const char* operator [] (const char* key) const {
|
|
43
|
+
if(NULL == key) {
|
|
44
|
+
return NULL;
|
|
45
|
+
}
|
|
46
|
+
map<string, string>::const_iterator it = map_.find(key);
|
|
47
|
+
if(map_.end() != it) {
|
|
48
|
+
return it->second.c_str();
|
|
49
|
+
}
|
|
50
|
+
return NULL;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
string GetConfigInfo() const {
|
|
54
|
+
string res;
|
|
55
|
+
res << *this;
|
|
56
|
+
return res;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private:
|
|
60
|
+
void LoadFile(const string& filePath) {
|
|
61
|
+
ifstream ifs(filePath.c_str());
|
|
62
|
+
assert(ifs);
|
|
63
|
+
string line;
|
|
64
|
+
vector<string> vecBuf;
|
|
65
|
+
size_t lineno = 0;
|
|
66
|
+
while(getline(ifs, line)) {
|
|
67
|
+
lineno ++;
|
|
68
|
+
Trim(line);
|
|
69
|
+
if(line.empty() || StartsWith(line, "#")) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
vecBuf.clear();
|
|
73
|
+
Split(line, vecBuf, "=");
|
|
74
|
+
if(2 != vecBuf.size()) {
|
|
75
|
+
fprintf(stderr, "line[%s] illegal.\n", line.c_str());
|
|
76
|
+
assert(false);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
string& key = vecBuf[0];
|
|
80
|
+
string& value = vecBuf[1];
|
|
81
|
+
Trim(key);
|
|
82
|
+
Trim(value);
|
|
83
|
+
if(!map_.insert(make_pair(key, value)).second) {
|
|
84
|
+
fprintf(stderr, "key[%s] already exits.\n", key.c_str());
|
|
85
|
+
assert(false);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
ifs.close();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
friend ostream& operator << (ostream& os, const Config& config);
|
|
93
|
+
|
|
94
|
+
map<string, string> map_;
|
|
95
|
+
}; // class Config
|
|
96
|
+
|
|
97
|
+
inline ostream& operator << (ostream& os, const Config& config) {
|
|
98
|
+
return os << config.map_;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
} // namespace limonp
|
|
102
|
+
|
|
103
|
+
#endif // LIMONP_CONFIG_H
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
#ifndef LIMONP_LOCAL_VECTOR_HPP
|
|
2
|
+
#define LIMONP_LOCAL_VECTOR_HPP
|
|
3
|
+
|
|
4
|
+
#include <iostream>
|
|
5
|
+
#include <stdlib.h>
|
|
6
|
+
#include <assert.h>
|
|
7
|
+
#include <string.h>
|
|
8
|
+
|
|
9
|
+
namespace limonp {
|
|
10
|
+
using namespace std;
|
|
11
|
+
/*
|
|
12
|
+
* LocalVector<T> : T must be primitive type (char , int, size_t), if T is struct or class, LocalVector<T> may be dangerous..
|
|
13
|
+
* LocalVector<T> is simple and not well-tested.
|
|
14
|
+
*/
|
|
15
|
+
const size_t LOCAL_VECTOR_BUFFER_SIZE = 16;
|
|
16
|
+
template <class T>
|
|
17
|
+
class LocalVector {
|
|
18
|
+
public:
|
|
19
|
+
typedef const T* const_iterator ;
|
|
20
|
+
typedef T value_type;
|
|
21
|
+
typedef size_t size_type;
|
|
22
|
+
private:
|
|
23
|
+
T buffer_[LOCAL_VECTOR_BUFFER_SIZE];
|
|
24
|
+
T * ptr_;
|
|
25
|
+
size_t size_;
|
|
26
|
+
size_t capacity_;
|
|
27
|
+
public:
|
|
28
|
+
LocalVector() {
|
|
29
|
+
init_();
|
|
30
|
+
};
|
|
31
|
+
LocalVector(const LocalVector<T>& vec) {
|
|
32
|
+
init_();
|
|
33
|
+
*this = vec;
|
|
34
|
+
}
|
|
35
|
+
LocalVector(const_iterator begin, const_iterator end) { // TODO: make it faster
|
|
36
|
+
init_();
|
|
37
|
+
while(begin != end) {
|
|
38
|
+
push_back(*begin++);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
LocalVector(size_t size, const T& t) { // TODO: make it faster
|
|
42
|
+
init_();
|
|
43
|
+
while(size--) {
|
|
44
|
+
push_back(t);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
~LocalVector() {
|
|
48
|
+
if(ptr_ != buffer_) {
|
|
49
|
+
free(ptr_);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
public:
|
|
53
|
+
LocalVector<T>& operator = (const LocalVector<T>& vec) {
|
|
54
|
+
clear();
|
|
55
|
+
size_ = vec.size();
|
|
56
|
+
capacity_ = vec.capacity();
|
|
57
|
+
if(vec.buffer_ == vec.ptr_) {
|
|
58
|
+
memcpy(static_cast<void*>(buffer_), vec.buffer_, sizeof(T) * size_);
|
|
59
|
+
ptr_ = buffer_;
|
|
60
|
+
} else {
|
|
61
|
+
ptr_ = (T*) malloc(vec.capacity() * sizeof(T));
|
|
62
|
+
assert(ptr_);
|
|
63
|
+
memcpy(static_cast<void*>(ptr_), vec.ptr_, vec.size() * sizeof(T));
|
|
64
|
+
}
|
|
65
|
+
return *this;
|
|
66
|
+
}
|
|
67
|
+
private:
|
|
68
|
+
void init_() {
|
|
69
|
+
ptr_ = buffer_;
|
|
70
|
+
size_ = 0;
|
|
71
|
+
capacity_ = LOCAL_VECTOR_BUFFER_SIZE;
|
|
72
|
+
}
|
|
73
|
+
public:
|
|
74
|
+
T& operator [] (size_t i) {
|
|
75
|
+
return ptr_[i];
|
|
76
|
+
}
|
|
77
|
+
const T& operator [] (size_t i) const {
|
|
78
|
+
return ptr_[i];
|
|
79
|
+
}
|
|
80
|
+
void push_back(const T& t) {
|
|
81
|
+
if(size_ == capacity_) {
|
|
82
|
+
assert(capacity_);
|
|
83
|
+
reserve(capacity_ * 2);
|
|
84
|
+
}
|
|
85
|
+
ptr_[size_ ++ ] = t;
|
|
86
|
+
}
|
|
87
|
+
void reserve(size_t size) {
|
|
88
|
+
if(size <= capacity_) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
T * next = (T*)malloc(sizeof(T) * size);
|
|
92
|
+
assert(next);
|
|
93
|
+
T * old = ptr_;
|
|
94
|
+
ptr_ = next;
|
|
95
|
+
memcpy(static_cast<void*>(ptr_), old, sizeof(T) * capacity_);
|
|
96
|
+
capacity_ = size;
|
|
97
|
+
if(old != buffer_) {
|
|
98
|
+
free(old);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
bool empty() const {
|
|
102
|
+
return 0 == size();
|
|
103
|
+
}
|
|
104
|
+
size_t size() const {
|
|
105
|
+
return size_;
|
|
106
|
+
}
|
|
107
|
+
size_t capacity() const {
|
|
108
|
+
return capacity_;
|
|
109
|
+
}
|
|
110
|
+
const_iterator begin() const {
|
|
111
|
+
return ptr_;
|
|
112
|
+
}
|
|
113
|
+
const_iterator end() const {
|
|
114
|
+
return ptr_ + size_;
|
|
115
|
+
}
|
|
116
|
+
void clear() {
|
|
117
|
+
if(ptr_ != buffer_) {
|
|
118
|
+
free(ptr_);
|
|
119
|
+
}
|
|
120
|
+
init_();
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
template <class T>
|
|
125
|
+
ostream & operator << (ostream& os, const LocalVector<T>& vec) {
|
|
126
|
+
if(vec.empty()) {
|
|
127
|
+
return os << "[]";
|
|
128
|
+
}
|
|
129
|
+
os<<"[\""<<vec[0];
|
|
130
|
+
for(size_t i = 1; i < vec.size(); i++) {
|
|
131
|
+
os<<"\", \""<<vec[i];
|
|
132
|
+
}
|
|
133
|
+
os<<"\"]";
|
|
134
|
+
return os;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
#endif
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#ifndef LIMONP_LOGGING_HPP
|
|
2
|
+
#define LIMONP_LOGGING_HPP
|
|
3
|
+
|
|
4
|
+
#include <sstream>
|
|
5
|
+
#include <iostream>
|
|
6
|
+
#include <cassert>
|
|
7
|
+
#include <cstdlib>
|
|
8
|
+
#include <ctime>
|
|
9
|
+
|
|
10
|
+
#ifdef XLOG
|
|
11
|
+
#error "XLOG has been defined already"
|
|
12
|
+
#endif // XLOG
|
|
13
|
+
#ifdef XCHECK
|
|
14
|
+
#error "XCHECK has been defined already"
|
|
15
|
+
#endif // XCHECK
|
|
16
|
+
|
|
17
|
+
#define XLOG(level) limonp::Logger(limonp::LL_##level, __FILE__, __LINE__).Stream()
|
|
18
|
+
#define XCHECK(exp) if(!(exp)) XLOG(FATAL) << "exp: ["#exp << "] false. "
|
|
19
|
+
|
|
20
|
+
namespace limonp {
|
|
21
|
+
|
|
22
|
+
enum {
|
|
23
|
+
LL_DEBUG = 0,
|
|
24
|
+
LL_INFO = 1,
|
|
25
|
+
LL_WARNING = 2,
|
|
26
|
+
LL_ERROR = 3,
|
|
27
|
+
LL_FATAL = 4,
|
|
28
|
+
}; // enum
|
|
29
|
+
|
|
30
|
+
static const char * LOG_LEVEL_ARRAY[] = {"DEBUG","INFO","WARN","ERROR","FATAL"};
|
|
31
|
+
static const char * LOG_TIME_FORMAT = "%Y-%m-%d %H:%M:%S";
|
|
32
|
+
|
|
33
|
+
class Logger {
|
|
34
|
+
public:
|
|
35
|
+
Logger(size_t level, const char* filename, int lineno)
|
|
36
|
+
: level_(level) {
|
|
37
|
+
#ifdef LOGGING_LEVEL
|
|
38
|
+
if (level_ < LOGGING_LEVEL) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
#endif
|
|
42
|
+
assert(level_ <= sizeof(LOG_LEVEL_ARRAY)/sizeof(*LOG_LEVEL_ARRAY));
|
|
43
|
+
|
|
44
|
+
char buf[32];
|
|
45
|
+
|
|
46
|
+
time_t timeNow;
|
|
47
|
+
time(&timeNow);
|
|
48
|
+
|
|
49
|
+
struct tm tmNow;
|
|
50
|
+
|
|
51
|
+
#if defined(_WIN32) || defined(_WIN64)
|
|
52
|
+
errno_t e = localtime_s(&tmNow, &timeNow);
|
|
53
|
+
assert(e == 0);
|
|
54
|
+
#else
|
|
55
|
+
struct tm * tm_tmp = localtime_r(&timeNow, &tmNow);
|
|
56
|
+
assert(tm_tmp != nullptr);
|
|
57
|
+
#endif
|
|
58
|
+
|
|
59
|
+
strftime(buf, sizeof(buf), LOG_TIME_FORMAT, &tmNow);
|
|
60
|
+
|
|
61
|
+
stream_ << buf
|
|
62
|
+
<< " " << filename
|
|
63
|
+
<< ":" << lineno
|
|
64
|
+
<< " " << LOG_LEVEL_ARRAY[level_]
|
|
65
|
+
<< " ";
|
|
66
|
+
}
|
|
67
|
+
~Logger() {
|
|
68
|
+
#ifdef LOGGING_LEVEL
|
|
69
|
+
if (level_ < LOGGING_LEVEL) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
#endif
|
|
73
|
+
std::cerr << stream_.str() << std::endl;
|
|
74
|
+
if (level_ == LL_FATAL) {
|
|
75
|
+
abort();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
std::ostream& Stream() {
|
|
80
|
+
return stream_;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private:
|
|
84
|
+
std::ostringstream stream_;
|
|
85
|
+
size_t level_;
|
|
86
|
+
}; // class Logger
|
|
87
|
+
|
|
88
|
+
} // namespace limonp
|
|
89
|
+
|
|
90
|
+
#endif // LIMONP_LOGGING_HPP
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/************************************
|
|
2
|
+
************************************/
|
|
3
|
+
#ifndef LIMONP_NONCOPYABLE_H
|
|
4
|
+
#define LIMONP_NONCOPYABLE_H
|
|
5
|
+
|
|
6
|
+
namespace limonp {
|
|
7
|
+
|
|
8
|
+
class NonCopyable {
|
|
9
|
+
protected:
|
|
10
|
+
NonCopyable() {
|
|
11
|
+
}
|
|
12
|
+
~NonCopyable() {
|
|
13
|
+
}
|
|
14
|
+
private:
|
|
15
|
+
NonCopyable(const NonCopyable& );
|
|
16
|
+
const NonCopyable& operator=(const NonCopyable& );
|
|
17
|
+
}; // class NonCopyable
|
|
18
|
+
|
|
19
|
+
} // namespace limonp
|
|
20
|
+
|
|
21
|
+
#endif // LIMONP_NONCOPYABLE_H
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
#ifndef LIMONP_STD_EXTEMSION_HPP
|
|
2
|
+
#define LIMONP_STD_EXTEMSION_HPP
|
|
3
|
+
|
|
4
|
+
#include <map>
|
|
5
|
+
|
|
6
|
+
#ifdef __APPLE__
|
|
7
|
+
#include <unordered_map>
|
|
8
|
+
#include <unordered_set>
|
|
9
|
+
#elif(__cplusplus >= 201103L)
|
|
10
|
+
#include <unordered_map>
|
|
11
|
+
#include <unordered_set>
|
|
12
|
+
#elif defined _MSC_VER
|
|
13
|
+
#include <unordered_map>
|
|
14
|
+
#include <unordered_set>
|
|
15
|
+
#else
|
|
16
|
+
#include <tr1/unordered_map>
|
|
17
|
+
#include <tr1/unordered_set>
|
|
18
|
+
namespace std {
|
|
19
|
+
using std::tr1::unordered_map;
|
|
20
|
+
using std::tr1::unordered_set;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
#endif
|
|
24
|
+
|
|
25
|
+
#include <set>
|
|
26
|
+
#include <string>
|
|
27
|
+
#include <vector>
|
|
28
|
+
#include <deque>
|
|
29
|
+
#include <fstream>
|
|
30
|
+
#include <sstream>
|
|
31
|
+
|
|
32
|
+
namespace std {
|
|
33
|
+
|
|
34
|
+
template<typename T>
|
|
35
|
+
ostream& operator << (ostream& os, const vector<T>& v) {
|
|
36
|
+
if(v.empty()) {
|
|
37
|
+
return os << "[]";
|
|
38
|
+
}
|
|
39
|
+
os<<"["<<v[0];
|
|
40
|
+
for(size_t i = 1; i < v.size(); i++) {
|
|
41
|
+
os<<", "<<v[i];
|
|
42
|
+
}
|
|
43
|
+
os<<"]";
|
|
44
|
+
return os;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
template<>
|
|
48
|
+
inline ostream& operator << (ostream& os, const vector<string>& v) {
|
|
49
|
+
if(v.empty()) {
|
|
50
|
+
return os << "[]";
|
|
51
|
+
}
|
|
52
|
+
os<<"[\""<<v[0];
|
|
53
|
+
for(size_t i = 1; i < v.size(); i++) {
|
|
54
|
+
os<<"\", \""<<v[i];
|
|
55
|
+
}
|
|
56
|
+
os<<"\"]";
|
|
57
|
+
return os;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
template<typename T>
|
|
61
|
+
ostream& operator << (ostream& os, const deque<T>& dq) {
|
|
62
|
+
if(dq.empty()) {
|
|
63
|
+
return os << "[]";
|
|
64
|
+
}
|
|
65
|
+
os<<"[\""<<dq[0];
|
|
66
|
+
for(size_t i = 1; i < dq.size(); i++) {
|
|
67
|
+
os<<"\", \""<<dq[i];
|
|
68
|
+
}
|
|
69
|
+
os<<"\"]";
|
|
70
|
+
return os;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
template<class T1, class T2>
|
|
75
|
+
ostream& operator << (ostream& os, const pair<T1, T2>& pr) {
|
|
76
|
+
os << pr.first << ":" << pr.second ;
|
|
77
|
+
return os;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
template<class T>
|
|
82
|
+
string& operator << (string& str, const T& obj) {
|
|
83
|
+
stringstream ss;
|
|
84
|
+
ss << obj; // call ostream& operator << (ostream& os,
|
|
85
|
+
return str = ss.str();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
template<class T1, class T2>
|
|
89
|
+
ostream& operator << (ostream& os, const map<T1, T2>& mp) {
|
|
90
|
+
if(mp.empty()) {
|
|
91
|
+
os<<"{}";
|
|
92
|
+
return os;
|
|
93
|
+
}
|
|
94
|
+
os<<'{';
|
|
95
|
+
typename map<T1, T2>::const_iterator it = mp.begin();
|
|
96
|
+
os<<*it;
|
|
97
|
+
it++;
|
|
98
|
+
while(it != mp.end()) {
|
|
99
|
+
os<<", "<<*it;
|
|
100
|
+
it++;
|
|
101
|
+
}
|
|
102
|
+
os<<'}';
|
|
103
|
+
return os;
|
|
104
|
+
}
|
|
105
|
+
template<class T1, class T2>
|
|
106
|
+
ostream& operator << (ostream& os, const std::unordered_map<T1, T2>& mp) {
|
|
107
|
+
if(mp.empty()) {
|
|
108
|
+
return os << "{}";
|
|
109
|
+
}
|
|
110
|
+
os<<'{';
|
|
111
|
+
typename std::unordered_map<T1, T2>::const_iterator it = mp.begin();
|
|
112
|
+
os<<*it;
|
|
113
|
+
it++;
|
|
114
|
+
while(it != mp.end()) {
|
|
115
|
+
os<<", "<<*it++;
|
|
116
|
+
}
|
|
117
|
+
return os<<'}';
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
template<class T>
|
|
121
|
+
ostream& operator << (ostream& os, const set<T>& st) {
|
|
122
|
+
if(st.empty()) {
|
|
123
|
+
os << "{}";
|
|
124
|
+
return os;
|
|
125
|
+
}
|
|
126
|
+
os<<'{';
|
|
127
|
+
typename set<T>::const_iterator it = st.begin();
|
|
128
|
+
os<<*it;
|
|
129
|
+
it++;
|
|
130
|
+
while(it != st.end()) {
|
|
131
|
+
os<<", "<<*it;
|
|
132
|
+
it++;
|
|
133
|
+
}
|
|
134
|
+
os<<'}';
|
|
135
|
+
return os;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
template<class KeyType, class ContainType>
|
|
139
|
+
bool IsIn(const ContainType& contain, const KeyType& key) {
|
|
140
|
+
return contain.end() != contain.find(key);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
template<class T>
|
|
144
|
+
basic_string<T> & operator << (basic_string<T> & s, ifstream & ifs) {
|
|
145
|
+
return s.assign((istreambuf_iterator<T>(ifs)), istreambuf_iterator<T>());
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
template<class T>
|
|
149
|
+
ofstream & operator << (ofstream & ofs, const basic_string<T>& s) {
|
|
150
|
+
ostreambuf_iterator<T> itr (ofs);
|
|
151
|
+
copy(s.begin(), s.end(), itr);
|
|
152
|
+
return ofs;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
} // namespace std
|
|
156
|
+
|
|
157
|
+
#endif
|