#include <Utility.h>
Definition at line 12 of file Utility.h.
CppSamples::Common::Utility::Utility |
( |
| ) |
|
|
inline |
CppSamples::Common::Utility::~Utility |
( |
| ) |
|
|
inline |
void Utility::ClearScreen |
( |
| ) |
|
|
static |
string Utility::ConvertLocalTimetoUTC |
( |
struct tm |
t | ) |
|
|
static |
Converts the local time to UTC format
- Parameters
-
- Parameters
-
Definition at line 28 of file Utility.cpp.
31 time_t epochTime = mktime(&t);
34 gmtime_r(&epochTime, &timeinfo);
40 fmt << timeinfo.tm_year + 1900 <<
"-" 41 << setfill(
'0') << setw(2) << (timeinfo.tm_mon + 1) <<
"-" 42 << setfill(
'0') << setw(2) << timeinfo.tm_mday <<
"T" 43 << setfill(
'0') << setw(2) << timeinfo.tm_hour <<
":" 44 << setfill(
'0') << setw(2) << timeinfo.tm_min <<
":" 45 << setfill(
'0') << setw(2) << timeinfo.tm_sec <<
"Z";
#define gmtime_s(time, result)
string Utility::ConvertUTCTimeFormatToString |
( |
std::string |
utcFormat | ) |
|
|
static |
Converts UTC time to string
Converts the UTC time format to string format (HH:MM::SS, Day Month)
- Parameters
-
utcFormat | time string in UTC format (YYYYmmddTHHMMSSZ) |
Definition at line 312 of file Utility.cpp.
313 stringstream dateStream(utcFormat);
316 dateStream >> get_time(&parseTime,
"%Y-%m-%dT%H:%M:%S");
318 strftime(buffer, 18,
"%X %x", &parseTime);
320 return string(buffer);
string Utility::ConvertUTCtoLocalTime |
( |
struct tm |
t | ) |
|
|
static |
Converts the UTC time to local time format
- Parameters
-
- Parameters
-
Definition at line 53 of file Utility.cpp.
56 time_t epochTime = mktime(&t);
62 fmt << timeinfo.tm_year + 1900 <<
"-" 63 << setfill(
'0') << setw(2) << (timeinfo.tm_mon + 1) <<
"-" 64 << setfill(
'0') << setw(2) << timeinfo.tm_mday <<
"T" 65 << setfill(
'0') << setw(2) << timeinfo.tm_hour <<
":" 66 << setfill(
'0') << setw(2) << timeinfo.tm_min <<
":" 67 << setfill(
'0') << setw(2) << timeinfo.tm_sec <<
"Z";
static int TzOffset()
Get the time zone offset in seconds
#define localtime_s(time, result)
string Utility::Encode |
( |
const std::string & |
toEncode | ) |
|
|
static |
Encode given std::string using Base64
Encode given string using Base64
- Parameters
-
- Parameters
-
Definition at line 75 of file Utility.cpp.
76 string kBase64Chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
77 const char* data = toEncode.c_str();
78 size_t size = toEncode.length();
81 unsigned char char_array_3[3];
82 unsigned char char_array_4[4];
85 char_array_3[i++] = *(data++);
87 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
88 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
89 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
90 char_array_4[3] = char_array_3[2] & 0x3f;
92 for (i = 0; i < 4; i++)
93 ret += kBase64Chars[char_array_4[i]];
100 for (j = i; j < 3; j++)
101 char_array_3[j] =
'\0';
103 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
104 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
105 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
106 char_array_4[3] = char_array_3[2] & 0x3f;
108 for (j = 0; j < i + 1; j++)
109 ret += kBase64Chars[char_array_4[j]];
tm Utility::GetDateAndTimeFromUser |
( |
| ) |
|
|
static |
Get the date and time input from user and returns in struct format
Definition at line 120 of file Utility.cpp.
124 string dateAndTimeVal;
125 getline(cin, dateAndTimeVal);
127 if (!dateAndTimeVal.empty()) {
129 stringstream dateStream(dateAndTimeVal);
130 dateStream >> get_time(&parseTime,
"%Y-%m-%d %H:%M:%S");
131 if (dateStream.fail()) {
132 cout <<
"Invalid time.\n";
139 cout <<
"Please enter a time.\n";
141 cout <<
"\n" <<
"Enter time (yyyy-mm-dd hh:mm:ss): ";
146 t.tm_mon = parseTime.tm_mon;
147 t.tm_year = parseTime.tm_year;
148 t.tm_mday = parseTime.tm_mday;
149 t.tm_hour = parseTime.tm_hour;
150 t.tm_min = parseTime.tm_min;
151 t.tm_sec = parseTime.tm_sec;
string Utility::GetNewGuid |
( |
| ) |
|
|
static |
Initializes a new instance of the System.Guid structure and returns equivalent std::string.
Initializes a new instance of the System.Guid structure and returns equivalent string.
- Returns
- String value of new Guid.
Definition at line 204 of file Utility.cpp.
208 uuid_generate_random ( uuid );
210 uuid_unparse ( uuid, buffer );
211 return string(buffer);
214 HRESULT hCreateGuid = CoCreateGuid(&newGuid);
218 sprintf_s(buffer,
"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
219 newGuid.Data1, newGuid.Data2, newGuid.Data3,
220 newGuid.Data4[0], newGuid.Data4[1], newGuid.Data4[2], newGuid.Data4[3],
221 newGuid.Data4[4], newGuid.Data4[5], newGuid.Data4[6], newGuid.Data4[7]);
222 return string(buffer);
static bool CppSamples::Common::Utility::Init |
( |
| ) |
|
|
static |
Login to the VideoExpert system.
Definition at line 15 of file Utility.cpp.
EXTERN_C VXAPI VxResult::Value VxSystemLogin(const VxLoginInfo &loginInfo, IVxSystem *&system)
tm Utility::ParseDateTime |
( |
char * |
dateTime | ) |
|
|
static |
Parse a date time string and return in struct format
Parses a date time string and returns in struct format
Definition at line 158 of file Utility.cpp.
160 string dateAndTimeVal = string(dateTime);
163 stringstream dateStream(dateAndTimeVal);
164 dateStream >> get_time(&parseTime,
"%Y-%m-%dT%H:%M:%S");
168 t.tm_mon = parseTime.tm_mon;
169 t.tm_year = parseTime.tm_year;
170 t.tm_mday = parseTime.tm_mday;
171 t.tm_hour = parseTime.tm_hour;
172 t.tm_min = parseTime.tm_min;
173 t.tm_sec = parseTime.tm_sec;
Pause for a user input
Definition at line 280 of file Utility.cpp.
282 std::cout <<
"Press any key to continue...";
284 fseek(stdin, 0, SEEK_END);
286 while (std::cin.
get() !=
'\n');
Read an integer from console input
Definition at line 269 of file Utility.cpp.
272 int value = atoi(line.c_str());
273 while (std::cin.
get() !=
'\n');
string Utility::ReadString |
( |
| ) |
|
|
static |
Read a line from console input
Read a string from console input
Definition at line 260 of file Utility.cpp.
262 std::getline(std::cin, line);
string Utility::Replace |
( |
std::string |
original, |
|
|
std::string |
from, |
|
|
std::string |
to |
|
) |
| |
|
static |
Replace a give string
Definition at line 295 of file Utility.cpp.
297 int len = from.length();
299 index = original.find(from);
303 original = original.replace(index, len, to);
void Utility::ShowProgress |
( |
std::string |
statusMsg, |
|
|
unsigned int |
x, |
|
|
unsigned int |
n, |
|
|
int |
w = 50 |
|
) |
| |
|
static |
Show progress indicator in console
- Parameters
-
statusMsg | Message to display |
x | progress value |
n | actual size |
w | width of bar |
Definition at line 184 of file Utility.cpp.
185 if ((x != n) && (x % (n / 100 + 1) != 0))
188 float ratio = x /
static_cast<float>(n);
189 int c =
static_cast<int>(ratio * w);
190 int percentToDisplay =
static_cast<int>(ratio * 100);
192 if (percentToDisplay > 100)
193 percentToDisplay = 100;
194 cout <<
" " << statusMsg <<
" " << setfill(
' ') << setw(3) << percentToDisplay <<
"% [";
195 for (
int k = 0; k < c; k++) cout <<
"=";
196 for (
int m = c; m < w; m++) cout <<
" ";
197 cout <<
"]\r" << flush;
int Utility::TzOffset |
( |
| ) |
|
|
static |
Get the time zone offset in seconds
Definition at line 229 of file Utility.cpp.
231 tm utcTm{ 0 }, localTm{ 0 };
232 time_t local = time(
nullptr), utc;
234 gmtime_r(&local, &utcTm);
239 localTm.tm_isdst = 0;
240 local = mktime(&localTm);
241 utc = mktime(&utcTm);
242 offset =
static_cast<int>(difftime(local, utc));
#define localtime_s(time, result)
#define gmtime_s(time, result)
The documentation for this class was generated from the following files:
- C:/Git/VxSDK-Samples/CppSamples/Source/Common/Utility.h
- C:/Git/VxSDK-Samples/CppSamples/Source/Common/Utility.cpp