ControllerHelper.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #pragma once
  2. namespace OTSController {
  3. #ifdef UNICODE
  4. #define isdigit_t iswdigit
  5. #else
  6. #define isdigit_t isdigit
  7. #endif
  8. class CControllerHelper /*: private boost::noncopyable*/
  9. {
  10. private:
  11. CControllerHelper(void) = delete;
  12. ~CControllerHelper(void) = delete;
  13. public:
  14. /// <summary>
  15. /// This class is for smart pointer deleter. Because Gdiplus define its own delete.
  16. /// </summary>
  17. template <class T>
  18. class StandardDelete
  19. {
  20. public:
  21. void operator() (T* d) const
  22. {
  23. ::delete d;
  24. }
  25. };
  26. public:
  27. /// <summary>
  28. /// Gets the name of the folder.
  29. /// </summary>
  30. /// <param name="fullPath">The full path.</param>
  31. /// <returns>the folder name</returns>
  32. static CString GetFolderName(CString fullPath);
  33. static CString GetFileNameWithoutExtension(CString fullPath);
  34. /// <summary>
  35. /// Gets the name of the file.
  36. /// </summary>
  37. /// <param name="fullPath">The full path.</param>
  38. /// <returns>the file name</returns>
  39. static CString GetFileName(LPCTSTR fullPath);
  40. /// <summary>
  41. /// Get file extension
  42. /// </summary>
  43. /// <param name="fullPath">The full path.</param>
  44. /// <returns>
  45. /// Return the file extension
  46. /// </returns>
  47. static CString GetFileExtension(LPCTSTR fullPath);
  48. /// <summary>
  49. /// Get system error string
  50. /// </summary>
  51. /// <param name="err">The err.</param>
  52. /// <returns>
  53. /// Return the system error string
  54. /// </returns>
  55. static LPCTSTR GetSystemErrorString(DWORD err);
  56. /// <summary>
  57. /// Strings to double.
  58. /// </summary>
  59. /// <param name="a_sValue">The string value.</param>
  60. /// <param name="a_nValue">The double value.</param>
  61. /// <returns>
  62. /// true if successful; otherwise, false.
  63. /// </returns>
  64. // Strings to double
  65. static BOOL StringToDouble(LPCTSTR a_sValue, double& a_nValue);
  66. static BOOL IsDoubleString(LPCTSTR a_sValue);
  67. static int CharToWChar(const char* a_psSource, wchar_t* a_psDest);
  68. static int WCharToChar(const wchar_t* a_psSource, char* a_psDest);
  69. static CString CharToString(const char* a_psSource);
  70. static DWORD ConvStreamToByteArr(IStream *stream, BYTE **byte);
  71. static std::vector<std::string> SplitSTDString(std::string& a_sSource, char a_cTok);
  72. static std::vector<CString> SplitString(const CString& a_sSource, LPCTSTR a_sTok);
  73. static void EnsureStringLengthNoMoreThan(CString& ioString, int inMaxLength);
  74. static void TrimSTDString(std::string& a_sString, char a_cTrimChar = ' ');
  75. template<typename _Type>
  76. static std::vector<const _Type*> GenerateReferenceList(const std::vector<_Type>& inValueList)
  77. {
  78. auto itemCount = inValueList.size();
  79. std::vector<const _Type*> referenceList(itemCount);
  80. auto* referencePointer = referenceList.data();
  81. for (auto i = 0u; i < itemCount; ++i)
  82. {
  83. referencePointer[i] = &inValueList[i];
  84. }
  85. return referenceList;
  86. }
  87. };
  88. }