diff --git a/array_core/array_core.h b/array_core/array_core.h index a8d24c4..d10b7c2 100644 --- a/array_core/array_core.h +++ b/array_core/array_core.h @@ -42,43 +42,44 @@ bool show(const T* data, uint64_t count, const string& htmlPageName = dvs::makeU template bool save(const T* data, uint64_t count, const string& filename, const configSaveToDisk& configuration = configSaveToDisk()); -//! (chart) 1-dimensional container -template()))>, - typename = std::enable_if_t> > +//! +(chart) 1-dimensional container +template()))>::type, + typename Enable = typename std::enable_if::value>::type> bool show(C const& container, const string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config()); template()))>, - typename = std::enable_if_t> > + typename T = typename std::decay()))>::type, + typename Enable = typename std::enable_if::value>::type> bool save(C const& container, const string& filename, const configSaveToDisk& configuration = configSaveToDisk()); -//! (chart) Two 1-dimensional container for X-Y plot -template()))>, - typename = std::enable_if_t> > +//! +(chart) Two 1-dimensional container for X-Y plot +template()))>::type, + typename Enable = typename std::enable_if::value>::type> bool show(C const& containerX, C const& containerY, const string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config()); -template()))>, - typename = std::enable_if_t> > +template()))>::type, + typename Enable = typename std::enable_if::value>::type> bool save(C const& containerX, C const& containerY, const string& filename, const configSaveToDisk& configuration = configSaveToDisk()); //! (chart / matrix) 2-dimensional container template()))>, - typename T = std::decay_t()))>, - typename = std::enable_if_t> > + typename E = typename std::decay()))>::type, + typename T = typename std::decay()))>::type, + typename Enable = typename std::enable_if::value>::type> bool show(C const& container_of_containers, const string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config()); template()))>, - typename T = std::decay_t()))>, - typename = std::enable_if_t> > + typename E = typename std::decay()))>::type, + typename T = typename std::decay()))>::type, + typename Enable = typename std::enable_if::value>::type> bool save(C const& container_of_containers, const string& filename, const configSaveToDisk& configuration = configSaveToDisk()); + // *********************************** // template functions implementations: // *********************************** @@ -204,7 +205,7 @@ bool show(C const& containerX, C const& containerY, const string& htmlPageName, return res; } -template +template bool save(C const& containerX, C const& containerY, const string& filename, const configSaveToDisk& configuration) { if (containerX.size() != containerY.size()) { return false; @@ -262,7 +263,7 @@ bool show(C const& container_of_containers, const string& htmlPageName, const Co return res; } -template +template bool save(C const& container_of_containers, const string& filename, const configSaveToDisk& configuration) { vector> vecVec; vecVec.reserve(container_of_containers.size()); diff --git a/common_utils/common_utils.cpp b/common_utils/common_utils.cpp index 8bceee2..065d1b2 100644 --- a/common_utils/common_utils.cpp +++ b/common_utils/common_utils.cpp @@ -346,17 +346,23 @@ string vectorToString(const vector& vec) { return oss.str(); } -string makeUniqueDavisHtmlName() { +std::string makeUniqueDavisHtmlName() { sleepMicroSec(1); - - auto now = std::chrono::system_clock::now(); - auto milliseconds = std::chrono::duration_cast(now.time_since_epoch()) % 1000; - auto in_time_t = std::chrono::system_clock::to_time_t(now); - std::stringstream ss; - ss << std::put_time(std::localtime(&in_time_t), "%Y-%m-%d_%H_%M_%S"); - ss << '_' << std::setfill('0') - << std::setw(3) - << milliseconds.count(); + using namespace std::chrono; + auto now = system_clock::now(); + auto ms_since_epoch = duration_cast(now.time_since_epoch()).count(); + int ms = static_cast(ms_since_epoch % 1000); + std::time_t in_time_t = system_clock::to_time_t(now); + std::tm tm{}; +#if defined(_MSC_VER) + localtime_s(&tm, &in_time_t); +#else + if (std::tm* p = std::localtime(&in_time_t)) + tm = *p; +#endif + std::ostringstream ss; + ss << std::put_time(&tm, "%Y-%m-%d_%H_%M_%S") + << '_' << std::setfill('0') << std::setw(3) << ms; return ss.str(); } diff --git a/common_utils/common_utils.h b/common_utils/common_utils.h index 478871c..473e00e 100644 --- a/common_utils/common_utils.h +++ b/common_utils/common_utils.h @@ -149,15 +149,14 @@ bool saveVecVec(const vector>& vecVec, const string& filename, dv::con //! convert any container to std::vector with G type template()))>, - typename = std::enable_if_t>> -vector vecFromTemplate(const C& container) { - vector vec(container.size()); - uint64_t i = 0; - for (auto v : container) { - vec[i] = static_cast(v); - ++i; + typename C, //https://devblogs.microsoft.com/oldnewthing/20190619-00/?p=102599 + typename T = typename std::decay()))>::type, + typename Enable = typename std::enable_if::value>::type> +std::vector vecFromTemplate(const C& container) { + std::vector vec; + vec.reserve(static_cast(std::distance(std::begin(container), std::end(container)))); + for (auto const& v : container) { + vec.push_back(static_cast(v)); } return vec; } @@ -181,7 +180,7 @@ std::string reverseString(const std::string& input); template std::vector> readBinaryFile(const std::string& filePath, - size_t rowLength) { +size_t rowLength) { std::ifstream file(filePath, std::ios::binary); if (!file) { throw std::runtime_error("Cannot open file"); diff --git a/davis_one/davis.cpp b/davis_one/davis.cpp index d29c8bc..4a518f5 100644 --- a/davis_one/davis.cpp +++ b/davis_one/davis.cpp @@ -1100,17 +1100,23 @@ string vectorToString(const vector& vec) { return oss.str(); } -string makeUniqueDavisHtmlName() { +std::string makeUniqueDavisHtmlName() { sleepMicroSec(1); - - auto now = std::chrono::system_clock::now(); - auto milliseconds = std::chrono::duration_cast(now.time_since_epoch()) % 1000; - auto in_time_t = std::chrono::system_clock::to_time_t(now); - std::stringstream ss; - ss << std::put_time(std::localtime(&in_time_t), "%Y-%m-%d_%H_%M_%S"); - ss << '_' << std::setfill('0') - << std::setw(3) - << milliseconds.count(); + using namespace std::chrono; + auto now = system_clock::now(); + auto ms_since_epoch = duration_cast(now.time_since_epoch()).count(); + int ms = static_cast(ms_since_epoch % 1000); + std::time_t in_time_t = system_clock::to_time_t(now); + std::tm tm{}; +#if defined(_MSC_VER) + localtime_s(&tm, &in_time_t); +#else + if (std::tm* p = std::localtime(&in_time_t)) + tm = *p; +#endif + std::ostringstream ss; + ss << std::put_time(&tm, "%Y-%m-%d_%H_%M_%S") + << '_' << std::setfill('0') << std::setw(3) << ms; return ss.str(); } diff --git a/davis_one/davis.h b/davis_one/davis.h index ec869ce..c3990e9 100644 --- a/davis_one/davis.h +++ b/davis_one/davis.h @@ -364,15 +364,14 @@ bool saveVecVec(const vector>& vecVec, const string& filename, dv::con //! convert any container to std::vector with G type template()))>, - typename = std::enable_if_t>> -vector vecFromTemplate(const C& container) { - vector vec(container.size()); - uint64_t i = 0; - for (auto v : container) { - vec[i] = static_cast(v); - ++i; + typename C, //https://devblogs.microsoft.com/oldnewthing/20190619-00/?p=102599 + typename T = typename std::decay()))>::type, + typename Enable = typename std::enable_if::value>::type> +std::vector vecFromTemplate(const C& container) { + std::vector vec; + vec.reserve(static_cast(std::distance(std::begin(container), std::end(container)))); + for (auto const& v : container) { + vec.push_back(static_cast(v)); } return vec; } @@ -396,7 +395,7 @@ std::string reverseString(const std::string& input); template std::vector> readBinaryFile(const std::string& filePath, - size_t rowLength) { +size_t rowLength) { std::ifstream file(filePath, std::ios::binary); if (!file) { throw std::runtime_error("Cannot open file"); @@ -529,43 +528,44 @@ bool show(const T* data, uint64_t count, const string& htmlPageName = dvs::makeU template bool save(const T* data, uint64_t count, const string& filename, const configSaveToDisk& configuration = configSaveToDisk()); -//! (chart) 1-dimensional container -template()))>, - typename = std::enable_if_t> > +//! +(chart) 1-dimensional container +template()))>::type, + typename Enable = typename std::enable_if::value>::type> bool show(C const& container, const string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config()); template()))>, - typename = std::enable_if_t> > + typename T = typename std::decay()))>::type, + typename Enable = typename std::enable_if::value>::type> bool save(C const& container, const string& filename, const configSaveToDisk& configuration = configSaveToDisk()); -//! (chart) Two 1-dimensional container for X-Y plot -template()))>, - typename = std::enable_if_t> > +//! +(chart) Two 1-dimensional container for X-Y plot +template()))>::type, + typename Enable = typename std::enable_if::value>::type> bool show(C const& containerX, C const& containerY, const string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config()); -template()))>, - typename = std::enable_if_t> > +template()))>::type, + typename Enable = typename std::enable_if::value>::type> bool save(C const& containerX, C const& containerY, const string& filename, const configSaveToDisk& configuration = configSaveToDisk()); //! (chart / matrix) 2-dimensional container template()))>, - typename T = std::decay_t()))>, - typename = std::enable_if_t> > + typename E = typename std::decay()))>::type, + typename T = typename std::decay()))>::type, + typename Enable = typename std::enable_if::value>::type> bool show(C const& container_of_containers, const string& htmlPageName = dvs::makeUniqueDavisHtmlName(), const Config& configuration = Config()); template()))>, - typename T = std::decay_t()))>, - typename = std::enable_if_t> > + typename E = typename std::decay()))>::type, + typename T = typename std::decay()))>::type, + typename Enable = typename std::enable_if::value>::type> bool save(C const& container_of_containers, const string& filename, const configSaveToDisk& configuration = configSaveToDisk()); + // *********************************** // template functions implementations: // *********************************** @@ -691,7 +691,7 @@ bool show(C const& containerX, C const& containerY, const string& htmlPageName, return res; } -template +template bool save(C const& containerX, C const& containerY, const string& filename, const configSaveToDisk& configuration) { if (containerX.size() != containerY.size()) { return false; @@ -749,7 +749,7 @@ bool show(C const& container_of_containers, const string& htmlPageName, const Co return res; } -template +template bool save(C const& container_of_containers, const string& filename, const configSaveToDisk& configuration) { vector> vecVec; vecVec.reserve(container_of_containers.size()); diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index 3d0064e..589ee31 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -10,7 +10,9 @@ set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD") +if (MSVC) + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD") +endif() set(CMAKE_WIN32_EXECUTABLE ON) # QtCreator supports the following variables for Android, which are identical to qmake Android variables.