Cheetah Software  1.0
utilities.cpp
Go to the documentation of this file.
2 
3 #include <ctime>
4 #include <iomanip>
5 #include <iostream>
6 
7 void writeStringToFile(const std::string& fileName,
8  const std::string& fileData) {
9  FILE* fp = fopen(fileName.c_str(), "w");
10  if (!fp) {
11  printf("Failed to fopen %s\n", fileName.c_str());
12  throw std::runtime_error("Failed to open file");
13  }
14  fprintf(fp, "%s", fileData.c_str());
15  fclose(fp);
16 }
17 
18 std::string getCurrentTimeAndDate() {
19  auto t = std::time(nullptr);
20  auto tm = *std::localtime(&t);
21  std::ostringstream ss;
22  ss << std::put_time(&tm, "%c");
23  return ss.str();
24 }
25 
30 std::string getConfigDirectoryPath() { return "../config/"; }
31 
32 std::string getLcmUrl(s64 ttl) {
33  assert(ttl >= 0 && ttl <= 255);
34  return "udpm://239.255.76.67:7667?ttl=" + std::to_string(ttl);
35 }
void writeStringToFile(const std::string &fileName, const std::string &fileData)
Definition: utilities.cpp:7
int64_t s64
Definition: cTypes.h:24
std::string getLcmUrl(s64 ttl)
Definition: utilities.cpp:32
std::string getConfigDirectoryPath()
Definition: utilities.cpp:30
std::string getCurrentTimeAndDate()
Definition: utilities.cpp:18