正在显示
1 个修改的文件
包含
88 行增加
和
0 行删除
src/server/dmpserverutils.h
0 → 100644
1 | + | |
2 | +/************************************************************************** | |
3 | +* file: dmpserverutils.h | |
4 | + | |
5 | +* Author: wanzhongping | |
6 | +* Date: 2021-03-17 16:05:31 | |
7 | +* Email: zhongpingw@chinadci.com | |
8 | +* copyright: 广州城市信息研究所有限公司 | |
9 | +***************************************************************************/ | |
10 | + | |
11 | +#ifndef __dmpserverutils_h__ | |
12 | +#define __dmpserverutils_h__ | |
13 | + | |
14 | +#include "dmap_server.h" | |
15 | +#include <boost/filesystem.hpp> | |
16 | +#include <unordered_map> | |
17 | + | |
18 | +class SERVER_EXPORT DmpServerUtils | |
19 | +{ | |
20 | + public: | |
21 | + //获取目录下的所有dll或so库文件 | |
22 | + static int GetLibraryPaths(const boost::filesystem::path &dir, std::vector<boost::filesystem::path> &locations); | |
23 | +}; | |
24 | + | |
25 | + class CaseInsensitiveEqual { | |
26 | + public: | |
27 | + bool operator()(const std::string &str1, const std::string &str2) const noexcept { | |
28 | + return str1.size() == str2.size() && | |
29 | + std::equal(str1.begin(), str1.end(), str2.begin(), [](char a, char b) { | |
30 | + return tolower(a) == tolower(b); | |
31 | + }); | |
32 | + } | |
33 | + }; | |
34 | + | |
35 | + class CaseInsensitiveHash { | |
36 | + public: | |
37 | + std::size_t operator()(const std::string &str) const noexcept { | |
38 | + std::size_t h = 0; | |
39 | + std::hash<int> hash; | |
40 | + for(auto c : str) | |
41 | + h ^= hash(tolower(c)) + 0x9e3779b9 + (h << 6) + (h >> 2); | |
42 | + return h; | |
43 | + } | |
44 | + }; | |
45 | + | |
46 | + | |
47 | + using CaseInsensitiveMultimap = std::unordered_multimap<std::string, std::string, CaseInsensitiveHash, CaseInsensitiveEqual>; | |
48 | + | |
49 | + // Percent encoding and decoding | |
50 | + class Percent { | |
51 | + public: | |
52 | + static std::string encode(const std::string &value) noexcept; | |
53 | + static std::string decode(const std::string &value) noexcept; | |
54 | + }; | |
55 | + | |
56 | + | |
57 | +//自定义大小写不敏感的map | |
58 | +struct ci_less : std::binary_function<std::string, std::string, bool> | |
59 | +{ | |
60 | + // case-independent (ci) compare_less binary function | |
61 | + struct nocase_compare : public std::binary_function<unsigned char, unsigned char, bool> | |
62 | + { | |
63 | + bool operator()(const unsigned char &c1, const unsigned char &c2) const | |
64 | + { | |
65 | + return tolower(c1) < tolower(c2); | |
66 | + } | |
67 | + }; | |
68 | + bool operator()(const std::string &s1, const std::string &s2) const | |
69 | + { | |
70 | + return std::lexicographical_compare(s1.begin(), s1.end(), // source range | |
71 | + s2.begin(), s2.end(), // dest range | |
72 | + nocase_compare()); // comparison | |
73 | + } | |
74 | +}; | |
75 | + | |
76 | +using CIMap = std::map<std::string, std::string, ci_less>; | |
77 | + | |
78 | + // Query string creation and parsing | |
79 | + class QueryString { | |
80 | + public: | |
81 | + // Returns query string created from given field names and values | |
82 | + static std::string create(const CIMap &fields) noexcept; | |
83 | + // Returns query keys with percent-decoded values. | |
84 | + static CIMap parse(const std::string &query_string) noexcept; | |
85 | + }; | |
86 | + | |
87 | + | |
88 | +#endif //__dmpserverutils_h__ | ... | ... |
请
注册
或
登录
后发表评论