Merge pull request #695 from taka-no-me/cv_str

cv::String to replace the std::string
This commit is contained in:
Andrey Kamaev
2013-03-25 03:24:42 -07:00
182 changed files with 2132 additions and 1470 deletions

View File

@@ -47,11 +47,12 @@
#define __OPENCV_CORE_HPP__
#include "opencv2/core/cvdef.h"
#include "opencv2/core/types_c.h"
#include "opencv2/core/version.hpp"
#include "opencv2/core/types_c.h"
#ifdef __cplusplus
#include "opencv2/core/cvstd.hpp"
#ifndef SKIP_INCLUDES
#include <limits.h>
@@ -61,7 +62,6 @@
#include <complex>
#include <map>
#include <new>
#include <string>
#include <vector>
#include <sstream>
#endif // SKIP_INCLUDES
@@ -125,7 +125,7 @@ public:
Full constructor. Normally the constuctor is not called explicitly.
Instead, the macros CV_Error(), CV_Error_() and CV_Assert() are used.
*/
Exception(int _code, const std::string& _err, const std::string& _func, const std::string& _file, int _line);
Exception(int _code, const String& _err, const String& _func, const String& _file, int _line);
virtual ~Exception() throw();
/*!
@@ -134,12 +134,12 @@ public:
virtual const char *what() const throw();
void formatMessage();
std::string msg; ///< the formatted error message
String msg; ///< the formatted error message
int code; ///< error code @see CVStatus
std::string err; ///< error description
std::string func; ///< function name. Available only when the compiler supports __func__ macro
std::string file; ///< source file name where the error has occured
String err; ///< error description
String func; ///< function name. Available only when the compiler supports __func__ macro
String file; ///< source file name where the error has occured
int line; ///< line number in the source file where the error has occured
};
@@ -2514,13 +2514,13 @@ enum
};
//! renders text string in the image
CV_EXPORTS_W void putText( Mat& img, const std::string& text, Point org,
CV_EXPORTS_W void putText( Mat& img, const String& text, Point org,
int fontFace, double fontScale, Scalar color,
int thickness=1, int lineType=8,
bool bottomLeftOrigin=false );
//! returns bounding box of the text string
CV_EXPORTS_W Size getTextSize(const std::string& text, int fontFace,
CV_EXPORTS_W Size getTextSize(const String& text, int fontFace,
double fontScale, int thickness,
CV_OUT int* baseLine);
@@ -3765,7 +3765,7 @@ class CV_EXPORTS FileNode;
FileStorage fs("test.yml", FileStorage::READ);
int test_int = (int)fs["test_int"];
double test_real = (double)fs["test_real"];
std::string test_string = (std::string)fs["test_string"];
String test_string = (String)fs["test_string"];
Mat M;
fs["test_mat"] >> M;
@@ -3776,7 +3776,7 @@ class CV_EXPORTS FileNode;
int tl1 = (int)tl[1];
double tl2 = (double)tl[2];
int tl3 = (int)tl[3];
std::string tl4 = (std::string)tl[4];
String tl4 = (String)tl[4];
CV_Assert(tl[5].type() == FileNode::MAP && tl[5].size() == 3);
int month = (int)tl[5]["month"];
@@ -3822,27 +3822,27 @@ public:
//! the default constructor
CV_WRAP FileStorage();
//! the full constructor that opens file storage for reading or writing
CV_WRAP FileStorage(const std::string& source, int flags, const std::string& encoding=std::string());
CV_WRAP FileStorage(const String& source, int flags, const String& encoding=String());
//! the constructor that takes pointer to the C FileStorage structure
FileStorage(CvFileStorage* fs);
//! the destructor. calls release()
virtual ~FileStorage();
//! opens file storage for reading or writing. The previous storage is closed with release()
CV_WRAP virtual bool open(const std::string& filename, int flags, const std::string& encoding=std::string());
CV_WRAP virtual bool open(const String& filename, int flags, const String& encoding=String());
//! returns true if the object is associated with currently opened file.
CV_WRAP virtual bool isOpened() const;
//! closes the file and releases all the memory buffers
CV_WRAP virtual void release();
//! closes the file, releases all the memory buffers and returns the text string
CV_WRAP virtual std::string releaseAndGetString();
CV_WRAP virtual String releaseAndGetString();
//! returns the first element of the top-level mapping
CV_WRAP FileNode getFirstTopLevelNode() const;
//! returns the top-level mapping. YAML supports multiple streams
CV_WRAP FileNode root(int streamidx=0) const;
//! returns the specified element of the top-level mapping
FileNode operator[](const std::string& nodename) const;
FileNode operator[](const String& nodename) const;
//! returns the specified element of the top-level mapping
CV_WRAP FileNode operator[](const char* nodename) const;
@@ -3851,15 +3851,15 @@ public:
//! returns pointer to the underlying C FileStorage structure
const CvFileStorage* operator *() const { return fs; }
//! writes one or more numbers of the specified format to the currently written structure
void writeRaw( const std::string& fmt, const uchar* vec, size_t len );
void writeRaw( const String& fmt, const uchar* vec, size_t len );
//! writes the registered C structure (CvMat, CvMatND, CvSeq). See cvWrite()
void writeObj( const std::string& name, const void* obj );
void writeObj( const String& name, const void* obj );
//! returns the normalized object name for the specified file name
static std::string getDefaultObjectName(const std::string& filename);
static String getDefaultObjectName(const String& filename);
Ptr<CvFileStorage> fs; //!< the underlying C FileStorage structure
std::string elname; //!< the currently written element
String elname; //!< the currently written element
std::vector<char> structs; //!< the stack of written structures
int state; //!< the writer state
};
@@ -3904,7 +3904,7 @@ public:
//! the copy constructor
FileNode(const FileNode& node);
//! returns element of a mapping node
FileNode operator[](const std::string& nodename) const;
FileNode operator[](const String& nodename) const;
//! returns element of a mapping node
CV_WRAP FileNode operator[](const char* nodename) const;
//! returns element of a sequence node
@@ -3929,7 +3929,7 @@ public:
//! returns true if the node has a name
CV_WRAP bool isNamed() const;
//! returns the node name or an empty string if the node is nameless
CV_WRAP std::string name() const;
CV_WRAP String name() const;
//! returns the number of elements in the node, if it is a sequence or mapping, or 1 otherwise.
CV_WRAP size_t size() const;
//! returns the node content as an integer. If the node stores floating-point number, it is rounded.
@@ -3939,7 +3939,10 @@ public:
//! returns the node content as double
operator double() const;
//! returns the node content as text string
operator String() const;
#ifndef OPENCV_NOSTL
operator std::string() const;
#endif
//! returns pointer to the underlying file node
CvFileNode* operator *();
@@ -3952,7 +3955,7 @@ public:
FileNodeIterator end() const;
//! reads node elements to the buffer with the specified format
void readRaw( const std::string& fmt, uchar* vec, size_t len ) const;
void readRaw( const String& fmt, uchar* vec, size_t len ) const;
//! reads the registered object and returns pointer to it
void* readObj() const;
@@ -3995,7 +3998,7 @@ public:
FileNodeIterator& operator -= (int ofs);
//! reads the next maxCount elements (or less, if the sequence/mapping last element occurs earlier) to the buffer with the specified format
FileNodeIterator& readRaw( const std::string& fmt, uchar* vec,
FileNodeIterator& readRaw( const String& fmt, uchar* vec,
size_t maxCount=(size_t)INT_MAX );
const CvFileStorage* fs;
@@ -4151,41 +4154,41 @@ class CV_EXPORTS_W Algorithm
public:
Algorithm();
virtual ~Algorithm();
std::string name() const;
String name() const;
template<typename _Tp> typename ParamType<_Tp>::member_type get(const std::string& name) const;
template<typename _Tp> typename ParamType<_Tp>::member_type get(const String& name) const;
template<typename _Tp> typename ParamType<_Tp>::member_type get(const char* name) const;
CV_WRAP int getInt(const std::string& name) const;
CV_WRAP double getDouble(const std::string& name) const;
CV_WRAP bool getBool(const std::string& name) const;
CV_WRAP std::string getString(const std::string& name) const;
CV_WRAP Mat getMat(const std::string& name) const;
CV_WRAP std::vector<Mat> getMatVector(const std::string& name) const;
CV_WRAP Ptr<Algorithm> getAlgorithm(const std::string& name) const;
CV_WRAP int getInt(const String& name) const;
CV_WRAP double getDouble(const String& name) const;
CV_WRAP bool getBool(const String& name) const;
CV_WRAP String getString(const String& name) const;
CV_WRAP Mat getMat(const String& name) const;
CV_WRAP std::vector<Mat> getMatVector(const String& name) const;
CV_WRAP Ptr<Algorithm> getAlgorithm(const String& name) const;
void set(const std::string& name, int value);
void set(const std::string& name, double value);
void set(const std::string& name, bool value);
void set(const std::string& name, const std::string& value);
void set(const std::string& name, const Mat& value);
void set(const std::string& name, const std::vector<Mat>& value);
void set(const std::string& name, const Ptr<Algorithm>& value);
template<typename _Tp> void set(const std::string& name, const Ptr<_Tp>& value);
void set(const String& name, int value);
void set(const String& name, double value);
void set(const String& name, bool value);
void set(const String& name, const String& value);
void set(const String& name, const Mat& value);
void set(const String& name, const std::vector<Mat>& value);
void set(const String& name, const Ptr<Algorithm>& value);
template<typename _Tp> void set(const String& name, const Ptr<_Tp>& value);
CV_WRAP void setInt(const std::string& name, int value);
CV_WRAP void setDouble(const std::string& name, double value);
CV_WRAP void setBool(const std::string& name, bool value);
CV_WRAP void setString(const std::string& name, const std::string& value);
CV_WRAP void setMat(const std::string& name, const Mat& value);
CV_WRAP void setMatVector(const std::string& name, const std::vector<Mat>& value);
CV_WRAP void setAlgorithm(const std::string& name, const Ptr<Algorithm>& value);
template<typename _Tp> void setAlgorithm(const std::string& name, const Ptr<_Tp>& value);
CV_WRAP void setInt(const String& name, int value);
CV_WRAP void setDouble(const String& name, double value);
CV_WRAP void setBool(const String& name, bool value);
CV_WRAP void setString(const String& name, const String& value);
CV_WRAP void setMat(const String& name, const Mat& value);
CV_WRAP void setMatVector(const String& name, const std::vector<Mat>& value);
CV_WRAP void setAlgorithm(const String& name, const Ptr<Algorithm>& value);
template<typename _Tp> void setAlgorithm(const String& name, const Ptr<_Tp>& value);
void set(const char* name, int value);
void set(const char* name, double value);
void set(const char* name, bool value);
void set(const char* name, const std::string& value);
void set(const char* name, const String& value);
void set(const char* name, const Mat& value);
void set(const char* name, const std::vector<Mat>& value);
void set(const char* name, const Ptr<Algorithm>& value);
@@ -4194,16 +4197,16 @@ public:
void setInt(const char* name, int value);
void setDouble(const char* name, double value);
void setBool(const char* name, bool value);
void setString(const char* name, const std::string& value);
void setString(const char* name, const String& value);
void setMat(const char* name, const Mat& value);
void setMatVector(const char* name, const std::vector<Mat>& value);
void setAlgorithm(const char* name, const Ptr<Algorithm>& value);
template<typename _Tp> void setAlgorithm(const char* name, const Ptr<_Tp>& value);
CV_WRAP std::string paramHelp(const std::string& name) const;
CV_WRAP String paramHelp(const String& name) const;
int paramType(const char* name) const;
CV_WRAP int paramType(const std::string& name) const;
CV_WRAP void getParams(CV_OUT std::vector<std::string>& names) const;
CV_WRAP int paramType(const String& name) const;
CV_WRAP void getParams(CV_OUT std::vector<String>& names) const;
virtual void write(FileStorage& fs) const;
@@ -4213,9 +4216,9 @@ public:
typedef int (Algorithm::*Getter)() const;
typedef void (Algorithm::*Setter)(int);
CV_WRAP static void getList(CV_OUT std::vector<std::string>& algorithms);
CV_WRAP static Ptr<Algorithm> _create(const std::string& name);
template<typename _Tp> static Ptr<_Tp> create(const std::string& name);
CV_WRAP static void getList(CV_OUT std::vector<String>& algorithms);
CV_WRAP static Ptr<Algorithm> _create(const String& name);
template<typename _Tp> static Ptr<_Tp> create(const String& name);
virtual AlgorithmInfo* info() const /* TODO: make it = 0;*/ { return 0; }
};
@@ -4225,86 +4228,86 @@ class CV_EXPORTS AlgorithmInfo
{
public:
friend class Algorithm;
AlgorithmInfo(const std::string& name, Algorithm::Constructor create);
AlgorithmInfo(const String& name, Algorithm::Constructor create);
~AlgorithmInfo();
void get(const Algorithm* algo, const char* name, int argType, void* value) const;
void addParam_(Algorithm& algo, const char* name, int argType,
void* value, bool readOnly,
Algorithm::Getter getter, Algorithm::Setter setter,
const std::string& help=std::string());
std::string paramHelp(const char* name) const;
const String& help=String());
String paramHelp(const char* name) const;
int paramType(const char* name) const;
void getParams(std::vector<std::string>& names) const;
void getParams(std::vector<String>& names) const;
void write(const Algorithm* algo, FileStorage& fs) const;
void read(Algorithm* algo, const FileNode& fn) const;
std::string name() const;
String name() const;
void addParam(Algorithm& algo, const char* name,
int& value, bool readOnly=false,
int (Algorithm::*getter)()=0,
void (Algorithm::*setter)(int)=0,
const std::string& help=std::string());
const String& help=String());
void addParam(Algorithm& algo, const char* name,
bool& value, bool readOnly=false,
int (Algorithm::*getter)()=0,
void (Algorithm::*setter)(int)=0,
const std::string& help=std::string());
const String& help=String());
void addParam(Algorithm& algo, const char* name,
double& value, bool readOnly=false,
double (Algorithm::*getter)()=0,
void (Algorithm::*setter)(double)=0,
const std::string& help=std::string());
const String& help=String());
void addParam(Algorithm& algo, const char* name,
std::string& value, bool readOnly=false,
std::string (Algorithm::*getter)()=0,
void (Algorithm::*setter)(const std::string&)=0,
const std::string& help=std::string());
String& value, bool readOnly=false,
String (Algorithm::*getter)()=0,
void (Algorithm::*setter)(const String&)=0,
const String& help=String());
void addParam(Algorithm& algo, const char* name,
Mat& value, bool readOnly=false,
Mat (Algorithm::*getter)()=0,
void (Algorithm::*setter)(const Mat&)=0,
const std::string& help=std::string());
const String& help=String());
void addParam(Algorithm& algo, const char* name,
std::vector<Mat>& value, bool readOnly=false,
std::vector<Mat> (Algorithm::*getter)()=0,
void (Algorithm::*setter)(const std::vector<Mat>&)=0,
const std::string& help=std::string());
const String& help=String());
void addParam(Algorithm& algo, const char* name,
Ptr<Algorithm>& value, bool readOnly=false,
Ptr<Algorithm> (Algorithm::*getter)()=0,
void (Algorithm::*setter)(const Ptr<Algorithm>&)=0,
const std::string& help=std::string());
const String& help=String());
void addParam(Algorithm& algo, const char* name,
float& value, bool readOnly=false,
float (Algorithm::*getter)()=0,
void (Algorithm::*setter)(float)=0,
const std::string& help=std::string());
const String& help=String());
void addParam(Algorithm& algo, const char* name,
unsigned int& value, bool readOnly=false,
unsigned int (Algorithm::*getter)()=0,
void (Algorithm::*setter)(unsigned int)=0,
const std::string& help=std::string());
const String& help=String());
void addParam(Algorithm& algo, const char* name,
uint64& value, bool readOnly=false,
uint64 (Algorithm::*getter)()=0,
void (Algorithm::*setter)(uint64)=0,
const std::string& help=std::string());
const String& help=String());
void addParam(Algorithm& algo, const char* name,
uchar& value, bool readOnly=false,
uchar (Algorithm::*getter)()=0,
void (Algorithm::*setter)(uchar)=0,
const std::string& help=std::string());
const String& help=String());
template<typename _Tp, typename _Base> void addParam(Algorithm& algo, const char* name,
Ptr<_Tp>& value, bool readOnly=false,
Ptr<_Tp> (Algorithm::*getter)()=0,
void (Algorithm::*setter)(const Ptr<_Tp>&)=0,
const std::string& help=std::string());
const String& help=String());
template<typename _Tp> void addParam(Algorithm& algo, const char* name,
Ptr<_Tp>& value, bool readOnly=false,
Ptr<_Tp> (Algorithm::*getter)()=0,
void (Algorithm::*setter)(const Ptr<_Tp>&)=0,
const std::string& help=std::string());
const String& help=String());
protected:
AlgorithmInfoData* data;
void set(Algorithm* algo, const char* name, int argType,
@@ -4320,13 +4323,13 @@ struct CV_EXPORTS Param
Param(int _type, bool _readonly, int _offset,
Algorithm::Getter _getter=0,
Algorithm::Setter _setter=0,
const std::string& _help=std::string());
const String& _help=String());
int type;
int offset;
bool readonly;
Algorithm::Getter getter;
Algorithm::Setter setter;
std::string help;
String help;
};
template<> struct ParamType<bool>
@@ -4353,10 +4356,10 @@ template<> struct ParamType<double>
enum { type = Param::REAL };
};
template<> struct ParamType<std::string>
template<> struct ParamType<String>
{
typedef const std::string& const_param_type;
typedef std::string member_type;
typedef const String& const_param_type;
typedef String member_type;
enum { type = Param::STRING };
};
@@ -4419,9 +4422,11 @@ template<> struct ParamType<uchar>
} //namespace cv
#endif // __cplusplus
#include "opencv2/core/operations.hpp"
#include "opencv2/core/mat.hpp"
#include "opencv2/core/cvstd.inl.hpp"
#endif // __cplusplus
#endif /*__OPENCV_CORE_HPP__*/

View File

@@ -0,0 +1,470 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef __OPENCV_CORE_CVSTD_HPP__
#define __OPENCV_CORE_CVSTD_HPP__
#include <cstddef>
#include <cstring>
#include "opencv2/core/cvdef.h"
#ifndef OPENCV_NOSTL
# include <string>
#endif
// import useful primitives from stl
#ifndef OPENCV_NOSTL_TRANSITIONAL
# include <algorithm>
# include <utility>
# include <cmath>
namespace cv
{
using std::min;
using std::max;
using std::abs;
using std::swap;
}
#else
namespace cv
{
template<typename T> inline T min(T a, T b) { return a < b ? a : b; }
template<typename T> inline T max(T a, T b) { return a > b ? a : b; }
template<typename T> inline T abs(T a) { return a < 0 ? -a : a; }
template<typename T> inline void swap(T& a, T& b) { T tmp = a; a = b; b = tmp; }
template<> inline uchar abs(uchar a) { return a; }
template<> inline ushort abs(ushort a) { return a; }
template<> inline uint abs(uint a) { return a; }
template<> inline uint64 abs(uint64 a) { return a; }
}
#endif
namespace cv {
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;
static const size_t npos = size_t(-1);
explicit String() : cstr_(0), len_(0) {}
String(const String& str) : cstr_(str.cstr_), len_(str.len_)
{
if (cstr_) CV_XADD(((int*)cstr_)-1, 1);
}
String(const String& str, size_t pos, size_t len = npos) : cstr_(0), len_(0)
{
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);
}
String(const char* s): cstr_(0), len_(0)
{
if (!s) return;
size_t len = strlen(s);
memcpy(allocate(len), s, len);
}
String(const char* s, size_t n): cstr_(0), len_(0)
{
if (!n) return;
memcpy(allocate(n), s, n);
}
String(size_t n, char c): cstr_(0), len_(0)
{
memset(allocate(n), c, n);
}
String(const char* first, const char* last): cstr_(0), len_(0)
{
size_t len = (size_t)(last - first);
memcpy(allocate(len), first, len);
}
template<typename Iterator>
String(Iterator first, Iterator last): cstr_(0), len_(0)
{
size_t len = (size_t)(last - first);
char* str = allocate(len);
while (first != last)
{
*str++ = *first;
++first;
}
}
~String() { deallocate(); }
String& operator=(const String& str)
{
deallocate();
if (str.cstr_) CV_XADD(((int*)str.cstr_)-1, 1);
cstr_ = str.cstr_;
len_ = str.len_;
return *this;
}
String& operator=(const char* s)
{
deallocate();
if (!s) return *this;
size_t len = strlen(s);
memcpy(allocate(len), s, len);
return *this;
}
String& operator=(char c)
{
deallocate();
allocate(1)[0] = c;
return *this;
}
size_t size() const { return len_; }
size_t length() const { return len_; }
char operator[](size_t idx) const { return cstr_[idx]; }
char operator[](int idx) const { return cstr_[idx]; }
const char* begin() const { return cstr_; }
const char* end() const { return len_ ? cstr_ + 1 : 0; }
bool empty() const { return len_ == 0; }
const char* c_str() const { return cstr_ ? cstr_ : ""; }
void swap(String& str)
{
cv::swap(cstr_, str.cstr_);
cv::swap(len_, str.len_);
}
void clear() { deallocate(); }
int compare(const char* s) const
{
if (cstr_ == s) return 0;
return strcmp(c_str(), s);
}
int compare(const String& str) const
{
if (cstr_ == str.cstr_) return 0;
return strcmp(c_str(), str.c_str());
}
String substr(size_t pos = 0, size_t len = npos) const
{
return String(*this, pos, len);
}
size_t 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;
}
size_t find(char c, size_t pos = 0) const
{
return find(&c, pos, 1);
}
size_t find(const String& str, size_t pos = 0) const
{
return find(str.c_str(), pos, str.len_);
}
size_t find(const char* s, size_t pos = 0) 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;
}
size_t 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;
}
size_t rfind(char c, size_t pos = npos) const
{
return rfind(&c, pos, 1);
}
size_t rfind(const String& str, size_t pos = npos) const
{
return rfind(str.c_str(), pos, str.len_);
}
size_t rfind(const char* s, size_t pos = npos) const
{
return rfind(s, pos, strlen(s));
}
size_t 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;
}
size_t find_first_of(char c, size_t pos = 0) const
{
return find_first_of(&c, pos, 1);
}
size_t find_first_of(const String& str, size_t pos = 0) const
{
return find_first_of(str.c_str(), pos, str.len_);
}
size_t find_first_of(const char* s, size_t pos = 0) const
{
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;
}
size_t find_last_of(const char* s, size_t pos, size_t n) const
{
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;
}
size_t find_last_of(char c, size_t pos = npos) const
{
return find_last_of(&c, pos, 1);
}
size_t find_last_of(const String& str, size_t pos = npos) const
{
return find_last_of(str.c_str(), pos, str.len_);
}
size_t find_last_of(const char* s, size_t pos = npos) const
{
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;
}
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);
#ifndef OPENCV_NOSTL
String(const std::string& str);
String(const std::string& str, size_t pos, size_t len = npos);
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);
#endif
explicit String(const FileNode& fn);
private:
char* cstr_;
size_t len_;
char* allocate(size_t len); // len_ without trailing 0
void deallocate();
};
inline String operator+ (const String& lhs, const String& rhs)
{
String s;
s.allocate(lhs.len_ + rhs.len_);
memcpy(s.cstr_, lhs.cstr_, lhs.len_);
memcpy(s.cstr_ + lhs.len_, rhs.cstr_, rhs.len_);
return s;
}
inline String operator+ (const String& lhs, const char* rhs)
{
String s;
size_t rhslen = strlen(rhs);
s.allocate(lhs.len_ + rhslen);
memcpy(s.cstr_, lhs.cstr_, lhs.len_);
memcpy(s.cstr_ + lhs.len_, rhs, rhslen);
return s;
}
inline String operator+ (const char* lhs, const String& rhs)
{
String s;
size_t lhslen = strlen(lhs);
s.allocate(lhslen + rhs.len_);
memcpy(s.cstr_, lhs, lhslen);
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);
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;
memcpy(s.cstr_ + 1, rhs.cstr_, rhs.len_);
return s;
}
inline bool operator== (const String& lhs, const String& rhs) { return 0 == lhs.compare(rhs); }
inline bool operator== (const char* lhs, const String& rhs) { return 0 == rhs.compare(lhs); }
inline bool operator== (const String& lhs, const char* rhs) { return 0 == lhs.compare(rhs); }
inline bool operator!= (const String& lhs, const String& rhs) { return 0 != lhs.compare(rhs); }
inline bool operator!= (const char* lhs, const String& rhs) { return 0 != rhs.compare(lhs); }
inline bool operator!= (const String& lhs, const char* rhs) { return 0 != lhs.compare(rhs); }
inline bool operator< (const String& lhs, const String& rhs) { return lhs.compare(rhs) < 0; }
inline bool operator< (const char* lhs, const String& rhs) { return rhs.compare(lhs) > 0; }
inline bool operator< (const String& lhs, const char* rhs) { return lhs.compare(rhs) < 0; }
inline bool operator<= (const String& lhs, const String& rhs) { return lhs.compare(rhs) <= 0; }
inline bool operator<= (const char* lhs, const String& rhs) { return rhs.compare(lhs) >= 0; }
inline bool operator<= (const String& lhs, const char* rhs) { return lhs.compare(rhs) <= 0; }
inline bool operator> (const String& lhs, const String& rhs) { return lhs.compare(rhs) > 0; }
inline bool operator> (const char* lhs, const String& rhs) { return rhs.compare(lhs) < 0; }
inline bool operator> (const String& lhs, const char* rhs) { return lhs.compare(rhs) > 0; }
inline bool operator>= (const String& lhs, const String& rhs) { return lhs.compare(rhs) >= 0; }
inline bool operator>= (const char* lhs, const String& rhs) { return rhs.compare(lhs) <= 0; }
inline bool operator>= (const String& lhs, const char* rhs) { return lhs.compare(rhs) >= 0; }
} // cv
#ifndef OPENCV_NOSTL_TRANSITIONAL
namespace std
#else
namespace cv
#endif
{
template<> inline void swap<cv::String>(cv::String& a, cv::String& b) { a.swap(b); }
}
#endif //__OPENCV_CORE_CVSTD_HPP__

View File

@@ -0,0 +1,131 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef __OPENCV_CORE_CVSTDINL_HPP__
#define __OPENCV_CORE_CVSTDINL_HPP__
#ifndef OPENCV_NOSTL
# include <ostream>
#endif
namespace cv
{
#ifndef OPENCV_NOSTL
inline String::String(const std::string& str) : cstr_(0), len_(0)
{
if (!str.empty())
{
size_t len = str.size();
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 = max(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();
if (!str.empty())
{
size_t len = str.size();
memcpy(allocate(len), str.c_str(), len);
}
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);
memcpy(s.cstr_, lhs.cstr_, lhs.len_);
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_);
memcpy(s.cstr_, lhs.c_str(), lhslen);
memcpy(s.cstr_ + lhslen, rhs.cstr_, rhs.len_);
return s;
}
inline std::ostream& operator << (std::ostream& os, const String& str)
{
return os << str.c_str();
}
inline FileNode::operator std::string() const
{
String value;
read(*this, value, value);
return value;
}
template<> inline void operator >> (const FileNode& n, std::string& value)
{
String val;
read(n, val, val);
value = val;
}
#endif // OPENCV_NOSTL
} // cv
#endif // __OPENCV_CORE_CVSTDINL_HPP__

View File

@@ -247,7 +247,7 @@ namespace cv { namespace gpu
// Creates DeviceInfo object for the given GPU
DeviceInfo(int device_id) : device_id_(device_id) { query(); }
std::string name() const { return name_; }
String name() const { return name_; }
// Return compute capability versions
int majorVersion() const { return majorVersion_; }
@@ -274,7 +274,7 @@ namespace cv { namespace gpu
int device_id_;
std::string name_;
String name_;
int multi_processor_count_;
int majorVersion_;
int minorVersion_;

View File

@@ -2648,18 +2648,18 @@ template<> CV_EXPORTS void Ptr<CvFileStorage>::delete_obj();
//////////////////////////////////////// XML & YAML I/O ////////////////////////////////////
CV_EXPORTS_W void write( FileStorage& fs, const std::string& name, int value );
CV_EXPORTS_W void write( FileStorage& fs, const std::string& name, float value );
CV_EXPORTS_W void write( FileStorage& fs, const std::string& name, double value );
CV_EXPORTS_W void write( FileStorage& fs, const std::string& name, const std::string& value );
CV_EXPORTS_W void write( FileStorage& fs, const String& name, int value );
CV_EXPORTS_W void write( FileStorage& fs, const String& name, float value );
CV_EXPORTS_W void write( FileStorage& fs, const String& name, double value );
CV_EXPORTS_W void write( FileStorage& fs, const String& name, const String& value );
template<typename _Tp> inline void write(FileStorage& fs, const _Tp& value)
{ write(fs, std::string(), value); }
{ write(fs, String(), value); }
CV_EXPORTS void writeScalar( FileStorage& fs, int value );
CV_EXPORTS void writeScalar( FileStorage& fs, float value );
CV_EXPORTS void writeScalar( FileStorage& fs, double value );
CV_EXPORTS void writeScalar( FileStorage& fs, const std::string& value );
CV_EXPORTS void writeScalar( FileStorage& fs, const String& value );
template<> inline void write( FileStorage& fs, const int& value )
{
@@ -2676,7 +2676,7 @@ template<> inline void write( FileStorage& fs, const double& value )
writeScalar(fs, value);
}
template<> inline void write( FileStorage& fs, const std::string& value )
template<> inline void write( FileStorage& fs, const String& value )
{
writeScalar(fs, value);
}
@@ -2737,20 +2737,20 @@ inline void write(FileStorage& fs, const Range& r )
class CV_EXPORTS WriteStructContext
{
public:
WriteStructContext(FileStorage& _fs, const std::string& name,
int flags, const std::string& typeName=std::string());
WriteStructContext(FileStorage& _fs, const String& name,
int flags, const String& typeName=String());
~WriteStructContext();
FileStorage* fs;
};
template<typename _Tp> inline void write(FileStorage& fs, const std::string& name, const Point_<_Tp>& pt )
template<typename _Tp> inline void write(FileStorage& fs, const String& name, const Point_<_Tp>& pt )
{
WriteStructContext ws(fs, name, CV_NODE_SEQ+CV_NODE_FLOW);
write(fs, pt.x);
write(fs, pt.y);
}
template<typename _Tp> inline void write(FileStorage& fs, const std::string& name, const Point3_<_Tp>& pt )
template<typename _Tp> inline void write(FileStorage& fs, const String& name, const Point3_<_Tp>& pt )
{
WriteStructContext ws(fs, name, CV_NODE_SEQ+CV_NODE_FLOW);
write(fs, pt.x);
@@ -2758,21 +2758,21 @@ template<typename _Tp> inline void write(FileStorage& fs, const std::string& nam
write(fs, pt.z);
}
template<typename _Tp> inline void write(FileStorage& fs, const std::string& name, const Size_<_Tp>& sz )
template<typename _Tp> inline void write(FileStorage& fs, const String& name, const Size_<_Tp>& sz )
{
WriteStructContext ws(fs, name, CV_NODE_SEQ+CV_NODE_FLOW);
write(fs, sz.width);
write(fs, sz.height);
}
template<typename _Tp> inline void write(FileStorage& fs, const std::string& name, const Complex<_Tp>& c )
template<typename _Tp> inline void write(FileStorage& fs, const String& name, const Complex<_Tp>& c )
{
WriteStructContext ws(fs, name, CV_NODE_SEQ+CV_NODE_FLOW);
write(fs, c.re);
write(fs, c.im);
}
template<typename _Tp> inline void write(FileStorage& fs, const std::string& name, const Rect_<_Tp>& r )
template<typename _Tp> inline void write(FileStorage& fs, const String& name, const Rect_<_Tp>& r )
{
WriteStructContext ws(fs, name, CV_NODE_SEQ+CV_NODE_FLOW);
write(fs, r.x);
@@ -2781,14 +2781,14 @@ template<typename _Tp> inline void write(FileStorage& fs, const std::string& nam
write(fs, r.height);
}
template<typename _Tp, int cn> inline void write(FileStorage& fs, const std::string& name, const Vec<_Tp, cn>& v )
template<typename _Tp, int cn> inline void write(FileStorage& fs, const String& name, const Vec<_Tp, cn>& v )
{
WriteStructContext ws(fs, name, CV_NODE_SEQ+CV_NODE_FLOW);
for(int i = 0; i < cn; i++)
write(fs, v.val[i]);
}
template<typename _Tp> inline void write(FileStorage& fs, const std::string& name, const Scalar_<_Tp>& s )
template<typename _Tp> inline void write(FileStorage& fs, const String& name, const Scalar_<_Tp>& s )
{
WriteStructContext ws(fs, name, CV_NODE_SEQ+CV_NODE_FLOW);
write(fs, s.val[0]);
@@ -2797,7 +2797,7 @@ template<typename _Tp> inline void write(FileStorage& fs, const std::string& nam
write(fs, s.val[3]);
}
inline void write(FileStorage& fs, const std::string& name, const Range& r )
inline void write(FileStorage& fs, const String& name, const Range& r )
{
WriteStructContext ws(fs, name, CV_NODE_SEQ+CV_NODE_FLOW);
write(fs, r.start);
@@ -2825,7 +2825,7 @@ public:
{
int _fmt = DataType<_Tp>::fmt;
char fmt[] = { (char)((_fmt>>8)+'1'), (char)_fmt, '\0' };
fs->writeRaw( std::string(fmt), !vec.empty() ? (uchar*)&vec[0] : 0, vec.size()*sizeof(_Tp) );
fs->writeRaw( String(fmt), !vec.empty() ? (uchar*)&vec[0] : 0, vec.size()*sizeof(_Tp) );
}
FileStorage* fs;
};
@@ -2836,15 +2836,15 @@ template<typename _Tp> static inline void write( FileStorage& fs, const std::vec
w(vec);
}
template<typename _Tp> static inline void write( FileStorage& fs, const std::string& name,
template<typename _Tp> static inline void write( FileStorage& fs, const String& name,
const std::vector<_Tp>& vec )
{
WriteStructContext ws(fs, name, CV_NODE_SEQ+(DataType<_Tp>::fmt != 0 ? CV_NODE_FLOW : 0));
write(fs, vec);
}
CV_EXPORTS_W void write( FileStorage& fs, const std::string& name, const Mat& value );
CV_EXPORTS void write( FileStorage& fs, const std::string& name, const SparseMat& value );
CV_EXPORTS_W void write( FileStorage& fs, const String& name, const Mat& value );
CV_EXPORTS void write( FileStorage& fs, const String& name, const SparseMat& value );
template<typename _Tp> static inline FileStorage& operator << (FileStorage& fs, const _Tp& value)
{
@@ -2858,10 +2858,10 @@ template<typename _Tp> static inline FileStorage& operator << (FileStorage& fs,
return fs;
}
CV_EXPORTS FileStorage& operator << (FileStorage& fs, const std::string& str);
CV_EXPORTS FileStorage& operator << (FileStorage& fs, const String& str);
static inline FileStorage& operator << (FileStorage& fs, const char* str)
{ return (fs << std::string(str)); }
{ return (fs << String(str)); }
inline FileNode::FileNode() : fs(0), node(0) {}
inline FileNode::FileNode(const CvFileStorage* _fs, const CvFileNode* _node)
@@ -2939,9 +2939,9 @@ static inline void read(const FileNode& node, double& value, double default_valu
CV_NODE_IS_REAL(node.node->tag) ? node.node->data.f : 1e300;
}
static inline void read(const FileNode& node, std::string& value, const std::string& default_value)
static inline void read(const FileNode& node, String& value, const String& default_value)
{
value = !node.node ? default_value : CV_NODE_IS_STRING(node.node->tag) ? std::string(node.node->data.str.ptr) : std::string("");
value = !node.node ? default_value : CV_NODE_IS_STRING(node.node->tag) ? String(node.node->data.str.ptr) : String();
}
CV_EXPORTS_W void read(const FileNode& node, Mat& mat, const Mat& default_mat=Mat() );
@@ -2965,14 +2965,19 @@ inline FileNode::operator double() const
read(*this, value, 0.);
return value;
}
inline FileNode::operator std::string() const
inline FileNode::operator String() const
{
std::string value;
String value;
read(*this, value, value);
return value;
}
inline void FileNode::readRaw( const std::string& fmt, uchar* vec, size_t len ) const
inline String::String(const FileNode& fn): cstr_(0), len_(0)
{
read(fn, *this, *this);
}
inline void FileNode::readRaw( const String& fmt, uchar* vec, size_t len ) const
{
begin().readRaw( fmt, vec, len );
}
@@ -3003,7 +3008,7 @@ public:
size_t remaining1 = remaining/cn;
count = count < remaining1 ? count : remaining1;
vec.resize(count);
it->readRaw( std::string(fmt), !vec.empty() ? (uchar*)&vec[0] : 0, count*sizeof(_Tp) );
it->readRaw( String(fmt), !vec.empty() ? (uchar*)&vec[0] : 0, count*sizeof(_Tp) );
}
FileNodeIterator* it;
};
@@ -3694,7 +3699,7 @@ public:
{
FileStorage fs(_fs);
fs.fs.addref();
((const _ClsName*)ptr)->write(fs, std::string(name));
((const _ClsName*)ptr)->write(fs, String(name));
}
}
@@ -3856,7 +3861,7 @@ template<typename _Tp> inline std::ostream& operator<<(std::ostream& out, const
}
template<typename _Tp> inline Ptr<_Tp> Algorithm::create(const std::string& name)
template<typename _Tp> inline Ptr<_Tp> Algorithm::create(const String& name)
{
return _create(name).ptr<_Tp>();
}
@@ -3872,7 +3877,7 @@ inline void Algorithm::set(const char* _name, const Ptr<_Tp>& value)
}
template<typename _Tp>
inline void Algorithm::set(const std::string& _name, const Ptr<_Tp>& value)
inline void Algorithm::set(const String& _name, const Ptr<_Tp>& value)
{
this->set<_Tp>(_name.c_str(), value);
}
@@ -3888,12 +3893,12 @@ inline void Algorithm::setAlgorithm(const char* _name, const Ptr<_Tp>& value)
}
template<typename _Tp>
inline void Algorithm::setAlgorithm(const std::string& _name, const Ptr<_Tp>& value)
inline void Algorithm::setAlgorithm(const String& _name, const Ptr<_Tp>& value)
{
this->set<_Tp>(_name.c_str(), value);
}
template<typename _Tp> inline typename ParamType<_Tp>::member_type Algorithm::get(const std::string& _name) const
template<typename _Tp> inline typename ParamType<_Tp>::member_type Algorithm::get(const String& _name) const
{
typename ParamType<_Tp>::member_type value;
info()->get(this, _name.c_str(), ParamType<_Tp>::type, &value);
@@ -3909,7 +3914,7 @@ template<typename _Tp> inline typename ParamType<_Tp>::member_type Algorithm::ge
template<typename _Tp, typename _Base> inline void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
Ptr<_Tp>& value, bool readOnly, Ptr<_Tp> (Algorithm::*getter)(), void (Algorithm::*setter)(const Ptr<_Tp>&),
const std::string& help)
const String& help)
{
//TODO: static assert: _Tp inherits from _Base
addParam_(algo, parameter, ParamType<_Base>::type, &value, readOnly,
@@ -3918,7 +3923,7 @@ template<typename _Tp, typename _Base> inline void AlgorithmInfo::addParam(Algor
template<typename _Tp> inline void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
Ptr<_Tp>& value, bool readOnly, Ptr<_Tp> (Algorithm::*getter)(), void (Algorithm::*setter)(const Ptr<_Tp>&),
const std::string& help)
const String& help)
{
//TODO: static assert: _Tp inherits from Algorithm
addParam_(algo, parameter, ParamType<Algorithm>::type, &value, readOnly,

View File

@@ -143,14 +143,14 @@ typedef int (CV_CDECL *ErrorCallback)( int status, const char* func_name,
*/
CV_EXPORTS ErrorCallback redirectError( ErrorCallback errCallback, void* userdata=0, void** prevUserdata=0);
CV_EXPORTS std::string format( const char* fmt, ... );
CV_EXPORTS std::string tempfile( const char* suffix CV_DEFAULT(0));
CV_EXPORTS void glob(std::string pattern, std::vector<std::string>& result, bool recursive = false);
CV_EXPORTS String format( const char* fmt, ... );
CV_EXPORTS String tempfile( const char* suffix CV_DEFAULT(0));
CV_EXPORTS void glob(String pattern, std::vector<String>& result, bool recursive = false);
CV_EXPORTS void setNumThreads(int nthreads);
CV_EXPORTS int getNumThreads();
CV_EXPORTS int getThreadNum();
CV_EXPORTS_W const std::string& getBuildInformation();
CV_EXPORTS_W const String& getBuildInformation();
//! Returns the number of ticks.
@@ -297,19 +297,19 @@ protected:
class CV_EXPORTS CommandLineParser
{
public:
CommandLineParser(int argc, const char* const argv[], const std::string& keys);
CommandLineParser(int argc, const char* const argv[], const String& keys);
CommandLineParser(const CommandLineParser& parser);
CommandLineParser& operator = (const CommandLineParser& parser);
std::string getPathToApplication() const;
String getPathToApplication() const;
template <typename T>
T get(const std::string& name, bool space_delete = true) const
{
T get(const String& name, bool space_delete = true) const
{
T val = T();
getByName(name, space_delete, ParamType<T>::type, (void*)&val);
return val;
}
}
template <typename T>
T get(int index, bool space_delete = true) const
@@ -319,17 +319,17 @@ class CV_EXPORTS CommandLineParser
return val;
}
bool has(const std::string& name) const;
bool has(const String& name) const;
bool check() const;
void about(const std::string& message);
void about(const String& message);
void printMessage() const;
void printErrors() const;
protected:
void getByName(const std::string& name, bool space_delete, int type, void* dst) const;
void getByName(const String& name, bool space_delete, int type, void* dst) const;
void getByIndex(int index, bool space_delete, int type, void* dst) const;
struct Impl;
@@ -454,6 +454,17 @@ static inline Mat cvarrToMatND(const CvArr* arr, bool copyData=false, int coiMod
return cvarrToMat(arr, copyData, true, coiMode);
}
#ifndef OPENCV_NOSTL
template<> inline std::string CommandLineParser::get<std::string>(int index, bool space_delete) const
{
return get<String>(index, space_delete);
}
template<> inline std::string CommandLineParser::get<std::string>(const String& name, bool space_delete) const
{
return get<String>(name, space_delete);
}
#endif // OPENCV_NOSTL
} //namespace cv
#endif //__OPENCV_CORE_UTILITY_H__