helpfunc.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #pragma once
  2. #ifndef __HELPFUCN_H_
  3. #define __HELPFUNC_H_
  4. #include "optype.h"
  5. #include "frameInfo.h"
  6. std::wstring _s2wstring(const std::string& s);
  7. std::string _ws2string(const std::wstring& s);
  8. //½«Â·¾¶×ª»¯ÎªÈ«¾Ö·¾¶
  9. long Path2GlobalPath(const TString& file, const TString& curr_path, TString& out);
  10. void split(const TString& s, std::vector<TString>& v, const TString& c);
  11. void wstring2upper(std::wstring& s);
  12. void string2upper(std::string& s);
  13. void wstring2lower(std::wstring& s);
  14. void string2lower(std::string& s);
  15. void replacea(TString& str, const TString& oldval, const TString& newval);
  16. //for debug
  17. long setlog(const wchar_t* format, ...);
  18. //
  19. long setlog(const char* format, ...);
  20. int inline hex2bin(int c) {
  21. return c <= L'9' ? c - L'0' : c - L'A' + 10;
  22. };
  23. int inline bin2hex(int c) {
  24. int ans = 0;
  25. int c1 = c >> 4 & 0xf;
  26. int c2 = c & 0xf;
  27. ans |= (c1 <= 9 ? c1 + L'0' : c1 + 'A' - 10) << 8;
  28. ans |= c2 <= 9 ? c2 + L'0' : c2 + 'A' - 10;
  29. return ans;
  30. };
  31. constexpr int PTY(uint pt) {
  32. return pt >> 16;
  33. }
  34. constexpr int PTX(uint pt) {
  35. return pt & 0xffff;
  36. }
  37. template<typename T>
  38. void nextVal(const T& t, int* next) {
  39. next[0] = -1;
  40. int k = -1, j = 0;
  41. while (j < (int)t.size() - 1) {
  42. if (k == -1 || t[k] == t[j]) {
  43. k++;
  44. j++;
  45. next[j] = k;
  46. }
  47. else {
  48. k = next[k];
  49. }
  50. }
  51. }
  52. template<typename T>
  53. int kmp(const T& s, const T& t) {
  54. vector<int> next(t.size());
  55. nextVal(t, next.data());
  56. int i = 0, j = 0;
  57. while (i < (int)s.size() && j < (int)t.size()) {
  58. if (j == -1 || s[i] == t[j]) {
  59. i++;
  60. j++;
  61. }
  62. else {
  63. j = next[j];
  64. }
  65. }
  66. return j == s.size() ? i - j : -1;
  67. }
  68. std::ostream& operator<<(std::ostream& o, point_t const& rhs);
  69. std::wostream& operator<<(std::wostream& o, point_t const& rhs);
  70. std::ostream& operator<<(std::ostream& o, FrameInfo const& rhs);
  71. std::wostream& operator<<(std::wostream& o, FrameInfo const& rhs);
  72. #endif // !__TOOL_H_