Skip to content

Commit

Permalink
cleanup common utils (#46)
Browse files Browse the repository at this point in the history
* cleanup common utils

* mingw copy plotly.js case
  • Loading branch information
ValeryStk authored Nov 15, 2023
1 parent c870358 commit 6b8d463
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
6 changes: 4 additions & 2 deletions Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # Windows specific, for goog
MESSAGE("_____________________ Copy Plotlylib to Tests step ___________________________________________")
if(WIN32)
file(COPY ${CMAKE_SOURCE_DIR}/plotly_maker/plotly-2.27.0.min.js DESTINATION
${CMAKE_CURRENT_BINARY_DIR}/Debug/davis_htmls)
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/davis_htmls)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
file(COPY ${CMAKE_SOURCE_DIR}/plotly_maker/plotly-2.27.0.min.js DESTINATION
${CMAKE_CURRENT_BINARY_DIR}/Release/davis_htmls)
${CMAKE_CURRENT_BINARY_DIR}/davis_htmls)
endif()
endif(WIN32)

add_executable(${PROJECT_NAME}_plotly_tests PlotlyLibTest.cpp)
Expand Down
19 changes: 11 additions & 8 deletions common_utils/common_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@


namespace {

using std::string;

#ifdef _WIN32
#include <direct.h>
#include <windows.h>
Expand All @@ -13,16 +16,16 @@ namespace {
#include <unistd.h>
#endif

inline bool is_file_exists(const std::string& file_name) {
inline bool is_file_exists(const string& file_name) {
std::ifstream file(file_name.c_str());
if (!file) {
return false;
}
return true;
}

void openFileBySystem(const std::string& file_name) {
std::string command;
void openFileBySystem(const string& file_name) {
string command;
#ifdef _WIN32
command = "start ";
#elif __APPLE__
Expand All @@ -40,10 +43,10 @@ void openFileBySystem(const std::string& file_name) {

namespace davis {

std::string getCurrentPath() {
string getCurrentPath() {
char buffer[1024];
char* answer = getcwd(buffer, sizeof(buffer));
std::string s_cwd;
string s_cwd;
if (answer) {
s_cwd = answer;
}
Expand All @@ -54,8 +57,8 @@ bool isPlotlyScriptExists() {
return is_file_exists(kPlotlyJsWorkPath);
};

bool saveStringToFile(const std::string& file_name,
const std::string& data) {
bool saveStringToFile(const string& file_name,
const string& data) {
std::ofstream out(file_name);
if (out.is_open()) {
out << data.c_str();
Expand All @@ -66,7 +69,7 @@ bool saveStringToFile(const std::string& file_name,
}


void openPlotlyHtml(const std::string& file_name) {
void openPlotlyHtml(const string& file_name) {
openFileBySystem(file_name);
}

Expand Down
7 changes: 4 additions & 3 deletions common_utils/common_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@

namespace davis {

using std::string;

std::string getCurrentPath();

bool isPlotlyScriptExists();

bool saveStringToFile(const std::string& file_name,
const std::string& data);
bool saveStringToFile(const string& file_name,
const string& data);

void mayBeCreateJsWorkingFolder();

void sleepMs(unsigned long milisec);

void openPlotlyHtml(const std::string& file_name);
void openPlotlyHtml(const string& file_name);

// Now it doesn't work.
bool deleteFolder(const char* fname);
Expand Down

0 comments on commit 6b8d463

Please sign in to comment.