diff --git a/src/Husky/CMakeLists.txt b/src/Husky/CMakeLists.txt index a27ad9b..6353e4b 100644 --- a/src/Husky/CMakeLists.txt +++ b/src/Husky/CMakeLists.txt @@ -7,4 +7,3 @@ ADD_LIBRARY(husky STATIC ${LIBHUSKY_SRC}) INSTALL(TARGETS husky ARCHIVE DESTINATION lib/CppJieba/Husky) INSTALL(FILES Daemon.h globals.h HttpReqInfo.hpp ServerFrame.h ThreadManager.hpp DESTINATION include/CppJieba/Husky) -ADD_SUBDIRECTORY(Limonp) diff --git a/src/Husky/Daemon.h b/src/Husky/Daemon.h index e1402b8..61506a5 100644 --- a/src/Husky/Daemon.h +++ b/src/Husky/Daemon.h @@ -8,7 +8,7 @@ #include #include #include -#include "Limonp/logger.hpp" +#include "../Limonp/logger.hpp" #include "ServerFrame.h" namespace Husky diff --git a/src/Husky/HttpReqInfo.hpp b/src/Husky/HttpReqInfo.hpp index a664f5f..9b735a2 100644 --- a/src/Husky/HttpReqInfo.hpp +++ b/src/Husky/HttpReqInfo.hpp @@ -3,8 +3,8 @@ #include #include -#include "Limonp/logger.hpp" -#include "Limonp/str_functs.hpp" +#include "../Limonp/logger.hpp" +#include "../Limonp/str_functs.hpp" #include "globals.h" namespace Husky diff --git a/src/Husky/Limonp/ArgvContext.hpp b/src/Husky/Limonp/ArgvContext.hpp deleted file mode 100644 index 8be15f1..0000000 --- a/src/Husky/Limonp/ArgvContext.hpp +++ /dev/null @@ -1,90 +0,0 @@ -/************************************ - * file enc : ascii - * author : wuyanyi09@gmail.com - ************************************/ - -#ifndef LIMONP_ARGV_FUNCTS_H -#define LIMONP_ARGV_FUNCTS_H - -#include -#include -#include "str_functs.hpp" -#include "map_functs.hpp" - -namespace Limonp -{ - using namespace std; - class ArgvContext - { - public : - ArgvContext(int argc, const char* const * argv) - { - - for(int i = 0; i < argc; i++) - { - if(strStartsWith(argv[i], "-")) - { - if(i + 1 < argc && !strStartsWith(argv[i + 1], "-")) - { - _mpss[argv[i]] = argv[i+1]; - i++; - } - else - { - _sset.insert(argv[i]); - } - } - else - { - _args.push_back(argv[i]); - } - } - } - ~ArgvContext(){}; - public: - friend ostream& operator << (ostream& os, const ArgvContext& args); - string operator [](uint i) - { - if(i < _args.size()) - { - return _args[i]; - } - return ""; - } - string operator [](const string& key) - { - map::const_iterator it = _mpss.find(key); - if(it != _mpss.end()) - { - return it->second; - } - return ""; - } - public: - bool hasKey(const string& key) - { - if(_mpss.find(key) != _mpss.end() || _sset.find(key) != _sset.end()) - { - return true; - } - return false; - } - private: - vector _args; - map _mpss; - set _sset; - - }; - - inline ostream& operator << (ostream& os, const ArgvContext& args) - { - return os< -#include -#include -#include -#include "logger.hpp" - -namespace Limonp -{ - using namespace std; - class MysqlClient - { - public: - typedef vector< vector > RowsType; - private: - const char * const HOST; - const unsigned int PORT; - const char * const USER; - const char * const PASSWD; - const char * const DB; - const char * const CHARSET; - public: - MysqlClient(const char* host, uint port, const char* user, const char* passwd, const char* db, const char* charset = "utf8"): HOST(host), PORT(port), USER(user), PASSWD(passwd), DB(db), CHARSET(charset){ _conn = NULL;}; - ~MysqlClient(){dispose();}; - public: - bool init() - { - //cout< vec; - for(uint i = 0; i < num_fields; i ++) - { - row[i] ? vec.push_back(row[i]) : vec.push_back("NULL"); - } - rows.push_back(vec); - } - mysql_free_result(result); - return true; - } - - private: - MYSQL * _conn; - - }; -} - -#endif diff --git a/src/Husky/Limonp/cast_functs.hpp b/src/Husky/Limonp/cast_functs.hpp deleted file mode 100644 index cf8c54f..0000000 --- a/src/Husky/Limonp/cast_functs.hpp +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef LIMONP_CAST_FUNCTS_H -#define LIMONP_CAST_FUNCTS_H - -namespace Limonp -{ - //logical and or - static const int sign_32 = 0xC0000000; - static const int exponent_32 = 0x07800000; - static const int mantissa_32 = 0x007FE000; - static const int sign_exponent_32 = 0x40000000; - static const int loss_32 = 0x38000000; - - static const short sign_16 = (short)0xC000; - static const short exponent_16 = (short)0x3C00; - static const short mantissa_16 = (short)0x03FF; - static const short sign_exponent_16 = (short)0x4000; - static const int exponent_fill_32 = 0x38000000; - - //infinite - static const short infinite_16 = (short) 0x7FFF; - static const short infinitesmall_16 = (short) 0x0000; - - inline float intBitsToFloat(unsigned int x) - { - union - { - float f; - int i; - }u; - u.i = x; - return u.f; - } - - inline int floatToIntBits(float f) - { - union - { - float f; - int i ; - }u; - u.f = f; - return u.i; - } - - inline short floatToShortBits(float f) - { - int fi = floatToIntBits(f); - - // 提取关键信息 - short sign = (short) ((unsigned int)(fi & sign_32) >> 16); - short exponent = (short) ((unsigned int)(fi & exponent_32) >> 13); - short mantissa = (short) ((unsigned int)(fi & mantissa_32) >> 13); - // 生成编码结果 - short code = (short) (sign | exponent | mantissa); - // 无穷大量、无穷小量的处理 - if ((fi & loss_32) > 0 && (fi & sign_exponent_32) > 0) { - // 当指数符号为1时(正次方),且左234位为1,返回无穷大量 - return (short) (code | infinite_16); - } - if (((fi & loss_32) ^ loss_32) > 0 && (fi & sign_exponent_32) == 0) { - // 当指数符号位0时(负次方),且左234位为0(与111异或>0),返回无穷小量 - return infinitesmall_16; - } - - return code; - } - - inline float shortBitsToFloat(short s) - { - /* - * 指数空余3位:若符号位为1,补0;若符号位为0,补1。 尾数位在后补0(13个) - */ - int sign = ((int) (s & sign_16)) << 16; - int exponent = ((int) (s & exponent_16)) << 13; - // 指数符号位为0,234位补1 - if ((s & sign_exponent_16) == 0 && s != 0) { - exponent |= exponent_fill_32; - } - int mantissa = ((int) (s & mantissa_16)) << 13; - // 生成解码结果 - int code = sign | exponent | mantissa; - return intBitsToFloat(code); - - } -} - -#endif diff --git a/src/Husky/Limonp/config.hpp b/src/Husky/Limonp/config.hpp deleted file mode 100644 index 3e45e6d..0000000 --- a/src/Husky/Limonp/config.hpp +++ /dev/null @@ -1,107 +0,0 @@ -/************************************ - * file enc : utf8 - * author : wuyanyi09@gmail.com - ************************************/ -#ifndef LIMONP_CONFIG_H -#define LIMONP_CONFIG_H - - -#include -#include -#include -#include "logger.hpp" -#include "str_functs.hpp" - -namespace Limonp -{ - using std::map; - using std::string; - using std::cout; - using std::endl; - using std::ifstream; - class Config - { - public: - Config(){_isInit = false;}; - ~Config(){}; - bool init(const string& configFile) - { - if(_isInit) - { - LogFatal("already have been initialized. "); - return false; - } - ifstream ifile(configFile.c_str()); - if(!ifile) - { - LogFatal("open configFile[%s] failed.", configFile.c_str()); - return false; - } - string line, key, value; - vector vecBuf; - while(getline(ifile, line)) - { - //line = _stripComment(line); - if(line.empty()) - { - continue; - } - vecBuf.clear(); - if(!splitStr(line, vecBuf, "=") || 2 != vecBuf.size()) - { - LogFatal("line[%s] is illegal.", line.c_str()); - return false; - } - key = vecBuf[0]; - value = vecBuf[1]; - if(_map.end() != _map.find(key)) - { - LogFatal("key[%s] already exists.", key.c_str()); - return false; - } - _map[key] = value; - } - ifile.close(); - _isInit = true; - return true; - } - void display() - { - for(map::iterator it = _map.begin(); it != _map.end(); it++) - { - cout<<"("<first<<","<second<<")"< _map; - bool _isInit; - - }; -} - -namespace Limonp -{ - extern Config gConfig; -} - -#endif diff --git a/src/Husky/Limonp/io_functs.hpp b/src/Husky/Limonp/io_functs.hpp deleted file mode 100644 index 0128e62..0000000 --- a/src/Husky/Limonp/io_functs.hpp +++ /dev/null @@ -1,82 +0,0 @@ -/************************************ - * file enc : utf8 - * author : wuyanyi09@gmail.com -************************************/ -#ifndef LIMONP_IO_FUNCTS_H -#define LIMONP_IO_FUNCTS_H -#include -#include -#include -namespace Limonp -{ - using namespace std; - inline string loadFile2Str(const char * const filepath) - { - ifstream in(filepath); - if(!in) - { - return ""; - } - istreambuf_iterator beg(in), end; - string str(beg, end); - in.close(); - return str; - } - - inline void loadStr2File(const char * const filename, ios_base::openmode mode, const string& str) - { - ofstream out(filename, mode); - ostreambuf_iterator itr (out); - copy(str.begin(), str.end(), itr); - out.close(); - } - - inline int ReadFromFile(const char * fileName, char* buf, int maxCount, const char* mode) - { - FILE* fp = fopen(fileName, mode); - if (!fp) - return 0; - int ret; - fgets(buf, maxCount, fp) ? ret = 1 : ret = 0; - fclose(fp); - return ret; - } - - inline int WriteStr2File(const char* fileName, const char* buf, const char* mode) - { - FILE* fp = fopen(fileName, mode); - if (!fp) - return 0; - int n = fprintf(fp, "%s", buf); - fclose(fp); - return n; - } - - inline bool checkFileExist(const string& filePath) - { - fstream _file; - _file.open(filePath.c_str(), ios::in); - if(_file) - return true; - return false; - } - - inline bool createDir(const string& dirPath, bool p = true) - { - string dir_str(dirPath); - string cmd = "mkdir"; - if(p) - { - cmd += " -p"; - } - cmd += " " + dir_str; - int res = system(cmd.c_str()); - return res; - } - - inline bool checkDirExist(const string& dirPath) - { - return checkFileExist(dirPath); - } -} -#endif diff --git a/src/Husky/Limonp/logger.hpp b/src/Husky/Limonp/logger.hpp deleted file mode 100644 index ed1a3c2..0000000 --- a/src/Husky/Limonp/logger.hpp +++ /dev/null @@ -1,78 +0,0 @@ -/************************************ - * file enc : utf8 - * author : wuyanyi09@gmail.com - ************************************/ -#ifndef LIMONP_LOGGER_H -#define LIMONP_LOGGER_H - -#include -#include -#include -#include -#include -#include -#include "io_functs.hpp" -#include "str_functs.hpp" - -#define LogDebug(fmt, ...) Logger::LoggingF(LL_DEBUG, __FILE__, __LINE__, fmt, ## __VA_ARGS__) -#define LogInfo(fmt, ...) Logger::LoggingF(LL_INFO, __FILE__, __LINE__, fmt, ## __VA_ARGS__) -#define LogWarn(fmt, ...) Logger::LoggingF(LL_WARN, __FILE__, __LINE__, fmt, ## __VA_ARGS__) -#define LogError(fmt, ...) Logger::LoggingF(LL_ERROR, __FILE__, __LINE__, fmt, ## __VA_ARGS__) -#define LogFatal(fmt, ...) Logger::LoggingF(LL_FATAL, __FILE__, __LINE__, fmt, ## __VA_ARGS__) - - -namespace Limonp -{ - using namespace std; - enum {LL_DEBUG = 0, LL_INFO = 1, LL_WARN = 2, LL_ERROR = 3, LL_FATAL = 4, LEVEL_ARRAY_SIZE = 5, CSTR_BUFFER_SIZE = 1024}; - static const char * LOG_LEVEL_ARRAY[LEVEL_ARRAY_SIZE]= {"DEBUG","INFO","WARN","ERROR","FATAL"}; - static const char * LOG_FORMAT = "%s %s:%d %s %s\n"; - static const char * LOG_TIME_FORMAT = "%Y-%m-%d %H:%M:%S"; - - class Logger - { - public: - static bool Logging(uint level, const string& msg, const char* fileName, int lineNo) - { - if(level > LL_FATAL) - { - cerr<<"level's value is out of range"< -1 && n < size) { - msg.resize(n); - break; - } - if (n > -1) - size = n + 1; - else - size *= 2; - } - return Logging(level, msg, fileName, lineNo); - } - }; -} - -#endif diff --git a/src/Husky/Limonp/macro_def.hpp b/src/Husky/Limonp/macro_def.hpp deleted file mode 100644 index 58fe835..0000000 --- a/src/Husky/Limonp/macro_def.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef LIMONP_MACRO_DEF_H -#define LIMONP_MACRO_DEF_H - -#define XX_GET_SET(varType, varName, funName)\ -private: varType varName;\ -public: inline varType get##funName(void) const {return varName;}\ -public: inline void set##funName(varType var) {varName = var;} - -#define XX_GET(varType, varName, funName)\ -private: varType varName;\ -public: inline varType get##funName(void) const {return varName;} - -#define XX_SET(varType, varName, funName)\ -private: varType varName;\ -public: inline void set##funName(varType var) {varName = var;} - -#define XX_GET_SET_BY_REF(varType, varName, funName)\ -private: varType varName;\ -public: inline const varType& get##funName(void) const {return varName;}\ -public: inline void set##funName(const varType& var){varName = var;} - -#endif diff --git a/src/Husky/Limonp/map_functs.hpp b/src/Husky/Limonp/map_functs.hpp deleted file mode 100644 index 44d472c..0000000 --- a/src/Husky/Limonp/map_functs.hpp +++ /dev/null @@ -1,116 +0,0 @@ -/************************************ - * file enc : ascii - * author : wuyanyi09@gmail.com - ************************************/ - - -#ifndef LIMONP_MAP_FUNCTS_H -#define LIMONP_MAP_FUNCTS_H - -#include -#include -#include -#include - -#include -#define HashMap std::tr1::unordered_map - -namespace Limonp -{ - using namespace std; - - - //template - // string setToString(const set& st) - // { - // if(st.empty()) - // { - // return "{}"; - // } - // stringstream ss; - // ss<<'{'; - // typename set::const_iterator it = st.begin(); - // ss<<*it; - // it++; - // while(it != st.end()) - // { - // ss<<", "<<*it; - // it++; - // } - // ss<<'}'; - // return ss.str(); - // } - - //template - // string mapToString(const map& mp) - // { - // if(mp.empty()) - // { - // return "{}"; - // } - // stringstream ss; - // ss<<'{'; - // typename map::const_iterator it = mp.begin(); - // ss<first<<": "<second; - // it++; - // while(it != mp.end()) - // { - // ss<<", "<first<<": "<second; - // it++; - // } - // ss<<'}'; - // return ss.str(); - // } - - //template - // string HashMapToString(const HashMap& mp) - // { - // if(mp.empty()) - // { - // return "{}"; - // } - // stringstream ss; - // ss<<'{'; - // typename HashMap::const_iterator it = mp.begin(); - // ss<first<<": "<second; - // it++; - // while(it != mp.end()) - // { - // ss<<", "<first<<": "<second; - // it++; - // } - // ss<<'}'; - // return ss.str(); - // } - //template - // string pairToString(const pair& p) - // { - // stringstream ss; - // ss< - vT getMap(const map& mp, const kT & key, const vT & defaultVal) - { - typename map::const_iterator it; - it = mp.find(key); - if(mp.end() == it) - { - return defaultVal; - } - return it->second; - } - - template - void map2Vec(const map& mp, vector > & res) - { - typename map::const_iterator it = mp.begin(); - for(; it != mp.end(); it++) - { - res.push_back(*it); - } - } -} - -#endif diff --git a/src/Husky/Limonp/std_outbound.hpp b/src/Husky/Limonp/std_outbound.hpp deleted file mode 100644 index ab3e5c3..0000000 --- a/src/Husky/Limonp/std_outbound.hpp +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef LIMONP_STD_OUTBOUND_H -#define LIMONP_STD_OUTBOUND_H - -#include -#include -#include - -namespace std -{ - template - ostream& operator << (ostream& os, const vector& vec) - { - if(vec.empty()) - { - return os << "[]"; - } - os<<"[\""< - ostream& operator << (ostream& os, const pair& pr) - { - os << pr.first << ":" << pr.second ; - return os; - } - - - template - string& operator << (string& str, const T& obj) - { - stringstream ss; - ss << obj; // call ostream& operator << (ostream& os, - return str = ss.str(); - } - - template - ostream& operator << (ostream& os, const map& mp) - { - if(mp.empty()) - { - os<<"{}"; - return os; - } - os<<'{'; - typename map::const_iterator it = mp.begin(); - os<<*it; - it++; - while(it != mp.end()) - { - os<<", "<<*it; - it++; - } - os<<'}'; - return os; - } - template - ostream& operator << (ostream& os, const std::tr1::unordered_map& mp) - { - if(mp.empty()) - { - return os << "{}"; - } - os<<'{'; - typename std::tr1::unordered_map::const_iterator it = mp.begin(); - os<<*it; - it++; - while(it != mp.end()) - { - os<<", "<<*it++; - } - return os<<'}'; - } - - template - ostream& operator << (ostream& os, const set& st) - { - if(st.empty()) - { - os << "{}"; - return os; - } - os<<'{'; - typename set::const_iterator it = st.begin(); - os<<*it; - it++; - while(it != st.end()) - { - os<<", "<<*it; - it++; - } - os<<'}'; - return os; - } -} - -#endif diff --git a/src/Husky/Limonp/str_functs.hpp b/src/Husky/Limonp/str_functs.hpp deleted file mode 100644 index 8be5366..0000000 --- a/src/Husky/Limonp/str_functs.hpp +++ /dev/null @@ -1,257 +0,0 @@ -/************************************ - * file enc : ascii - * author : wuyanyi09@gmail.com - ************************************/ -#ifndef LIMONP_STR_FUNCTS_H -#define LIMONP_STR_FUNCTS_H -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "std_outbound.hpp" -#include "map_functs.hpp" - -#define print(x) cout<<(x)< -1 && n < size) { - str.resize(n); - return str; - } - if (n > -1) - size = n + 1; - else - size *= 2; - } - return str; - } - - inline void string_format(string& res, const char* fmt, ...) - { - int size = 256; - va_list ap; - while (1) { - res.resize(size); - va_start(ap, fmt); - int n = vsnprintf((char *)res.c_str(), size, fmt, ap); - va_end(ap); - if (n > -1 && n < size) { - res.resize(n); - return; - } - if (n > -1) - size = n + 1; - else - size *= 2; - } - } - - //inline bool joinStr(const vector& src, string& dest, const string& connectorStr) - //{ - // if(src.empty()) - // { - // return false; - // } - // for(uint i = 0; i < src.size() - 1; i++) - // { - // dest += src[i]; - // dest += connectorStr; - // } - // dest += src[src.size() - 1]; - // return true; - //} - - //inline string joinStr(const vector& source, const string& connector) - //{ - // string res; - // joinStr(source, res, connector); - // return res; - //} - - template - void join(T begin, T end, string& res, const string& connector) - { - if(begin == end) - { - return; - } - stringstream ss; - ss<<*begin; - begin++; - while(begin != end) - { - ss << connector << *begin; - begin ++; - } - res = ss.str(); - } - - template - string join(T begin, T end, const string& connector) - { - string res; - join(begin ,end, res, connector); - return res; - } - - - - inline bool splitStr(const string& src, vector& res, const string& pattern) - { - if(src.empty()) - { - return false; - } - res.clear(); - - size_t start = 0; - size_t end = 0; - while(start < src.size()) - { - end = src.find_first_of(pattern, start); - if(string::npos == end) - { - res.push_back(src.substr(start)); - return true; - } - res.push_back(src.substr(start, end - start)); - if(end == src.size() - 1) - { - res.push_back(""); - break; - } - start = end + 1; - } - return true; - } - - inline string& upper(string& str) - { - transform(str.begin(), str.end(), str.begin(), (int (*)(int))toupper); - return str; - } - - inline string& lower(string& str) - { - transform(str.begin(), str.end(), str.begin(), (int (*)(int))tolower); - return str; - } - - inline std::string <rim(std::string &s) - { - s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun(std::isspace)))); - return s; - } - - inline std::string &rtrim(std::string &s) - { - s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun(std::isspace))).base(), s.end()); - return s; - } - - inline std::string &trim(std::string &s) - { - return ltrim(rtrim(s)); - } - - - inline uint16_t twocharToUint16(char high, char low) - { - return (((uint16_t(high) & 0x00ff ) << 8) | (uint16_t(low) & 0x00ff)); - } - - inline pair uint16ToChar2(uint16_t in) - { - pair res; - res.first = (in>>8) & 0x00ff; //high - res.second = (in) & 0x00ff; //low - return res; - } - - inline bool strStartsWith(const string& str, const string& prefix) - { - //return str.substr(0, prefix.size()) == prefix; - if(prefix.length() > str.length()) - { - return false; - } - return 0 == str.compare(0, prefix.length(), prefix); - } - - inline bool strEndsWith(const string& str, const string& suffix) - { - if(suffix.length() > str.length()) - { - return false; - } - return 0 == str.compare(str.length() - suffix.length(), suffix.length(), suffix); - } - - inline bool isInStr(const string& str, char ch) - { - return str.find(ch) != string::npos; - } - - //inline void extractWords(const string& sentence, vector& words) - //{ - // bool flag = false; - // uint lhs = 0, len = 0; - // for(uint i = 0; i < sentence.size(); i++) - // { - // char x = sentence[i]; - // if((0x0030 <= x && x<= 0x0039) || (0x0041 <= x && x <= 0x005a ) || (0x0061 <= x && x <= 0x007a)) - // { - // if(flag) - // { - // len ++; - // } - // else - // { - // lhs = i; - // len = 1; - // } - // flag = true; - // } - // else - // { - // if(flag) - // { - // words.push_back(string(sentence, lhs, len)); - // } - // flag = false; - // } - // } - // if(flag) - // { - // words.push_back(string(sentence, lhs, len)); - // } - //} - - -} -#endif diff --git a/src/Husky/Limonp/typedefs.h b/src/Husky/Limonp/typedefs.h deleted file mode 100644 index a8da002..0000000 --- a/src/Husky/Limonp/typedefs.h +++ /dev/null @@ -1,21 +0,0 @@ -/************************************ - * file enc : utf8 - * author : wuyanyi09@gmail.com -************************************/ -#ifndef LIMONP_TYPEDEFS_H -#define LIMONP_TYPEDEFS_H - -#include -#include -#include -#include -#define HashMap std::tr1::unordered_map - -namespace Limonp -{ - typedef std::vector Unicode; - typedef std::vector::const_iterator UnicodeConstIterator; -} - - -#endif diff --git a/src/Husky/Limonp/vec_functs.hpp b/src/Husky/Limonp/vec_functs.hpp deleted file mode 100644 index ac18548..0000000 --- a/src/Husky/Limonp/vec_functs.hpp +++ /dev/null @@ -1,142 +0,0 @@ -/************************************ - * file enc : ascii - * author : wuyanyi09@gmail.com -************************************/ -#ifndef LIMONP_VEC_FUNCTS_H -#define LIMONP_VEC_FUNCTS_H -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define FOR_VECTOR(vec, i) for(size_t i = 0; i < vec.size(); i++) - -#define PRINT_VECTOR(vec) FOR_VECTOR(vec, i)\ -{\ - cout< - bool vecToString(const vector& vec, string& res) - { - if(vec.empty()) - { - res = "[]"; - return false; - } - stringstream ss; - ss<<"[\""< - string vecToString(const vector& vec) - { - string res; - vecToString(vec, res); - return res; - } - - template - bool isInVec(const vector& vec, const T& item) - { - typename vector::const_iterator it = find(vec.begin(), vec.end(), item); - return it != vec.end(); - } - template - void splitVec(const vector& vecSrc, vector< pair > >& outVec, const vector& patterns) - { - vector tmp; - T pattern; - size_t patternSize = patterns.size(); - for(size_t i = 0; i < vecSrc.size(); i++) - { - size_t patternPos = patternSize; - for(size_t j = 0; j < patternSize; j++) - { - if(patterns[j] == vecSrc[i]) - { - patternPos = j; - break; - } - } - if(patternPos != patternSize) - { - if(!tmp.empty()) - { - outVec.push_back(make_pair >(pattern, tmp)); - tmp.clear(); - } - pattern = patterns[patternPos]; - } - else - { - tmp.push_back(vecSrc[i]); - } - } - if(!tmp.empty()) - { - outVec.push_back(make_pair >(pattern, tmp)); - } - } - - template - void splitVec(const vector& vecSrc, vector< vector >& outVec, const vector& patternVec) - { - vector tmp; - for(size_t i = 0; i < vecSrc.size(); i++) - { - bool flag = false; - for(size_t j = 0; j < patternVec.size(); j++) - { - if(patternVec[j] == vecSrc[i]) - { - flag = true; - break; - } - } - if(flag) - { - if(!tmp.empty()) - { - outVec.push_back(tmp); - tmp.clear(); - } - } - else - { - tmp.push_back(vecSrc[i]); - } - } - if(!tmp.empty()) - { - outVec.push_back(tmp); - } - } -} - -#endif