From 677dc4667d473bc23f458c3f9e121d7c9fe02b0f Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Fri, 25 Mar 2016 09:12:24 -0400 Subject: [PATCH] Replace CMAKE_INSTALL_PREFIX from default config if it hasn't been swapped out by CMAKE --- src/openalpr/config.cpp | 5 +++++ src/openalpr/utility.cpp | 9 +++++++++ src/openalpr/utility.h | 2 ++ 3 files changed, 16 insertions(+) diff --git a/src/openalpr/config.cpp b/src/openalpr/config.cpp index 628f89b..1b085b2 100644 --- a/src/openalpr/config.cpp +++ b/src/openalpr/config.cpp @@ -167,6 +167,11 @@ namespace alpr runtimeBaseDir = getString(ini,defaultIni, "", "runtime_dir", DEFAULT_RUNTIME_DATA_DIR); + // Special hack to allow config files to work if the package hasn't been installed + // Cmake will do this replacement on deploy, but this is useful in development + if (runtimeBaseDir.find("${CMAKE_INSTALL_PREFIX}") >= 0) + runtimeBaseDir = replaceAll(runtimeBaseDir, "${CMAKE_INSTALL_PREFIX}", INSTALL_PREFIX); + std::string detectorString = getString(ini, defaultIni, "", "detector", "lbpcpu"); std::transform(detectorString.begin(), detectorString.end(), detectorString.begin(), ::tolower); diff --git a/src/openalpr/utility.cpp b/src/openalpr/utility.cpp index 7ec9177..36752f9 100644 --- a/src/openalpr/utility.cpp +++ b/src/openalpr/utility.cpp @@ -613,6 +613,15 @@ int levenshteinDistance (const std::string &s1, const std::string &s2, int max) return ss.str(); } + std::string replaceAll(std::string str, const std::string& from, const std::string& to) { + size_t start_pos = 0; + while((start_pos = str.find(from, start_pos)) != std::string::npos) { + str.replace(start_pos, from.length(), to); + start_pos += to.length(); // Handles case where 'to' is a substring of 'from' + } + return str; + } + // trim from start std::string <rim(std::string &s) { s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun(std::isspace)))); diff --git a/src/openalpr/utility.h b/src/openalpr/utility.h index 83889d0..000752e 100644 --- a/src/openalpr/utility.h +++ b/src/openalpr/utility.h @@ -115,6 +115,8 @@ namespace alpr std::string toString(float value); std::string toString(double value); + std::string replaceAll(std::string str, const std::string& from, const std::string& to); + std::string <rim(std::string &s); std::string &rtrim(std::string &s); std::string &trim(std::string &s);