diff --git a/modules/core/include/opencv2/core/cvstd.hpp b/modules/core/include/opencv2/core/cvstd.hpp index ec2258bb2a..69846f7ab6 100644 --- a/modules/core/include/opencv2/core/cvstd.hpp +++ b/modules/core/include/opencv2/core/cvstd.hpp @@ -450,586 +450,44 @@ Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& class CV_EXPORTS FileNode; //for string constructor from FileNode -class CV_EXPORTS String -{ -public: - typedef char value_type; - typedef char& reference; - typedef const char& const_reference; - typedef char* pointer; - typedef const char* const_pointer; - typedef ptrdiff_t difference_type; - typedef size_t size_type; - typedef char* iterator; - typedef const char* const_iterator; +typedef std::string String; - static const size_t npos = size_t(-1); - - String(); - String(const String& str); - String(const String& str, size_t pos, size_t len = npos); - String(const char* s); - String(const char* s, size_t n); - String(size_t n, char c); - String(const char* first, const char* last); - template String(Iterator first, Iterator last); - explicit String(const FileNode& fn); - ~String(); - - String& operator=(const String& str); - String& operator=(const char* s); - String& operator=(char c); - - String& operator+=(const String& str); - String& operator+=(const char* s); - String& operator+=(char c); - - size_t size() const; - size_t length() const; - - char operator[](size_t idx) const; - char operator[](int idx) const; - - const char* begin() const; - const char* end() const; - - const char* c_str() const; - - bool empty() const; - void clear(); - - int compare(const char* s) const; - int compare(const String& str) const; - - void swap(String& str); - String substr(size_t pos = 0, size_t len = npos) const; - - size_t find(const char* s, size_t pos, size_t n) const; - size_t find(char c, size_t pos = 0) const; - size_t find(const String& str, size_t pos = 0) const; - size_t find(const char* s, size_t pos = 0) const; - - size_t rfind(const char* s, size_t pos, size_t n) const; - size_t rfind(char c, size_t pos = npos) const; - size_t rfind(const String& str, size_t pos = npos) const; - size_t rfind(const char* s, size_t pos = npos) const; - - size_t find_first_of(const char* s, size_t pos, size_t n) const; - size_t find_first_of(char c, size_t pos = 0) const; - size_t find_first_of(const String& str, size_t pos = 0) const; - size_t find_first_of(const char* s, size_t pos = 0) const; - - size_t find_last_of(const char* s, size_t pos, size_t n) const; - size_t find_last_of(char c, size_t pos = npos) const; - size_t find_last_of(const String& str, size_t pos = npos) const; - size_t find_last_of(const char* s, size_t pos = npos) const; - - friend String operator+ (const String& lhs, const String& rhs); - friend String operator+ (const String& lhs, const char* rhs); - friend String operator+ (const char* lhs, const String& rhs); - friend String operator+ (const String& lhs, char rhs); - friend String operator+ (char lhs, const String& rhs); - - String toLowerCase() const; - - String(const std::string& str); - String(const std::string& str, size_t pos, size_t len = npos); - String& operator=(const std::string& str); - String& operator+=(const std::string& str); - operator std::string() const; - - friend String operator+ (const String& lhs, const std::string& rhs); - friend String operator+ (const std::string& lhs, const String& rhs); - -private: - char* cstr_; - size_t len_; - - char* allocate(size_t len); // len without trailing 0 - void deallocate(); - - String(int); // disabled and invalid. Catch invalid usages like, commandLineParser.has(0) problem -}; - -//! @} core_basic - -////////////////////////// cv::String implementation ///////////////////////// +#ifndef OPENCV_DISABLE_STRING_LOWER_UPPER_CONVERSIONS //! @cond IGNORED - -inline -String::String() - : cstr_(0), len_(0) -{} - -inline -String::String(const String& str) - : cstr_(str.cstr_), len_(str.len_) +namespace details { +// std::tolower is int->int +static inline char char_tolower(char ch) { - if (cstr_) - CV_XADD(((int*)cstr_)-1, 1); + return (char)std::tolower((int)ch); } - -inline -String::String(const String& str, size_t pos, size_t len) - : cstr_(0), len_(0) +// std::toupper is int->int +static inline char char_toupper(char ch) { - pos = min(pos, str.len_); - len = min(str.len_ - pos, len); - if (!len) return; - if (len == str.len_) - { - CV_XADD(((int*)str.cstr_)-1, 1); - cstr_ = str.cstr_; - len_ = str.len_; - return; - } - memcpy(allocate(len), str.cstr_ + pos, len); + return (char)std::toupper((int)ch); } - -inline -String::String(const char* s) - : cstr_(0), len_(0) -{ - if (!s) return; - size_t len = strlen(s); - if (!len) return; - memcpy(allocate(len), s, len); -} - -inline -String::String(const char* s, size_t n) - : cstr_(0), len_(0) -{ - if (!n) return; - if (!s) return; - memcpy(allocate(n), s, n); -} - -inline -String::String(size_t n, char c) - : cstr_(0), len_(0) -{ - if (!n) return; - memset(allocate(n), c, n); -} - -inline -String::String(const char* first, const char* last) - : cstr_(0), len_(0) -{ - size_t len = (size_t)(last - first); - if (!len) return; - memcpy(allocate(len), first, len); -} - -template inline -String::String(Iterator first, Iterator last) - : cstr_(0), len_(0) -{ - size_t len = (size_t)(last - first); - if (!len) return; - char* str = allocate(len); - while (first != last) - { - *str++ = *first; - ++first; - } -} - -inline -String::~String() -{ - deallocate(); -} - -inline -String& String::operator=(const String& str) -{ - if (&str == this) return *this; - - deallocate(); - if (str.cstr_) CV_XADD(((int*)str.cstr_)-1, 1); - cstr_ = str.cstr_; - len_ = str.len_; - return *this; -} - -inline -String& String::operator=(const char* s) -{ - deallocate(); - if (!s) return *this; - size_t len = strlen(s); - if (len) memcpy(allocate(len), s, len); - return *this; -} - -inline -String& String::operator=(char c) -{ - deallocate(); - allocate(1)[0] = c; - return *this; -} - -inline -String& String::operator+=(const String& str) -{ - *this = *this + str; - return *this; -} - -inline -String& String::operator+=(const char* s) -{ - *this = *this + s; - return *this; -} - -inline -String& String::operator+=(char c) -{ - *this = *this + c; - return *this; -} - -inline -size_t String::size() const -{ - return len_; -} - -inline -size_t String::length() const -{ - return len_; -} - -inline -char String::operator[](size_t idx) const -{ - return cstr_[idx]; -} - -inline -char String::operator[](int idx) const -{ - return cstr_[idx]; -} - -inline -const char* String::begin() const -{ - return cstr_; -} - -inline -const char* String::end() const -{ - return len_ ? cstr_ + len_ : NULL; -} - -inline -bool String::empty() const -{ - return len_ == 0; -} - -inline -const char* String::c_str() const -{ - return cstr_ ? cstr_ : ""; -} - -inline -void String::swap(String& str) -{ - cv::swap(cstr_, str.cstr_); - cv::swap(len_, str.len_); -} - -inline -void String::clear() -{ - deallocate(); -} - -inline -int String::compare(const char* s) const -{ - if (cstr_ == s) return 0; - return strcmp(c_str(), s); -} - -inline -int String::compare(const String& str) const -{ - if (cstr_ == str.cstr_) return 0; - return strcmp(c_str(), str.c_str()); -} - -inline -String String::substr(size_t pos, size_t len) const -{ - return String(*this, pos, len); -} - -inline -size_t String::find(const char* s, size_t pos, size_t n) const -{ - if (n == 0 || pos + n > len_) return npos; - const char* lmax = cstr_ + len_ - n; - for (const char* i = cstr_ + pos; i <= lmax; ++i) - { - size_t j = 0; - while (j < n && s[j] == i[j]) ++j; - if (j == n) return (size_t)(i - cstr_); - } - return npos; -} - -inline -size_t String::find(char c, size_t pos) const -{ - return find(&c, pos, 1); -} - -inline -size_t String::find(const String& str, size_t pos) const -{ - return find(str.c_str(), pos, str.len_); -} - -inline -size_t String::find(const char* s, size_t pos) const -{ - if (pos >= len_ || !s[0]) return npos; - const char* lmax = cstr_ + len_; - for (const char* i = cstr_ + pos; i < lmax; ++i) - { - size_t j = 0; - while (s[j] && s[j] == i[j]) - { if(i + j >= lmax) return npos; - ++j; - } - if (!s[j]) return (size_t)(i - cstr_); - } - return npos; -} - -inline -size_t String::rfind(const char* s, size_t pos, size_t n) const -{ - if (n > len_) return npos; - if (pos > len_ - n) pos = len_ - n; - for (const char* i = cstr_ + pos; i >= cstr_; --i) - { - size_t j = 0; - while (j < n && s[j] == i[j]) ++j; - if (j == n) return (size_t)(i - cstr_); - } - return npos; -} - -inline -size_t String::rfind(char c, size_t pos) const -{ - return rfind(&c, pos, 1); -} - -inline -size_t String::rfind(const String& str, size_t pos) const -{ - return rfind(str.c_str(), pos, str.len_); -} - -inline -size_t String::rfind(const char* s, size_t pos) const -{ - return rfind(s, pos, strlen(s)); -} - -inline -size_t String::find_first_of(const char* s, size_t pos, size_t n) const -{ - if (n == 0 || pos + n > len_) return npos; - const char* lmax = cstr_ + len_; - for (const char* i = cstr_ + pos; i < lmax; ++i) - { - for (size_t j = 0; j < n; ++j) - if (s[j] == *i) - return (size_t)(i - cstr_); - } - return npos; -} - -inline -size_t String::find_first_of(char c, size_t pos) const -{ - return find_first_of(&c, pos, 1); -} - -inline -size_t String::find_first_of(const String& str, size_t pos) const -{ - return find_first_of(str.c_str(), pos, str.len_); -} - -inline -size_t String::find_first_of(const char* s, size_t pos) const -{ - if (len_ == 0) return npos; - if (pos >= len_ || !s[0]) return npos; - const char* lmax = cstr_ + len_; - for (const char* i = cstr_ + pos; i < lmax; ++i) - { - for (size_t j = 0; s[j]; ++j) - if (s[j] == *i) - return (size_t)(i - cstr_); - } - return npos; -} - -inline -size_t String::find_last_of(const char* s, size_t pos, size_t n) const -{ - if (len_ == 0) return npos; - if (pos >= len_) pos = len_ - 1; - for (const char* i = cstr_ + pos; i >= cstr_; --i) - { - for (size_t j = 0; j < n; ++j) - if (s[j] == *i) - return (size_t)(i - cstr_); - } - return npos; -} - -inline -size_t String::find_last_of(char c, size_t pos) const -{ - return find_last_of(&c, pos, 1); -} - -inline -size_t String::find_last_of(const String& str, size_t pos) const -{ - return find_last_of(str.c_str(), pos, str.len_); -} - -inline -size_t String::find_last_of(const char* s, size_t pos) const -{ - if (len_ == 0) return npos; - if (pos >= len_) pos = len_ - 1; - for (const char* i = cstr_ + pos; i >= cstr_; --i) - { - for (size_t j = 0; s[j]; ++j) - if (s[j] == *i) - return (size_t)(i - cstr_); - } - return npos; -} - -inline -String String::toLowerCase() const -{ - if (!cstr_) - return String(); - String res(cstr_, len_); - for (size_t i = 0; i < len_; ++i) - res.cstr_[i] = (char) ::tolower(cstr_[i]); - - return res; -} - +} // namespace details //! @endcond -// ************************* cv::String non-member functions ************************* - -//! @relates cv::String -//! @{ - -inline -String operator + (const String& lhs, const String& rhs) +static inline std::string toLowerCase(const std::string& str) { - String s; - s.allocate(lhs.len_ + rhs.len_); - if (lhs.len_) memcpy(s.cstr_, lhs.cstr_, lhs.len_); - if (rhs.len_) memcpy(s.cstr_ + lhs.len_, rhs.cstr_, rhs.len_); - return s; + std::string result(str); + std::transform(result.begin(), result.end(), result.begin(), details::char_tolower); + return result; } -inline -String operator + (const String& lhs, const char* rhs) +static inline std::string toUpperCase(const std::string& str) { - String s; - size_t rhslen = strlen(rhs); - s.allocate(lhs.len_ + rhslen); - if (lhs.len_) memcpy(s.cstr_, lhs.cstr_, lhs.len_); - if (rhslen) memcpy(s.cstr_ + lhs.len_, rhs, rhslen); - return s; + std::string result(str); + std::transform(result.begin(), result.end(), result.begin(), details::char_toupper); + return result; } -inline -String operator + (const char* lhs, const String& rhs) -{ - String s; - size_t lhslen = strlen(lhs); - s.allocate(lhslen + rhs.len_); - if (lhslen) memcpy(s.cstr_, lhs, lhslen); - if (rhs.len_) memcpy(s.cstr_ + lhslen, rhs.cstr_, rhs.len_); - return s; -} - -inline -String operator + (const String& lhs, char rhs) -{ - String s; - s.allocate(lhs.len_ + 1); - if (lhs.len_) memcpy(s.cstr_, lhs.cstr_, lhs.len_); - s.cstr_[lhs.len_] = rhs; - return s; -} - -inline -String operator + (char lhs, const String& rhs) -{ - String s; - s.allocate(rhs.len_ + 1); - s.cstr_[0] = lhs; - if (rhs.len_) memcpy(s.cstr_ + 1, rhs.cstr_, rhs.len_); - return s; -} - -static inline bool operator== (const String& lhs, const String& rhs) { return 0 == lhs.compare(rhs); } -static inline bool operator== (const char* lhs, const String& rhs) { return 0 == rhs.compare(lhs); } -static inline bool operator== (const String& lhs, const char* rhs) { return 0 == lhs.compare(rhs); } -static inline bool operator!= (const String& lhs, const String& rhs) { return 0 != lhs.compare(rhs); } -static inline bool operator!= (const char* lhs, const String& rhs) { return 0 != rhs.compare(lhs); } -static inline bool operator!= (const String& lhs, const char* rhs) { return 0 != lhs.compare(rhs); } -static inline bool operator< (const String& lhs, const String& rhs) { return lhs.compare(rhs) < 0; } -static inline bool operator< (const char* lhs, const String& rhs) { return rhs.compare(lhs) > 0; } -static inline bool operator< (const String& lhs, const char* rhs) { return lhs.compare(rhs) < 0; } -static inline bool operator<= (const String& lhs, const String& rhs) { return lhs.compare(rhs) <= 0; } -static inline bool operator<= (const char* lhs, const String& rhs) { return rhs.compare(lhs) >= 0; } -static inline bool operator<= (const String& lhs, const char* rhs) { return lhs.compare(rhs) <= 0; } -static inline bool operator> (const String& lhs, const String& rhs) { return lhs.compare(rhs) > 0; } -static inline bool operator> (const char* lhs, const String& rhs) { return rhs.compare(lhs) < 0; } -static inline bool operator> (const String& lhs, const char* rhs) { return lhs.compare(rhs) > 0; } -static inline bool operator>= (const String& lhs, const String& rhs) { return lhs.compare(rhs) >= 0; } -static inline bool operator>= (const char* lhs, const String& rhs) { return rhs.compare(lhs) <= 0; } -static inline bool operator>= (const String& lhs, const char* rhs) { return lhs.compare(rhs) >= 0; } - -//! @} relates cv::String +#endif // OPENCV_DISABLE_STRING_LOWER_UPPER_CONVERSIONS +//! @} core_basic } // cv -namespace std -{ - static inline void swap(cv::String& a, cv::String& b) { a.swap(b); } -} - #include "opencv2/core/ptr.inl.hpp" #endif //OPENCV_CORE_CVSTD_HPP diff --git a/modules/core/include/opencv2/core/cvstd.inl.hpp b/modules/core/include/opencv2/core/cvstd.inl.hpp index ed37cacb30..5df48abb63 100644 --- a/modules/core/include/opencv2/core/cvstd.inl.hpp +++ b/modules/core/include/opencv2/core/cvstd.inl.hpp @@ -73,69 +73,6 @@ public: typedef Vec vec_type; }; -inline -String::String(const std::string& str) - : cstr_(0), len_(0) -{ - size_t len = str.size(); - if (len) memcpy(allocate(len), str.c_str(), len); -} - -inline -String::String(const std::string& str, size_t pos, size_t len) - : cstr_(0), len_(0) -{ - size_t strlen = str.size(); - pos = min(pos, strlen); - len = min(strlen - pos, len); - if (!len) return; - memcpy(allocate(len), str.c_str() + pos, len); -} - -inline -String& String::operator = (const std::string& str) -{ - deallocate(); - size_t len = str.size(); - if (len) memcpy(allocate(len), str.c_str(), len); - return *this; -} - -inline -String& String::operator += (const std::string& str) -{ - *this = *this + str; - return *this; -} - -inline -String::operator std::string() const -{ - return std::string(cstr_, len_); -} - -inline -String operator + (const String& lhs, const std::string& rhs) -{ - String s; - size_t rhslen = rhs.size(); - s.allocate(lhs.len_ + rhslen); - if (lhs.len_) memcpy(s.cstr_, lhs.cstr_, lhs.len_); - if (rhslen) memcpy(s.cstr_ + lhs.len_, rhs.c_str(), rhslen); - return s; -} - -inline -String operator + (const std::string& lhs, const String& rhs) -{ - String s; - size_t lhslen = lhs.size(); - s.allocate(lhslen + rhs.len_); - if (lhslen) memcpy(s.cstr_, lhs.c_str(), lhslen); - if (rhs.len_) memcpy(s.cstr_ + lhslen, rhs.cstr_, rhs.len_); - return s; -} - inline FileNode::operator std::string() const { diff --git a/modules/core/include/opencv2/core/mat.hpp b/modules/core/include/opencv2/core/mat.hpp index 0e9fac0ecc..1884abd66c 100644 --- a/modules/core/include/opencv2/core/mat.hpp +++ b/modules/core/include/opencv2/core/mat.hpp @@ -183,7 +183,7 @@ public: template _InputArray(const std::vector<_Tp>& vec); _InputArray(const std::vector& vec); template _InputArray(const std::vector >& vec); - _InputArray(const std::vector >&); + _InputArray(const std::vector >&) = delete; // not supported template _InputArray(const std::vector >& vec); template _InputArray(const _Tp* vec, int n); template _InputArray(const Matx<_Tp, m, n>& matx); @@ -302,9 +302,9 @@ public: _OutputArray(cuda::HostMem& cuda_mem); template _OutputArray(cudev::GpuMat_<_Tp>& m); template _OutputArray(std::vector<_Tp>& vec); - _OutputArray(std::vector& vec); + _OutputArray(std::vector& vec) = delete; // not supported template _OutputArray(std::vector >& vec); - _OutputArray(std::vector >&); + _OutputArray(std::vector >&) = delete; // not supported template _OutputArray(std::vector >& vec); template _OutputArray(Mat_<_Tp>& m); template _OutputArray(_Tp* vec, int n); @@ -372,7 +372,7 @@ public: _InputOutputArray(cuda::HostMem& cuda_mem); template _InputOutputArray(cudev::GpuMat_<_Tp>& m); template _InputOutputArray(std::vector<_Tp>& vec); - _InputOutputArray(std::vector& vec); + _InputOutputArray(std::vector& vec) = delete; // not supported template _InputOutputArray(std::vector >& vec); template _InputOutputArray(std::vector >& vec); template _InputOutputArray(Mat_<_Tp>& m); diff --git a/modules/core/include/opencv2/core/mat.inl.hpp b/modules/core/include/opencv2/core/mat.inl.hpp index d637a93cdc..ff1b9f8ee7 100644 --- a/modules/core/include/opencv2/core/mat.inl.hpp +++ b/modules/core/include/opencv2/core/mat.inl.hpp @@ -100,10 +100,6 @@ template inline _InputArray::_InputArray(const std::vector >& vec) { init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_READ, &vec); } -inline -_InputArray::_InputArray(const std::vector >&) -{ CV_Error(Error::StsUnsupportedFormat, "std::vector > is not supported!\n"); } - template inline _InputArray::_InputArray(const std::vector >& vec) { init(FIXED_TYPE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_READ, &vec); } @@ -179,18 +175,10 @@ template inline _OutputArray::_OutputArray(std::array& arr) { init(STD_ARRAY_MAT + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } -inline -_OutputArray::_OutputArray(std::vector&) -{ CV_Error(Error::StsUnsupportedFormat, "std::vector cannot be an output array\n"); } - template inline _OutputArray::_OutputArray(std::vector >& vec) { init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } -inline -_OutputArray::_OutputArray(std::vector >&) -{ CV_Error(Error::StsUnsupportedFormat, "std::vector > cannot be an output array\n"); } - template inline _OutputArray::_OutputArray(std::vector >& vec) { init(FIXED_TYPE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } @@ -294,9 +282,6 @@ template inline _InputOutputArray::_InputOutputArray(std::array& arr) { init(STD_ARRAY_MAT + ACCESS_RW, arr.data(), Size(1, _Nm)); } -inline _InputOutputArray::_InputOutputArray(std::vector&) -{ CV_Error(Error::StsUnsupportedFormat, "std::vector cannot be an input/output array\n"); } - template inline _InputOutputArray::_InputOutputArray(std::vector >& vec) { init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); } diff --git a/modules/core/include/opencv2/core/persistence.hpp b/modules/core/include/opencv2/core/persistence.hpp index c9a591ea97..790dde83f6 100644 --- a/modules/core/include/opencv2/core/persistence.hpp +++ b/modules/core/include/opencv2/core/persistence.hpp @@ -576,7 +576,6 @@ public: //! returns the node content as double operator double() const; //! returns the node content as text string - operator String() const; operator std::string() const; //! returns pointer to the underlying file node @@ -720,7 +719,6 @@ CV_EXPORTS void writeScalar( FileStorage& fs, const String& value ); CV_EXPORTS void read(const FileNode& node, int& value, int default_value); CV_EXPORTS void read(const FileNode& node, float& value, float default_value); CV_EXPORTS void read(const FileNode& node, double& value, double default_value); -CV_EXPORTS void read(const FileNode& node, String& value, const String& default_value); CV_EXPORTS void read(const FileNode& node, std::string& value, const std::string& default_value); CV_EXPORTS void read(const FileNode& node, Mat& mat, const Mat& default_mat = Mat() ); CV_EXPORTS void read(const FileNode& node, SparseMat& mat, const SparseMat& default_mat = SparseMat() ); @@ -1334,7 +1332,6 @@ inline const CvFileNode* FileNode::operator* () const { return node; } inline FileNode::operator int() const { int value; read(*this, value, 0); return value; } inline FileNode::operator float() const { float value; read(*this, value, 0.f); return value; } inline FileNode::operator double() const { double value; read(*this, value, 0.); return value; } -inline FileNode::operator String() const { String value; read(*this, value, value); return value; } inline double FileNode::real() const { return double(*this); } inline String FileNode::string() const { return String(*this); } inline Mat FileNode::mat() const { Mat value; read(*this, value, value); return value; } @@ -1343,7 +1340,6 @@ inline FileNodeIterator FileNode::end() const { return FileNodeIterator(fs, no inline void FileNode::readRaw( const String& fmt, uchar* vec, size_t len ) const { begin().readRaw( fmt, vec, len ); } inline FileNode FileNodeIterator::operator *() const { return FileNode(fs, (const CvFileNode*)(const void*)reader.ptr); } inline FileNode FileNodeIterator::operator ->() const { return FileNode(fs, (const CvFileNode*)(const void*)reader.ptr); } -inline String::String(const FileNode& fn): cstr_(0), len_(0) { read(fn, *this, *this); } //! @endcond diff --git a/modules/core/include/opencv2/core/utility.hpp b/modules/core/include/opencv2/core/utility.hpp index 2bc6daf43b..03f5d44ecb 100644 --- a/modules/core/include/opencv2/core/utility.hpp +++ b/modules/core/include/opencv2/core/utility.hpp @@ -1053,15 +1053,6 @@ template inline size_t AutoBuffer<_Tp, fixed_size>::size() const { return sz; } -template<> inline std::string CommandLineParser::get(int index, bool space_delete) const -{ - return get(index, space_delete); -} -template<> inline std::string CommandLineParser::get(const String& name, bool space_delete) const -{ - return get(name, space_delete); -} - //! @endcond diff --git a/modules/core/src/command_line_parser.cpp b/modules/core/src/command_line_parser.cpp index 766835fe1d..6ef24d2cd0 100644 --- a/modules/core/src/command_line_parser.cpp +++ b/modules/core/src/command_line_parser.cpp @@ -72,14 +72,9 @@ static const char* get_type_name(int type) return "unknown"; } -// std::tolower is int->int -static char char_tolower(char ch) -{ - return (char)std::tolower((int)ch); -} static bool parse_bool(std::string str) { - std::transform(str.begin(), str.end(), str.begin(), char_tolower); + std::transform(str.begin(), str.end(), str.begin(), details::char_tolower); std::istringstream is(str); bool b; is >> (str.size() > 1 ? std::boolalpha : std::noboolalpha) >> b; diff --git a/modules/core/src/ocl.cpp b/modules/core/src/ocl.cpp index 05f128baa7..95d51f9cc5 100644 --- a/modules/core/src/ocl.cpp +++ b/modules/core/src/ocl.cpp @@ -1691,11 +1691,6 @@ static cl_device_id selectOpenCLDevice() return NULL; } #else -// std::tolower is int->int -static char char_tolower(char ch) -{ - return (char)std::tolower((int)ch); -} static cl_device_id selectOpenCLDevice() { std::string platform, deviceName; @@ -1780,7 +1775,7 @@ static cl_device_id selectOpenCLDevice() { int deviceType = 0; std::string tempStrDeviceType = deviceTypes[t]; - std::transform(tempStrDeviceType.begin(), tempStrDeviceType.end(), tempStrDeviceType.begin(), char_tolower); + std::transform(tempStrDeviceType.begin(), tempStrDeviceType.end(), tempStrDeviceType.begin(), details::char_tolower); if (tempStrDeviceType == "gpu" || tempStrDeviceType == "dgpu" || tempStrDeviceType == "igpu") deviceType = Device::TYPE_GPU; diff --git a/modules/core/src/persistence_cpp.cpp b/modules/core/src/persistence_cpp.cpp index 29984dba27..e584a130dd 100644 --- a/modules/core/src/persistence_cpp.cpp +++ b/modules/core/src/persistence_cpp.cpp @@ -667,11 +667,6 @@ void read(const FileNode& node, double& value, double default_value) CV_NODE_IS_REAL(node.node->tag) ? node.node->data.f : std::numeric_limits::max(); } -void read(const FileNode& node, String& value, const String& default_value) -{ - value = !node.node ? default_value : CV_NODE_IS_STRING(node.node->tag) ? String(node.node->data.str.ptr) : String(); -} - void read(const FileNode& node, std::string& value, const std::string& default_value) { value = !node.node ? default_value : CV_NODE_IS_STRING(node.node->tag) ? std::string(node.node->data.str.ptr) : default_value; diff --git a/modules/core/src/stl.cpp b/modules/core/src/stl.cpp index f03c1a2d79..bd6ee10ef6 100644 --- a/modules/core/src/stl.cpp +++ b/modules/core/src/stl.cpp @@ -43,27 +43,3 @@ #include "precomp.hpp" - -char* cv::String::allocate(size_t len) -{ - size_t totalsize = alignSize(len + 1, (int)sizeof(int)); - int* data = (int*)cv::fastMalloc(totalsize + sizeof(int)); - data[0] = 1; - cstr_ = (char*)(data + 1); - len_ = len; - cstr_[len] = 0; - return cstr_; -} - - -void cv::String::deallocate() -{ - int* data = (int*)cstr_; - len_ = 0; - cstr_ = 0; - - if(data && 1 == CV_XADD(data-1, -1)) - { - cv::fastFree(data-1); - } -} diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index eb4aecfd91..23c9bfd5a6 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -1655,12 +1655,7 @@ cv::String utils::getConfigurationParameterString(const char* name, const char* #else const char* envValue = getenv(name); #endif - if (envValue == NULL) - { - return defaultValue; - } - cv::String value = envValue; - return value; + return envValue ? cv::String(envValue) : (defaultValue ? cv::String(defaultValue) : cv::String()); } @@ -1953,7 +1948,9 @@ public: ippFeatures = cpuFeatures; const char* pIppEnv = getenv("OPENCV_IPP"); - cv::String env = pIppEnv; + cv::String env; + if(pIppEnv != NULL) + env = pIppEnv; if(env.size()) { #if IPP_VERSION_X100 >= 201703 @@ -1968,7 +1965,7 @@ public: const Ipp64u minorFeatures = 0; #endif - env = env.toLowerCase(); + env = toLowerCase(env); if(env.substr(0, 2) == "ne") { useIPP_NE = true; diff --git a/modules/cudalegacy/src/cuda/NCVHaarObjectDetection.cu b/modules/cudalegacy/src/cuda/NCVHaarObjectDetection.cu index 5e26039757..102c0ee4dc 100644 --- a/modules/cudalegacy/src/cuda/NCVHaarObjectDetection.cu +++ b/modules/cudalegacy/src/cuda/NCVHaarObjectDetection.cu @@ -2388,7 +2388,7 @@ NCVStatus ncvHaarGetClassifierSize(const cv::String &filename, Ncv32u &numStages NCVStatus ncvStat; cv::String fext = filename.substr(filename.find_last_of(".") + 1); - fext = fext.toLowerCase(); + std::transform(fext.begin(), fext.end(), fext.begin(), ::tolower); if (fext == "nvbin") { @@ -2446,7 +2446,7 @@ NCVStatus ncvHaarLoadFromFile_host(const cv::String &filename, NCVStatus ncvStat; cv::String fext = filename.substr(filename.find_last_of(".") + 1); - fext = fext.toLowerCase(); + std::transform(fext.begin(), fext.end(), fext.begin(), ::tolower); std::vector haarStages; std::vector haarNodes; diff --git a/modules/cudaobjdetect/src/cascadeclassifier.cpp b/modules/cudaobjdetect/src/cascadeclassifier.cpp index 4013ca10db..c264e182f3 100644 --- a/modules/cudaobjdetect/src/cascadeclassifier.cpp +++ b/modules/cudaobjdetect/src/cascadeclassifier.cpp @@ -809,7 +809,7 @@ namespace Ptr cv::cuda::CascadeClassifier::create(const String& filename) { String fext = filename.substr(filename.find_last_of(".") + 1); - fext = fext.toLowerCase(); + std::transform(fext.begin(), fext.end(), fext.begin(), ::tolower); if (fext == "nvbin") { diff --git a/modules/dnn/src/dnn.cpp b/modules/dnn/src/dnn.cpp index bc18695521..1301c285a4 100644 --- a/modules/dnn/src/dnn.cpp +++ b/modules/dnn/src/dnn.cpp @@ -3328,7 +3328,7 @@ void LayerFactory::registerLayer(const String &type, Constructor constructor) CV_TRACE_ARG_VALUE(type, "type", type.c_str()); cv::AutoLock lock(getLayerFactoryMutex()); - String type_ = type.toLowerCase(); + String type_ = toLowerCase(type); LayerFactory_Impl::iterator it = getLayerFactoryImpl().find(type_); if (it != getLayerFactoryImpl().end()) @@ -3346,7 +3346,7 @@ void LayerFactory::unregisterLayer(const String &type) CV_TRACE_ARG_VALUE(type, "type", type.c_str()); cv::AutoLock lock(getLayerFactoryMutex()); - String type_ = type.toLowerCase(); + String type_ = toLowerCase(type); LayerFactory_Impl::iterator it = getLayerFactoryImpl().find(type_); if (it != getLayerFactoryImpl().end()) @@ -3364,7 +3364,7 @@ Ptr LayerFactory::createLayerInstance(const String &type, LayerParams& pa CV_TRACE_ARG_VALUE(type, "type", type.c_str()); cv::AutoLock lock(getLayerFactoryMutex()); - String type_ = type.toLowerCase(); + String type_ = toLowerCase(type); LayerFactory_Impl::const_iterator it = getLayerFactoryImpl().find(type_); if (it != getLayerFactoryImpl().end()) @@ -3401,7 +3401,7 @@ BackendWrapper::~BackendWrapper() {} Net readNet(const String& _model, const String& _config, const String& _framework) { - String framework = _framework.toLowerCase(); + String framework = toLowerCase(_framework); String model = _model; String config = _config; const std::string modelExt = model.substr(model.rfind('.') + 1); @@ -3446,7 +3446,7 @@ Net readNet(const String& _model, const String& _config, const String& _framewor Net readNet(const String& _framework, const std::vector& bufferModel, const std::vector& bufferConfig) { - String framework = _framework.toLowerCase(); + String framework = toLowerCase(_framework); if (framework == "caffe") return readNetFromCaffe(bufferConfig, bufferModel); else if (framework == "tensorflow") diff --git a/modules/dnn/src/layers/detection_output_layer.cpp b/modules/dnn/src/layers/detection_output_layer.cpp index a3879128f9..bd926e49ce 100644 --- a/modules/dnn/src/layers/detection_output_layer.cpp +++ b/modules/dnn/src/layers/detection_output_layer.cpp @@ -164,7 +164,7 @@ public: void getCodeType(const LayerParams ¶ms) { - String codeTypeString = params.get("code_type").toLowerCase(); + String codeTypeString = toLowerCase(params.get("code_type")); if (codeTypeString == "center_size") _codeType = "CENTER_SIZE"; else diff --git a/modules/dnn/src/layers/eltwise_layer.cpp b/modules/dnn/src/layers/eltwise_layer.cpp index 567d598416..b1a3493a90 100644 --- a/modules/dnn/src/layers/eltwise_layer.cpp +++ b/modules/dnn/src/layers/eltwise_layer.cpp @@ -71,7 +71,7 @@ public: op = SUM; if (params.has("operation")) { - String operation = params.get("operation").toLowerCase(); + String operation = toLowerCase(params.get("operation")); if (operation == "prod") op = PROD; else if (operation == "sum") diff --git a/modules/dnn/src/layers/pooling_layer.cpp b/modules/dnn/src/layers/pooling_layer.cpp index 573565d025..200751d9b2 100644 --- a/modules/dnn/src/layers/pooling_layer.cpp +++ b/modules/dnn/src/layers/pooling_layer.cpp @@ -76,7 +76,7 @@ public: if (params.has("pool") || params.has("kernel_size") || params.has("kernel_w") || params.has("kernel_h")) { - String pool = params.get("pool", "max").toLowerCase(); + String pool = toLowerCase(params.get("pool", "max")); if (pool == "max") type = MAX; else if (pool == "ave") diff --git a/modules/dnn/src/layers/recurrent_layers.cpp b/modules/dnn/src/layers/recurrent_layers.cpp index b356b7627c..15f791a0b0 100644 --- a/modules/dnn/src/layers/recurrent_layers.cpp +++ b/modules/dnn/src/layers/recurrent_layers.cpp @@ -349,16 +349,16 @@ Ptr LSTMLayer::create(const LayerParams& params) int LSTMLayer::inputNameToIndex(String inputName) { - if (inputName.toLowerCase() == "x") + if (toLowerCase(inputName) == "x") return 0; return -1; } int LSTMLayer::outputNameToIndex(const String& outputName) { - if (outputName.toLowerCase() == "h") + if (toLowerCase(outputName) == "h") return 0; - else if (outputName.toLowerCase() == "c") + else if (toLowerCase(outputName) == "c") return 1; return -1; } diff --git a/modules/videostab/src/inpainting.cpp b/modules/videostab/src/inpainting.cpp index 3fad005318..1cd2e2391f 100644 --- a/modules/videostab/src/inpainting.cpp +++ b/modules/videostab/src/inpainting.cpp @@ -325,6 +325,9 @@ public: }; +#ifdef _MSC_VER +#pragma warning(disable: 4702) // unreachable code +#endif MotionInpainter::MotionInpainter() { #ifdef HAVE_OPENCV_CUDAOPTFLOW