-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
160 lines (125 loc) · 6.13 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#ifndef UTILS_H_
#define UTILS_H_
#include <string>
#include <vector>
#include <map>
#include "app_defs.h"
#include "app_common.h"
#include "boost/date_time/gregorian/gregorian_types.hpp"
#include "boost/date_time/posix_time/posix_time_types.hpp"
BEGIN_NAMESPACE;
typedef boost::posix_time::ptime DATETIME_BOOST;
typedef boost::posix_time::time_duration TIME_BOOST;
typedef boost::gregorian::date DATE_BOOST;
class EXPORT AppUtils
{
public:
/////////////////////////////////////////////////////////////////
/// \brief Delete File
///
/// \param[in] const std::string& sFilePath
///
/// \param[out] None
/// \return None
///
/// \pre \e
/////////////////////////////////////////////////////////////////
static bool DeleteLocalFile(const std::string& sFilePath);
/////////////////////////////////////////////////////////////////
/// \brief Delete Files
///
/// \param[in] const std::vector<std::string>& FilePathArray
///
/// \param[out] None
/// \return None
///
/// \pre \e
/////////////////////////////////////////////////////////////////
static void DeleteFiles(const std::vector<std::string>& FilePathArray);
static void DeteteFolder(const std::string& sFolderName);
/////////////////////////////////////////////////////////////////
/// \brief Create folders and subfolders
/// Using Boost FileSystem
///
/// \param[in] const std::string& sFolderName
/// eg. string strFilePath="E:/images/";
///
/// \param[out]
/// \return int
/// 0:success to create a Child Folder
/// -1:fail
/// \pre \e
/////////////////////////////////////////////////////////////////
static bool CreateMultiFolder(const std::string& sFolderName);
/////////////////////////////////////////////////////////////////
/// \brief ReadBufferFromFileDeleteDicomFiles
/// Note: should delete buffer outside
/// \param[in] const std::string& sFilePath
/// \param[out] char* buffer, std::size_t* size
/// \return bool
///
/// \pre \e
/////////////////////////////////////////////////////////////////
static bool ReadBufferFromFile(const std::string& sFilePath, char*& buffer, std::size_t* size);
static bool ReadBufferFromFile(const std::string& sFilePath, std::string& strBuffer);
static void CopyFileInBinary(const std::string& sFilePathSrc, const std::string& sFilePathDst);
static bool WriteFileInBinary(const std::string& sFileName, const char* buffer, std::size_t size);
static bool WriteDataToFile(const std::string& sFileName, const std::string& sData);
template <typename T>
static bool ReadBufferFromString(std::string sSource, std::string SplitString, std::vector<T>& vValueList);
static bool SaveToTrueColorBitmap(
const std::string& path,
unsigned char* buffer,
const int& height,
const int& width);
static void SaveToGrayBitmap(
const std::string& path,
unsigned char* buffer,
const int& height,
const int& width,
unsigned char color = 255);
//0018,1030 ProtocolName
//0018,0015 BodyPartExamined
static std::string GetLabel(int nSliceCount,
const std::string& Modality,
const std::string& BodyPartExamined,
const std::string& SeriesDescription,
const std::string& StudyDescription,
const std::string& ProtocolName);
static APP_TYPE String2Enum_APP_TYPE(const char* user_input);
//(0008,0020) Study Date StudyDate DA 1. A string of characters of the format
//YYYYMMDD where YYYY shall contain year,
//MM shall contain the month, and DD shall
//contain the day, interpreted as a date of the
//Gregorian calendar system. Example:19930822 would represent August 2
static DATE_BOOST ConvertDate2Boost(const std::string& date);
//(0008,0030) Study Time StudyTime TM 1.
//A string of characters of the format
//HHMMSS.FFFFFF; where HH contains hours
//(range 00 - 23), MM contains minutes (range 00 - 59), SS contains seconds
//(range 00 - 60), and FFFFFF contains a fractional part of a second as small as 1
//millionth of a second (range 000000 - 999999). A 24-hour clock is used. Midnight
//shall be represented by only 0000 since 2400 would violate the hour range. The
//string may be padded with trailing spaces. Leading and embedded spaces are n
static TIME_BOOST ConvertTime2Boost(const std::string& time);
static DATETIME_BOOST ConvertDateTime2Boost(const std::string& datetime);
static std::string GetCurrentDirPath();
static std::string GetSystemRootPath();
static std::string SimpleXmlParser(const std::string& logxml, const std::string& sKey);
static std::string AppUtils::GetCurrentDate();
static std::vector<std::string> Split( const std::string &s, const std::string &seperator );
// eg. key = "-k"
static std::vector<std::string> SplitSubstring(const std::string& str, const std::string& key);
static std::string GetAIConfig();
static std::wstring s2ws(const std::string& s);
static std::string ws2s(std::wstring& inputws);
static std::string Trim(const std::string str);
// calc the date = today - numDays
// 20181011
static std::string DatePlusDays(int numDays);
static void FindFilesRecursion(const std::string& path, std::vector<std::string>& files);
static void FindFiles(const std::string& path, std::vector<std::string>& files);
static void FindFolderRecursion(const std::string& path, std::vector<std::string>& folders);
};
END_NAMESPACE;
#endif //UTILS_H_