1
/*M///////////////////////////////////////////////////////////////////////////////////////
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
11
// For Open Source Computer Vision Library
13
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
16
// Third party copyrights are property of their respective owners.
18
// Redistribution and use in source and binary forms, with or without modification,
19
// are permitted provided that the following conditions are met:
21
// * Redistribution's of source code must retain the above copyright notice,
22
// this list of conditions and the following disclaimer.
24
// * Redistribution's in binary form must reproduce the above copyright notice,
25
// this list of conditions and the following disclaimer in the documentation
26
// and/or other materials provided with the distribution.
28
// * The name of the copyright holders may not be used to endorse or promote products
29
// derived from this software without specific prior written permission.
31
// This software is provided by the copyright holders and contributors "as is" and
32
// any express or implied warranties, including, but not limited to, the implied
33
// warranties of merchantability and fitness for a particular purpose are disclaimed.
34
// In no event shall the Intel Corporation or contributors be liable for any direct,
35
// indirect, incidental, special, exemplary, or consequential damages
36
// (including, but not limited to, procurement of substitute goods or services;
37
// loss of use, data, or profits; or business interruption) however caused
38
// and on any theory of liability, whether in contract, strict liability,
39
// or tort (including negligence or otherwise) arising in any way out of
40
// the use of this software, even if advised of the possibility of such damage.
44
#ifndef __OPENCV_CORE_CVSTD_HPP__
45
#define __OPENCV_CORE_CVSTD_HPP__
48
# error cvstd.hpp header must be compiled as C++
51
#include "opencv2/core/cvdef.h"
61
// import useful primitives from stl
62
#ifndef OPENCV_NOSTL_TRANSITIONAL
65
# include <cstdlib> //for abs(int)
82
static inline uchar abs(uchar a) { return a; }
83
static inline ushort abs(ushort a) { return a; }
84
static inline unsigned abs(unsigned a) { return a; }
85
static inline uint64 abs(uint64 a) { return a; }
91
template<typename T> static inline T min(T a, T b) { return a < b ? a : b; }
92
template<typename T> static inline T max(T a, T b) { return a > b ? a : b; }
93
template<typename T> static inline T abs(T a) { return a < 0 ? -a : a; }
94
template<typename T> static inline void swap(T& a, T& b) { T tmp = a; a = b; b = tmp; }
96
template<> inline uchar abs(uchar a) { return a; }
97
template<> inline ushort abs(ushort a) { return a; }
98
template<> inline unsigned abs(unsigned a) { return a; }
99
template<> inline uint64 abs(uint64 a) { return a; }
105
//! @addtogroup core_utils
108
//////////////////////////// memory management functions ////////////////////////////
110
/** @brief Allocates an aligned memory buffer.
112
The function allocates the buffer of the specified size and returns it. When the buffer size is 16
113
bytes or more, the returned buffer is aligned to 16 bytes.
114
@param bufSize Allocated buffer size.
116
CV_EXPORTS void* fastMalloc(size_t bufSize);
118
/** @brief Deallocates a memory buffer.
120
The function deallocates the buffer allocated with fastMalloc . If NULL pointer is passed, the
121
function does nothing. C version of the function clears the pointer *pptr* to avoid problems with
122
double memory deallocation.
123
@param ptr Pointer to the allocated buffer.
125
CV_EXPORTS void fastFree(void* ptr);
128
The STL-compilant memory Allocator based on cv::fastMalloc() and cv::fastFree()
130
template<typename _Tp> class Allocator
133
typedef _Tp value_type;
134
typedef value_type* pointer;
135
typedef const value_type* const_pointer;
136
typedef value_type& reference;
137
typedef const value_type& const_reference;
138
typedef size_t size_type;
139
typedef ptrdiff_t difference_type;
140
template<typename U> class rebind { typedef Allocator<U> other; };
142
explicit Allocator() {}
144
explicit Allocator(Allocator const&) {}
146
explicit Allocator(Allocator<U> const&) {}
149
pointer address(reference r) { return &r; }
150
const_pointer address(const_reference r) { return &r; }
152
pointer allocate(size_type count, const void* =0) { return reinterpret_cast<pointer>(fastMalloc(count * sizeof (_Tp))); }
153
void deallocate(pointer p, size_type) { fastFree(p); }
155
void construct(pointer p, const _Tp& v) { new(static_cast<void*>(p)) _Tp(v); }
156
void destroy(pointer p) { p->~_Tp(); }
158
size_type max_size() const { return cv::max(static_cast<_Tp>(-1)/sizeof(_Tp), 1); }
168
// Metafunction to avoid taking a reference to void.
170
struct RefOrVoid { typedef T& type; };
173
struct RefOrVoid<void>{ typedef void type; };
176
struct RefOrVoid<const void>{ typedef const void type; };
179
struct RefOrVoid<volatile void>{ typedef volatile void type; };
182
struct RefOrVoid<const volatile void>{ typedef const volatile void type; };
184
// This class would be private to Ptr, if it didn't have to be a non-template.
190
struct DefaultDeleter
192
void operator () (Y* p) const;
197
//! @addtogroup core_basic
200
/** @brief Template class for smart pointers with shared ownership
202
A Ptr\<T\> pretends to be a pointer to an object of type T. Unlike an ordinary pointer, however, the
203
object will be automatically cleaned up once all Ptr instances pointing to it are destroyed.
205
Ptr is similar to boost::shared_ptr that is part of the Boost library
206
(<http://www.boost.org/doc/libs/release/libs/smart_ptr/shared_ptr.htm>) and std::shared_ptr from
207
the [C++11](http://en.wikipedia.org/wiki/C++11) standard.
209
This class provides the following advantages:
210
- Default constructor, copy constructor, and assignment operator for an arbitrary C++ class or C
211
structure. For some objects, like files, windows, mutexes, sockets, and others, a copy
212
constructor or an assignment operator are difficult to define. For some other objects, like
213
complex classifiers in OpenCV, copy constructors are absent and not easy to implement. Finally,
214
some of complex OpenCV and your own data structures may be written in C. However, copy
215
constructors and default constructors can simplify programming a lot. Besides, they are often
216
required (for example, by STL containers). By using a Ptr to such an object instead of the
217
object itself, you automatically get all of the necessary constructors and the assignment
219
- *O(1)* complexity of the above-mentioned operations. While some structures, like std::vector,
220
provide a copy constructor and an assignment operator, the operations may take a considerable
221
amount of time if the data structures are large. But if the structures are put into a Ptr, the
222
overhead is small and independent of the data size.
223
- Automatic and customizable cleanup, even for C structures. See the example below with FILE\*.
224
- Heterogeneous collections of objects. The standard STL and most other C++ and OpenCV containers
225
can store only objects of the same type and the same size. The classical solution to store
226
objects of different types in the same container is to store pointers to the base class (Base\*)
227
instead but then you lose the automatic memory management. Again, by using Ptr\<Base\> instead
228
of raw pointers, you can solve the problem.
230
A Ptr is said to *own* a pointer - that is, for each Ptr there is a pointer that will be deleted
231
once all Ptr instances that own it are destroyed. The owned pointer may be null, in which case
232
nothing is deleted. Each Ptr also *stores* a pointer. The stored pointer is the pointer the Ptr
233
pretends to be; that is, the one you get when you use Ptr::get or the conversion to T\*. It's
234
usually the same as the owned pointer, but if you use casts or the general shared-ownership
235
constructor, the two may diverge: the Ptr will still own the original pointer, but will itself point
238
The owned pointer is treated as a black box. The only thing Ptr needs to know about it is how to
239
delete it. This knowledge is encapsulated in the *deleter* - an auxiliary object that is associated
240
with the owned pointer and shared between all Ptr instances that own it. The default deleter is an
241
instance of DefaultDeleter, which uses the standard C++ delete operator; as such it will work with
242
any pointer allocated with the standard new operator.
244
However, if the pointer must be deleted in a different way, you must specify a custom deleter upon
245
Ptr construction. A deleter is simply a callable object that accepts the pointer as its sole
246
argument. For example, if you want to wrap FILE, you may do so as follows:
248
Ptr<FILE> f(fopen("myfile.txt", "w"), fclose);
252
// the file will be closed automatically by f's destructor.
254
Alternatively, if you want all pointers of a particular type to be deleted the same way, you can
255
specialize DefaultDeleter<T>::operator() for that type, like this:
258
template<> void DefaultDeleter<FILE>::operator ()(FILE * obj) const
264
For convenience, the following types from the OpenCV C API already have such a specialization that
265
calls the appropriate release function:
268
- CvHaarClassifierCascade
275
@note The shared ownership mechanism is implemented with reference counting. As such, cyclic
276
ownership (e.g. when object a contains a Ptr to object b, which contains a Ptr to object a) will
277
lead to all involved objects never being cleaned up. Avoid such situations.
278
@note It is safe to concurrently read (but not write) a Ptr instance from multiple threads and
279
therefore it is normally safe to use it in multi-threaded applications. The same is true for Mat and
280
other C++ OpenCV classes that use internal reference counts.
285
/** Generic programming support. */
286
typedef T element_type;
288
/** The default constructor creates a null Ptr - one that owns and stores a null pointer.
293
If p is null, these are equivalent to the default constructor.
294
Otherwise, these constructors assume ownership of p - that is, the created Ptr owns and stores p
295
and assumes it is the sole owner of it. Don't use them if p is already owned by another Ptr, or
296
else p will get deleted twice.
297
With the first constructor, DefaultDeleter\<Y\>() becomes the associated deleter (so p will
298
eventually be deleted with the standard delete operator). Y must be a complete type at the point
300
With the second constructor, d becomes the associated deleter.
301
Y\* must be convertible to T\*.
302
@param p Pointer to own.
303
@note It is often easier to use makePtr instead.
306
#ifdef DISABLE_OPENCV_24_COMPATIBILITY
312
@param d Deleter to use for the owned pointer.
313
@param p Pointer to own.
315
template<typename Y, typename D>
319
These constructors create a Ptr that shares ownership with another Ptr - that is, own the same
321
With the first two, the same pointer is stored, as well; for the second, Y\* must be convertible
323
With the third, p is stored, and Y may be any type. This constructor allows to have completely
324
unrelated owned and stored pointers, and should be used with care to avoid confusion. A relatively
325
benign use is to create a non-owning Ptr, like this:
327
ptr = Ptr<T>(Ptr<T>(), dont_delete_me); // owns nothing; will not delete the pointer.
329
@param o Ptr to share ownership with.
334
@param o Ptr to share ownership with.
337
Ptr(const Ptr<Y>& o);
340
@param o Ptr to share ownership with.
341
@param p Pointer to store.
344
Ptr(const Ptr<Y>& o, T* p);
346
/** The destructor is equivalent to calling Ptr::release. */
350
Assignment replaces the current Ptr instance with one that owns and stores same pointers as o and
351
then destroys the old instance.
352
@param o Ptr to share ownership with.
354
Ptr& operator = (const Ptr& o);
358
Ptr& operator = (const Ptr<Y>& o);
360
/** If no other Ptr instance owns the owned pointer, deletes it with the associated deleter. Then sets
361
both the owned and the stored pointers to NULL.
366
`ptr.reset(...)` is equivalent to `ptr = Ptr<T>(...)`.
367
@param p Pointer to own.
373
@param d Deleter to use for the owned pointer.
374
@param p Pointer to own.
376
template<typename Y, typename D>
377
void reset(Y* p, D d);
380
Swaps the owned and stored pointers (and deleters, if any) of this and o.
381
@param o Ptr to swap with.
385
/** Returns the stored pointer. */
388
/** Ordinary pointer emulation. */
389
typename detail::RefOrVoid<T>::type operator * () const;
391
/** Ordinary pointer emulation. */
392
T* operator -> () const;
394
/** Equivalent to get(). */
395
operator T* () const;
397
/** ptr.empty() is equivalent to `!ptr.get()`. */
400
/** Returns a Ptr that owns the same pointer as this, and stores the same
401
pointer as this, except converted via static_cast to Y*.
404
Ptr<Y> staticCast() const;
406
/** Ditto for const_cast. */
408
Ptr<Y> constCast() const;
410
/** Ditto for dynamic_cast. */
412
Ptr<Y> dynamicCast() const;
414
#ifdef CV_CXX_MOVE_SEMANTICS
416
Ptr& operator = (Ptr&& o);
420
detail::PtrOwner* owner;
424
friend struct Ptr; // have to do this for the cross-type copy constructor
427
/** Equivalent to ptr1.swap(ptr2). Provided to help write generic algorithms. */
429
void swap(Ptr<T>& ptr1, Ptr<T>& ptr2);
431
/** Return whether ptr1.get() and ptr2.get() are equal and not equal, respectively. */
433
bool operator == (const Ptr<T>& ptr1, const Ptr<T>& ptr2);
435
bool operator != (const Ptr<T>& ptr1, const Ptr<T>& ptr2);
437
/** `makePtr<T>(...)` is equivalent to `Ptr<T>(new T(...))`. It is shorter than the latter, and it's
438
marginally safer than using a constructor or Ptr::reset, since it ensures that the owned pointer
439
is new and thus not owned by any other Ptr instance.
440
Unfortunately, perfect forwarding is impossible to implement in C++03, and so makePtr is limited
441
to constructors of T that have up to 10 arguments, none of which are non-const references.
446
template<typename T, typename A1>
447
Ptr<T> makePtr(const A1& a1);
449
template<typename T, typename A1, typename A2>
450
Ptr<T> makePtr(const A1& a1, const A2& a2);
452
template<typename T, typename A1, typename A2, typename A3>
453
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3);
455
template<typename T, typename A1, typename A2, typename A3, typename A4>
456
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4);
458
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5>
459
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5);
461
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
462
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6);
464
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7>
465
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7);
467
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8>
468
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8);
470
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9>
471
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9);
473
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9, typename A10>
474
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10);
476
//////////////////////////////// string class ////////////////////////////////
478
class CV_EXPORTS FileNode; //for string constructor from FileNode
480
class CV_EXPORTS String
483
typedef char value_type;
484
typedef char& reference;
485
typedef const char& const_reference;
486
typedef char* pointer;
487
typedef const char* const_pointer;
488
typedef ptrdiff_t difference_type;
489
typedef size_t size_type;
490
typedef char* iterator;
491
typedef const char* const_iterator;
493
static const size_t npos = size_t(-1);
496
String(const String& str);
497
String(const String& str, size_t pos, size_t len = npos);
498
String(const char* s);
499
String(const char* s, size_t n);
500
String(size_t n, char c);
501
String(const char* first, const char* last);
502
template<typename Iterator> String(Iterator first, Iterator last);
503
explicit String(const FileNode& fn);
506
String& operator=(const String& str);
507
String& operator=(const char* s);
508
String& operator=(char c);
510
String& operator+=(const String& str);
511
String& operator+=(const char* s);
512
String& operator+=(char c);
515
size_t length() const;
517
char operator[](size_t idx) const;
518
char operator[](int idx) const;
520
const char* begin() const;
521
const char* end() const;
523
const char* c_str() const;
528
int compare(const char* s) const;
529
int compare(const String& str) const;
531
void swap(String& str);
532
String substr(size_t pos = 0, size_t len = npos) const;
534
size_t find(const char* s, size_t pos, size_t n) const;
535
size_t find(char c, size_t pos = 0) const;
536
size_t find(const String& str, size_t pos = 0) const;
537
size_t find(const char* s, size_t pos = 0) const;
539
size_t rfind(const char* s, size_t pos, size_t n) const;
540
size_t rfind(char c, size_t pos = npos) const;
541
size_t rfind(const String& str, size_t pos = npos) const;
542
size_t rfind(const char* s, size_t pos = npos) const;
544
size_t find_first_of(const char* s, size_t pos, size_t n) const;
545
size_t find_first_of(char c, size_t pos = 0) const;
546
size_t find_first_of(const String& str, size_t pos = 0) const;
547
size_t find_first_of(const char* s, size_t pos = 0) const;
549
size_t find_last_of(const char* s, size_t pos, size_t n) const;
550
size_t find_last_of(char c, size_t pos = npos) const;
551
size_t find_last_of(const String& str, size_t pos = npos) const;
552
size_t find_last_of(const char* s, size_t pos = npos) const;
554
friend String operator+ (const String& lhs, const String& rhs);
555
friend String operator+ (const String& lhs, const char* rhs);
556
friend String operator+ (const char* lhs, const String& rhs);
557
friend String operator+ (const String& lhs, char rhs);
558
friend String operator+ (char lhs, const String& rhs);
560
String toLowerCase() const;
563
String(const std::string& str);
564
String(const std::string& str, size_t pos, size_t len = npos);
565
String& operator=(const std::string& str);
566
String& operator+=(const std::string& str);
567
operator std::string() const;
569
friend String operator+ (const String& lhs, const std::string& rhs);
570
friend String operator+ (const std::string& lhs, const String& rhs);
577
char* allocate(size_t len); // len without trailing 0
580
String(int); // disabled and invalid. Catch invalid usages like, commandLineParser.has(0) problem
585
////////////////////////// cv::String implementation /////////////////////////
595
String::String(const String& str)
596
: cstr_(str.cstr_), len_(str.len_)
599
CV_XADD(((int*)cstr_)-1, 1);
603
String::String(const String& str, size_t pos, size_t len)
606
pos = min(pos, str.len_);
607
len = min(str.len_ - pos, len);
611
CV_XADD(((int*)str.cstr_)-1, 1);
616
memcpy(allocate(len), str.cstr_ + pos, len);
620
String::String(const char* s)
624
size_t len = strlen(s);
625
memcpy(allocate(len), s, len);
629
String::String(const char* s, size_t n)
633
memcpy(allocate(n), s, n);
637
String::String(size_t n, char c)
640
memset(allocate(n), c, n);
644
String::String(const char* first, const char* last)
647
size_t len = (size_t)(last - first);
648
memcpy(allocate(len), first, len);
651
template<typename Iterator> inline
652
String::String(Iterator first, Iterator last)
655
size_t len = (size_t)(last - first);
656
char* str = allocate(len);
657
while (first != last)
671
String& String::operator=(const String& str)
673
if (&str == this) return *this;
676
if (str.cstr_) CV_XADD(((int*)str.cstr_)-1, 1);
683
String& String::operator=(const char* s)
686
if (!s) return *this;
687
size_t len = strlen(s);
688
memcpy(allocate(len), s, len);
693
String& String::operator=(char c)
701
String& String::operator+=(const String& str)
708
String& String::operator+=(const char* s)
715
String& String::operator+=(char c)
722
size_t String::size() const
728
size_t String::length() const
734
char String::operator[](size_t idx) const
740
char String::operator[](int idx) const
746
const char* String::begin() const
752
const char* String::end() const
754
return len_ ? cstr_ + 1 : 0;
758
bool String::empty() const
764
const char* String::c_str() const
766
return cstr_ ? cstr_ : "";
770
void String::swap(String& str)
772
cv::swap(cstr_, str.cstr_);
773
cv::swap(len_, str.len_);
783
int String::compare(const char* s) const
785
if (cstr_ == s) return 0;
786
return strcmp(c_str(), s);
790
int String::compare(const String& str) const
792
if (cstr_ == str.cstr_) return 0;
793
return strcmp(c_str(), str.c_str());
797
String String::substr(size_t pos, size_t len) const
799
return String(*this, pos, len);
803
size_t String::find(const char* s, size_t pos, size_t n) const
805
if (n == 0 || pos + n > len_) return npos;
806
const char* lmax = cstr_ + len_ - n;
807
for (const char* i = cstr_ + pos; i <= lmax; ++i)
810
while (j < n && s[j] == i[j]) ++j;
811
if (j == n) return (size_t)(i - cstr_);
817
size_t String::find(char c, size_t pos) const
819
return find(&c, pos, 1);
823
size_t String::find(const String& str, size_t pos) const
825
return find(str.c_str(), pos, str.len_);
829
size_t String::find(const char* s, size_t pos) const
831
if (pos >= len_ || !s[0]) return npos;
832
const char* lmax = cstr_ + len_;
833
for (const char* i = cstr_ + pos; i < lmax; ++i)
836
while (s[j] && s[j] == i[j])
837
{ if(i + j >= lmax) return npos;
840
if (!s[j]) return (size_t)(i - cstr_);
846
size_t String::rfind(const char* s, size_t pos, size_t n) const
848
if (n > len_) return npos;
849
if (pos > len_ - n) pos = len_ - n;
850
for (const char* i = cstr_ + pos; i >= cstr_; --i)
853
while (j < n && s[j] == i[j]) ++j;
854
if (j == n) return (size_t)(i - cstr_);
860
size_t String::rfind(char c, size_t pos) const
862
return rfind(&c, pos, 1);
866
size_t String::rfind(const String& str, size_t pos) const
868
return rfind(str.c_str(), pos, str.len_);
872
size_t String::rfind(const char* s, size_t pos) const
874
return rfind(s, pos, strlen(s));
878
size_t String::find_first_of(const char* s, size_t pos, size_t n) const
880
if (n == 0 || pos + n > len_) return npos;
881
const char* lmax = cstr_ + len_;
882
for (const char* i = cstr_ + pos; i < lmax; ++i)
884
for (size_t j = 0; j < n; ++j)
886
return (size_t)(i - cstr_);
892
size_t String::find_first_of(char c, size_t pos) const
894
return find_first_of(&c, pos, 1);
898
size_t String::find_first_of(const String& str, size_t pos) const
900
return find_first_of(str.c_str(), pos, str.len_);
904
size_t String::find_first_of(const char* s, size_t pos) const
906
if (len_ == 0) return npos;
907
if (pos >= len_ || !s[0]) return npos;
908
const char* lmax = cstr_ + len_;
909
for (const char* i = cstr_ + pos; i < lmax; ++i)
911
for (size_t j = 0; s[j]; ++j)
913
return (size_t)(i - cstr_);
919
size_t String::find_last_of(const char* s, size_t pos, size_t n) const
921
if (len_ == 0) return npos;
922
if (pos >= len_) pos = len_ - 1;
923
for (const char* i = cstr_ + pos; i >= cstr_; --i)
925
for (size_t j = 0; j < n; ++j)
927
return (size_t)(i - cstr_);
933
size_t String::find_last_of(char c, size_t pos) const
935
return find_last_of(&c, pos, 1);
939
size_t String::find_last_of(const String& str, size_t pos) const
941
return find_last_of(str.c_str(), pos, str.len_);
945
size_t String::find_last_of(const char* s, size_t pos) const
947
if (len_ == 0) return npos;
948
if (pos >= len_) pos = len_ - 1;
949
for (const char* i = cstr_ + pos; i >= cstr_; --i)
951
for (size_t j = 0; s[j]; ++j)
953
return (size_t)(i - cstr_);
959
String String::toLowerCase() const
961
String res(cstr_, len_);
963
for (size_t i = 0; i < len_; ++i)
964
res.cstr_[i] = (char) ::tolower(cstr_[i]);
971
// ************************* cv::String non-member functions *************************
973
//! @relates cv::String
977
String operator + (const String& lhs, const String& rhs)
980
s.allocate(lhs.len_ + rhs.len_);
981
memcpy(s.cstr_, lhs.cstr_, lhs.len_);
982
memcpy(s.cstr_ + lhs.len_, rhs.cstr_, rhs.len_);
987
String operator + (const String& lhs, const char* rhs)
990
size_t rhslen = strlen(rhs);
991
s.allocate(lhs.len_ + rhslen);
992
memcpy(s.cstr_, lhs.cstr_, lhs.len_);
993
memcpy(s.cstr_ + lhs.len_, rhs, rhslen);
998
String operator + (const char* lhs, const String& rhs)
1001
size_t lhslen = strlen(lhs);
1002
s.allocate(lhslen + rhs.len_);
1003
memcpy(s.cstr_, lhs, lhslen);
1004
memcpy(s.cstr_ + lhslen, rhs.cstr_, rhs.len_);
1009
String operator + (const String& lhs, char rhs)
1012
s.allocate(lhs.len_ + 1);
1013
memcpy(s.cstr_, lhs.cstr_, lhs.len_);
1014
s.cstr_[lhs.len_] = rhs;
1019
String operator + (char lhs, const String& rhs)
1022
s.allocate(rhs.len_ + 1);
1024
memcpy(s.cstr_ + 1, rhs.cstr_, rhs.len_);
1028
static inline bool operator== (const String& lhs, const String& rhs) { return 0 == lhs.compare(rhs); }
1029
static inline bool operator== (const char* lhs, const String& rhs) { return 0 == rhs.compare(lhs); }
1030
static inline bool operator== (const String& lhs, const char* rhs) { return 0 == lhs.compare(rhs); }
1031
static inline bool operator!= (const String& lhs, const String& rhs) { return 0 != lhs.compare(rhs); }
1032
static inline bool operator!= (const char* lhs, const String& rhs) { return 0 != rhs.compare(lhs); }
1033
static inline bool operator!= (const String& lhs, const char* rhs) { return 0 != lhs.compare(rhs); }
1034
static inline bool operator< (const String& lhs, const String& rhs) { return lhs.compare(rhs) < 0; }
1035
static inline bool operator< (const char* lhs, const String& rhs) { return rhs.compare(lhs) > 0; }
1036
static inline bool operator< (const String& lhs, const char* rhs) { return lhs.compare(rhs) < 0; }
1037
static inline bool operator<= (const String& lhs, const String& rhs) { return lhs.compare(rhs) <= 0; }
1038
static inline bool operator<= (const char* lhs, const String& rhs) { return rhs.compare(lhs) >= 0; }
1039
static inline bool operator<= (const String& lhs, const char* rhs) { return lhs.compare(rhs) <= 0; }
1040
static inline bool operator> (const String& lhs, const String& rhs) { return lhs.compare(rhs) > 0; }
1041
static inline bool operator> (const char* lhs, const String& rhs) { return rhs.compare(lhs) < 0; }
1042
static inline bool operator> (const String& lhs, const char* rhs) { return lhs.compare(rhs) > 0; }
1043
static inline bool operator>= (const String& lhs, const String& rhs) { return lhs.compare(rhs) >= 0; }
1044
static inline bool operator>= (const char* lhs, const String& rhs) { return rhs.compare(lhs) <= 0; }
1045
static inline bool operator>= (const String& lhs, const char* rhs) { return lhs.compare(rhs) >= 0; }
1047
//! @} relates cv::String
1051
#ifndef OPENCV_NOSTL_TRANSITIONAL
1054
static inline void swap(cv::String& a, cv::String& b) { a.swap(b); }
1060
void swap<cv::String>(cv::String& a, cv::String& b)
1067
#include "opencv2/core/ptr.inl.hpp"
1069
#endif //__OPENCV_CORE_CVSTD_HPP__