Compile opencv_test_core with cv::String instead of std::string
All tests passed!
This commit is contained in:
@@ -1,17 +1,14 @@
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
struct CommandLineParserParams
|
||||
{
|
||||
public:
|
||||
std::string help_message;
|
||||
std::string def_value;
|
||||
std::vector<std::string> keys;
|
||||
cv::String help_message;
|
||||
cv::String def_value;
|
||||
std::vector<cv::String> keys;
|
||||
int number;
|
||||
};
|
||||
|
||||
@@ -19,27 +16,27 @@ public:
|
||||
struct CommandLineParser::Impl
|
||||
{
|
||||
bool error;
|
||||
std::string error_message;
|
||||
std::string about_message;
|
||||
cv::String error_message;
|
||||
cv::String about_message;
|
||||
|
||||
std::string path_to_app;
|
||||
std::string app_name;
|
||||
cv::String path_to_app;
|
||||
cv::String app_name;
|
||||
|
||||
std::vector<CommandLineParserParams> data;
|
||||
|
||||
std::vector<std::string> split_range_string(const std::string& str, char fs, char ss) const;
|
||||
std::vector<std::string> split_string(const std::string& str, char symbol = ' ', bool create_empty_item = false) const;
|
||||
std::string cat_string(const std::string& str) const;
|
||||
std::vector<cv::String> split_range_string(const cv::String& str, char fs, char ss) const;
|
||||
std::vector<cv::String> split_string(const cv::String& str, char symbol = ' ', bool create_empty_item = false) const;
|
||||
cv::String cat_string(const cv::String& str) const;
|
||||
|
||||
void apply_params(const std::string& key, const std::string& value);
|
||||
void apply_params(int i, std::string value);
|
||||
void apply_params(const cv::String& key, const cv::String& value);
|
||||
void apply_params(int i, cv::String value);
|
||||
|
||||
void sort_params();
|
||||
int refcount;
|
||||
};
|
||||
|
||||
|
||||
static std::string get_type_name(int type)
|
||||
static cv::String get_type_name(int type)
|
||||
{
|
||||
if( type == Param::INT )
|
||||
return "int";
|
||||
@@ -56,9 +53,9 @@ static std::string get_type_name(int type)
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
static void from_str(const std::string& str, int type, void* dst)
|
||||
static void from_str(const cv::String& str, int type, void* dst)
|
||||
{
|
||||
std::stringstream ss(str);
|
||||
std::stringstream ss(str.c_str());
|
||||
if( type == Param::INT )
|
||||
ss >> *(int*)dst;
|
||||
else if( type == Param::UNSIGNED_INT )
|
||||
@@ -70,20 +67,20 @@ static void from_str(const std::string& str, int type, void* dst)
|
||||
else if( type == Param::REAL )
|
||||
ss >> *(double*)dst;
|
||||
else if( type == Param::STRING )
|
||||
*(std::string*)dst = str;
|
||||
*(cv::String*)dst = str;
|
||||
else
|
||||
throw cv::Exception(CV_StsBadArg, "unknown/unsupported parameter type", "", __FILE__, __LINE__);
|
||||
|
||||
if (ss.fail())
|
||||
{
|
||||
std::string err_msg = "can not convert: [" + str +
|
||||
cv::String err_msg = "can not convert: [" + str +
|
||||
+ "] to [" + get_type_name(type) + "]";
|
||||
|
||||
throw cv::Exception(CV_StsBadArg, err_msg, "", __FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
void CommandLineParser::getByName(const std::string& name, bool space_delete, int type, void* dst) const
|
||||
void CommandLineParser::getByName(const cv::String& name, bool space_delete, int type, void* dst) const
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -93,7 +90,7 @@ void CommandLineParser::getByName(const std::string& name, bool space_delete, in
|
||||
{
|
||||
if (name.compare(impl->data[i].keys[j]) == 0)
|
||||
{
|
||||
std::string v = impl->data[i].def_value;
|
||||
cv::String v = impl->data[i].def_value;
|
||||
if (space_delete)
|
||||
v = impl->cat_string(v);
|
||||
from_str(v, type, dst);
|
||||
@@ -102,12 +99,12 @@ void CommandLineParser::getByName(const std::string& name, bool space_delete, in
|
||||
}
|
||||
}
|
||||
impl->error = true;
|
||||
impl->error_message += "Unknown parametes " + name + "\n";
|
||||
impl->error_message = impl->error_message + "Unknown parametes " + name + "\n";
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
impl->error = true;
|
||||
impl->error_message += "Exception: " + std::string(e.what()) + "\n";
|
||||
impl->error_message = impl->error_message + "Exception: " + cv::String(e.what()) + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,19 +117,19 @@ void CommandLineParser::getByIndex(int index, bool space_delete, int type, void*
|
||||
{
|
||||
if (impl->data[i].number == index)
|
||||
{
|
||||
std::string v = impl->data[i].def_value;
|
||||
cv::String v = impl->data[i].def_value;
|
||||
if (space_delete == true) v = impl->cat_string(v);
|
||||
from_str(v, type, dst);
|
||||
return;
|
||||
}
|
||||
}
|
||||
impl->error = true;
|
||||
impl->error_message += "Unknown parametes #" + format("%d", index) + "\n";
|
||||
impl->error_message = impl->error_message + "Unknown parametes #" + format("%d", index) + "\n";
|
||||
}
|
||||
catch(std::exception & e)
|
||||
{
|
||||
impl->error = true;
|
||||
impl->error_message += "Exception: " + std::string(e.what()) + "\n";
|
||||
impl->error_message = impl->error_message + "Exception: " + cv::String(e.what()) + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,34 +149,34 @@ static bool cmp_params(const CommandLineParserParams & p1, const CommandLinePars
|
||||
return true;
|
||||
}
|
||||
|
||||
CommandLineParser::CommandLineParser(int argc, const char* const argv[], const std::string& keys)
|
||||
CommandLineParser::CommandLineParser(int argc, const char* const argv[], const cv::String& keys)
|
||||
{
|
||||
impl = new Impl;
|
||||
impl->refcount = 1;
|
||||
|
||||
// path to application
|
||||
size_t pos_s = std::string(argv[0]).find_last_of("/\\");
|
||||
if (pos_s == std::string::npos)
|
||||
size_t pos_s = cv::String(argv[0]).find_last_of("/\\");
|
||||
if (pos_s == cv::String::npos)
|
||||
{
|
||||
impl->path_to_app = "";
|
||||
impl->app_name = std::string(argv[0]);
|
||||
impl->app_name = cv::String(argv[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
impl->path_to_app = std::string(argv[0]).substr(0, pos_s);
|
||||
impl->app_name = std::string(argv[0]).substr(pos_s + 1, std::string(argv[0]).length() - pos_s);
|
||||
impl->path_to_app = cv::String(argv[0]).substr(0, pos_s);
|
||||
impl->app_name = cv::String(argv[0]).substr(pos_s + 1, cv::String(argv[0]).length() - pos_s);
|
||||
}
|
||||
|
||||
impl->error = false;
|
||||
impl->error_message = "";
|
||||
|
||||
// parse keys
|
||||
std::vector<std::string> k = impl->split_range_string(keys, '{', '}');
|
||||
std::vector<cv::String> k = impl->split_range_string(keys, '{', '}');
|
||||
|
||||
int jj = 0;
|
||||
for (size_t i = 0; i < k.size(); i++)
|
||||
{
|
||||
std::vector<std::string> l = impl->split_string(k[i], '|', true);
|
||||
std::vector<cv::String> l = impl->split_string(k[i], '|', true);
|
||||
CommandLineParserParams p;
|
||||
p.keys = impl->split_string(l[0]);
|
||||
p.def_value = l[1];
|
||||
@@ -206,11 +203,11 @@ CommandLineParser::CommandLineParser(int argc, const char* const argv[], const s
|
||||
jj = 0;
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
std::string s = std::string(argv[i]);
|
||||
cv::String s = cv::String(argv[i]);
|
||||
|
||||
if (s.find('=') != std::string::npos && s.find('=') < s.length())
|
||||
if (s.find('=') != cv::String::npos && s.find('=') < s.length())
|
||||
{
|
||||
std::vector<std::string> k_v = impl->split_string(s, '=', true);
|
||||
std::vector<cv::String> k_v = impl->split_string(s, '=', true);
|
||||
for (int h = 0; h < 2; h++)
|
||||
{
|
||||
if (k_v[0][0] == '-')
|
||||
@@ -256,12 +253,12 @@ CommandLineParser& CommandLineParser::operator = (const CommandLineParser& parse
|
||||
return *this;
|
||||
}
|
||||
|
||||
void CommandLineParser::about(const std::string& message)
|
||||
void CommandLineParser::about(const cv::String& message)
|
||||
{
|
||||
impl->about_message = message;
|
||||
}
|
||||
|
||||
void CommandLineParser::Impl::apply_params(const std::string& key, const std::string& value)
|
||||
void CommandLineParser::Impl::apply_params(const cv::String& key, const cv::String& value)
|
||||
{
|
||||
for (size_t i = 0; i < data.size(); i++)
|
||||
{
|
||||
@@ -276,7 +273,7 @@ void CommandLineParser::Impl::apply_params(const std::string& key, const std::st
|
||||
}
|
||||
}
|
||||
|
||||
void CommandLineParser::Impl::apply_params(int i, std::string value)
|
||||
void CommandLineParser::Impl::apply_params(int i, cv::String value)
|
||||
{
|
||||
for (size_t j = 0; j < data.size(); j++)
|
||||
{
|
||||
@@ -292,34 +289,34 @@ void CommandLineParser::Impl::sort_params()
|
||||
{
|
||||
for (size_t i = 0; i < data.size(); i++)
|
||||
{
|
||||
sort(data[i].keys.begin(), data[i].keys.end());
|
||||
std::sort(data[i].keys.begin(), data[i].keys.end());
|
||||
}
|
||||
|
||||
std::sort (data.begin(), data.end(), cmp_params);
|
||||
}
|
||||
|
||||
std::string CommandLineParser::Impl::cat_string(const std::string& str) const
|
||||
cv::String CommandLineParser::Impl::cat_string(const cv::String& str) const
|
||||
{
|
||||
int left = 0, right = (int)str.length();
|
||||
while( left <= right && str[left] == ' ' )
|
||||
left++;
|
||||
while( right > left && str[right-1] == ' ' )
|
||||
right--;
|
||||
return left >= right ? std::string("") : str.substr(left, right-left);
|
||||
return left >= right ? cv::String("") : str.substr(left, right-left);
|
||||
}
|
||||
|
||||
std::string CommandLineParser::getPathToApplication() const
|
||||
cv::String CommandLineParser::getPathToApplication() const
|
||||
{
|
||||
return impl->path_to_app;
|
||||
}
|
||||
|
||||
bool CommandLineParser::has(const std::string& name) const
|
||||
bool CommandLineParser::has(const cv::String& name) const
|
||||
{
|
||||
for (size_t i = 0; i < impl->data.size(); i++)
|
||||
{
|
||||
for (size_t j = 0; j < impl->data[i].keys.size(); j++)
|
||||
{
|
||||
if (name.compare(impl->data[i].keys[j]) == 0 && std::string("true").compare(impl->data[i].def_value) == 0)
|
||||
if (name.compare(impl->data[i].keys[j]) == 0 && cv::String("true").compare(impl->data[i].def_value) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -337,86 +334,87 @@ void CommandLineParser::printErrors() const
|
||||
{
|
||||
if (impl->error)
|
||||
{
|
||||
std::cout << std::endl << "ERRORS:" << std::endl << impl->error_message << std::endl;
|
||||
printf("\nERRORS:\n%s\n", impl->error_message.c_str());
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
void CommandLineParser::printMessage() const
|
||||
{
|
||||
if (impl->about_message != "")
|
||||
std::cout << impl->about_message << std::endl;
|
||||
printf("%s\n", impl->about_message.c_str());
|
||||
|
||||
std::cout << "Usage: " << impl->app_name << " [params] ";
|
||||
printf("Usage: %s [params] ", impl->app_name.c_str());
|
||||
|
||||
for (size_t i = 0; i < impl->data.size(); i++)
|
||||
{
|
||||
if (impl->data[i].number > -1)
|
||||
{
|
||||
std::string name = impl->data[i].keys[0].substr(1, impl->data[i].keys[0].length() - 1);
|
||||
std::cout << name << " ";
|
||||
cv::String name = impl->data[i].keys[0].substr(1, impl->data[i].keys[0].length() - 1);
|
||||
printf("%s ", name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << std::endl << std::endl;
|
||||
printf("\n\n");
|
||||
|
||||
for (size_t i = 0; i < impl->data.size(); i++)
|
||||
{
|
||||
if (impl->data[i].number == -1)
|
||||
{
|
||||
std::cout << "\t";
|
||||
printf("\t");
|
||||
for (size_t j = 0; j < impl->data[i].keys.size(); j++)
|
||||
{
|
||||
std::string k = impl->data[i].keys[j];
|
||||
cv::String k = impl->data[i].keys[j];
|
||||
if (k.length() > 1)
|
||||
{
|
||||
std::cout << "--";
|
||||
printf("--");
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "-";
|
||||
printf("-");
|
||||
}
|
||||
std::cout << k;
|
||||
printf("%s", k.c_str());
|
||||
|
||||
if (j != impl->data[i].keys.size() - 1)
|
||||
{
|
||||
std::cout << ", ";
|
||||
printf(", ");
|
||||
}
|
||||
}
|
||||
std::string dv = impl->cat_string(impl->data[i].def_value);
|
||||
cv::String dv = impl->cat_string(impl->data[i].def_value);
|
||||
if (dv.compare("") != 0)
|
||||
{
|
||||
std::cout << " (value:" << dv << ")";
|
||||
printf(" (value:%s)", dv.c_str());
|
||||
}
|
||||
std::cout << std::endl << "\t\t" << impl->data[i].help_message << std::endl;
|
||||
printf("\n\t\t%s\n", impl->data[i].help_message.c_str());
|
||||
}
|
||||
}
|
||||
std::cout << std::endl;
|
||||
printf("\n");
|
||||
|
||||
for (size_t i = 0; i < impl->data.size(); i++)
|
||||
{
|
||||
if (impl->data[i].number != -1)
|
||||
{
|
||||
std::cout << "\t";
|
||||
std::string k = impl->data[i].keys[0];
|
||||
printf("\t");
|
||||
cv::String k = impl->data[i].keys[0];
|
||||
k = k.substr(1, k.length() - 1);
|
||||
|
||||
std::cout << k;
|
||||
printf("%s", k.c_str());
|
||||
|
||||
std::string dv = impl->cat_string(impl->data[i].def_value);
|
||||
cv::String dv = impl->cat_string(impl->data[i].def_value);
|
||||
if (dv.compare("") != 0)
|
||||
{
|
||||
std::cout << " (value:" << dv << ")";
|
||||
printf(" (value:%s)", dv.c_str());
|
||||
}
|
||||
std::cout << std::endl << "\t\t" << impl->data[i].help_message << std::endl;
|
||||
printf("\n\t\t%s\n", impl->data[i].help_message.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> CommandLineParser::Impl::split_range_string(const std::string& _str, char fs, char ss) const
|
||||
std::vector<cv::String> CommandLineParser::Impl::split_range_string(const cv::String& _str, char fs, char ss) const
|
||||
{
|
||||
std::string str = _str;
|
||||
std::vector<std::string> vec;
|
||||
std::string word = "";
|
||||
cv::String str = _str;
|
||||
std::vector<cv::String> vec;
|
||||
cv::String word = "";
|
||||
bool begin = false;
|
||||
|
||||
while (!str.empty())
|
||||
@@ -426,13 +424,13 @@ std::vector<std::string> CommandLineParser::Impl::split_range_string(const std::
|
||||
if (begin == true)
|
||||
{
|
||||
throw cv::Exception(CV_StsParseError,
|
||||
std::string("error in split_range_string(")
|
||||
cv::String("error in split_range_string(")
|
||||
+ str
|
||||
+ std::string(", ")
|
||||
+ std::string(1, fs)
|
||||
+ std::string(", ")
|
||||
+ std::string(1, ss)
|
||||
+ std::string(")"),
|
||||
+ cv::String(", ")
|
||||
+ cv::String(1, fs)
|
||||
+ cv::String(", ")
|
||||
+ cv::String(1, ss)
|
||||
+ cv::String(")"),
|
||||
"", __FILE__, __LINE__
|
||||
);
|
||||
}
|
||||
@@ -446,13 +444,13 @@ std::vector<std::string> CommandLineParser::Impl::split_range_string(const std::
|
||||
if (begin == false)
|
||||
{
|
||||
throw cv::Exception(CV_StsParseError,
|
||||
std::string("error in split_range_string(")
|
||||
cv::String("error in split_range_string(")
|
||||
+ str
|
||||
+ std::string(", ")
|
||||
+ std::string(1, fs)
|
||||
+ std::string(", ")
|
||||
+ std::string(1, ss)
|
||||
+ std::string(")"),
|
||||
+ cv::String(", ")
|
||||
+ cv::String(1, fs)
|
||||
+ cv::String(", ")
|
||||
+ cv::String(1, ss)
|
||||
+ cv::String(")"),
|
||||
"", __FILE__, __LINE__
|
||||
);
|
||||
}
|
||||
@@ -462,7 +460,7 @@ std::vector<std::string> CommandLineParser::Impl::split_range_string(const std::
|
||||
|
||||
if (begin == true)
|
||||
{
|
||||
word += str[0];
|
||||
word = word + str[0];
|
||||
}
|
||||
str = str.substr(1, str.length() - 1);
|
||||
}
|
||||
@@ -470,13 +468,13 @@ std::vector<std::string> CommandLineParser::Impl::split_range_string(const std::
|
||||
if (begin == true)
|
||||
{
|
||||
throw cv::Exception(CV_StsParseError,
|
||||
std::string("error in split_range_string(")
|
||||
cv::String("error in split_range_string(")
|
||||
+ str
|
||||
+ std::string(", ")
|
||||
+ std::string(1, fs)
|
||||
+ std::string(", ")
|
||||
+ std::string(1, ss)
|
||||
+ std::string(")"),
|
||||
+ cv::String(", ")
|
||||
+ cv::String(1, fs)
|
||||
+ cv::String(", ")
|
||||
+ cv::String(1, ss)
|
||||
+ cv::String(")"),
|
||||
"", __FILE__, __LINE__
|
||||
);
|
||||
}
|
||||
@@ -484,11 +482,11 @@ std::vector<std::string> CommandLineParser::Impl::split_range_string(const std::
|
||||
return vec;
|
||||
}
|
||||
|
||||
std::vector<std::string> CommandLineParser::Impl::split_string(const std::string& _str, char symbol, bool create_empty_item) const
|
||||
std::vector<cv::String> CommandLineParser::Impl::split_string(const cv::String& _str, char symbol, bool create_empty_item) const
|
||||
{
|
||||
std::string str = _str;
|
||||
std::vector<std::string> vec;
|
||||
std::string word = "";
|
||||
cv::String str = _str;
|
||||
std::vector<cv::String> vec;
|
||||
cv::String word = "";
|
||||
|
||||
while (!str.empty())
|
||||
{
|
||||
@@ -502,7 +500,7 @@ std::vector<std::string> CommandLineParser::Impl::split_string(const std::string
|
||||
}
|
||||
else
|
||||
{
|
||||
word += str[0];
|
||||
word = word + str[0];
|
||||
}
|
||||
str = str.substr(1, str.length() - 1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user