openCV library for Renesas RZ/A
Dependents: RZ_A2M_Mbed_samples
include/opencv2/core/cvstd.hpp@0:0e0631af0305, 2021-01-29 (annotated)
- Committer:
- RyoheiHagimoto
- Date:
- Fri Jan 29 04:53:38 2021 +0000
- Revision:
- 0:0e0631af0305
copied from https://github.com/d-kato/opencv-lib.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| RyoheiHagimoto | 0:0e0631af0305 | 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// |
| RyoheiHagimoto | 0:0e0631af0305 | 2 | // |
| RyoheiHagimoto | 0:0e0631af0305 | 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. |
| RyoheiHagimoto | 0:0e0631af0305 | 4 | // |
| RyoheiHagimoto | 0:0e0631af0305 | 5 | // By downloading, copying, installing or using the software you agree to this license. |
| RyoheiHagimoto | 0:0e0631af0305 | 6 | // If you do not agree to this license, do not download, install, |
| RyoheiHagimoto | 0:0e0631af0305 | 7 | // copy or use the software. |
| RyoheiHagimoto | 0:0e0631af0305 | 8 | // |
| RyoheiHagimoto | 0:0e0631af0305 | 9 | // |
| RyoheiHagimoto | 0:0e0631af0305 | 10 | // License Agreement |
| RyoheiHagimoto | 0:0e0631af0305 | 11 | // For Open Source Computer Vision Library |
| RyoheiHagimoto | 0:0e0631af0305 | 12 | // |
| RyoheiHagimoto | 0:0e0631af0305 | 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. |
| RyoheiHagimoto | 0:0e0631af0305 | 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. |
| RyoheiHagimoto | 0:0e0631af0305 | 15 | // Copyright (C) 2013, OpenCV Foundation, all rights reserved. |
| RyoheiHagimoto | 0:0e0631af0305 | 16 | // Third party copyrights are property of their respective owners. |
| RyoheiHagimoto | 0:0e0631af0305 | 17 | // |
| RyoheiHagimoto | 0:0e0631af0305 | 18 | // Redistribution and use in source and binary forms, with or without modification, |
| RyoheiHagimoto | 0:0e0631af0305 | 19 | // are permitted provided that the following conditions are met: |
| RyoheiHagimoto | 0:0e0631af0305 | 20 | // |
| RyoheiHagimoto | 0:0e0631af0305 | 21 | // * Redistribution's of source code must retain the above copyright notice, |
| RyoheiHagimoto | 0:0e0631af0305 | 22 | // this list of conditions and the following disclaimer. |
| RyoheiHagimoto | 0:0e0631af0305 | 23 | // |
| RyoheiHagimoto | 0:0e0631af0305 | 24 | // * Redistribution's in binary form must reproduce the above copyright notice, |
| RyoheiHagimoto | 0:0e0631af0305 | 25 | // this list of conditions and the following disclaimer in the documentation |
| RyoheiHagimoto | 0:0e0631af0305 | 26 | // and/or other materials provided with the distribution. |
| RyoheiHagimoto | 0:0e0631af0305 | 27 | // |
| RyoheiHagimoto | 0:0e0631af0305 | 28 | // * The name of the copyright holders may not be used to endorse or promote products |
| RyoheiHagimoto | 0:0e0631af0305 | 29 | // derived from this software without specific prior written permission. |
| RyoheiHagimoto | 0:0e0631af0305 | 30 | // |
| RyoheiHagimoto | 0:0e0631af0305 | 31 | // This software is provided by the copyright holders and contributors "as is" and |
| RyoheiHagimoto | 0:0e0631af0305 | 32 | // any express or implied warranties, including, but not limited to, the implied |
| RyoheiHagimoto | 0:0e0631af0305 | 33 | // warranties of merchantability and fitness for a particular purpose are disclaimed. |
| RyoheiHagimoto | 0:0e0631af0305 | 34 | // In no event shall the Intel Corporation or contributors be liable for any direct, |
| RyoheiHagimoto | 0:0e0631af0305 | 35 | // indirect, incidental, special, exemplary, or consequential damages |
| RyoheiHagimoto | 0:0e0631af0305 | 36 | // (including, but not limited to, procurement of substitute goods or services; |
| RyoheiHagimoto | 0:0e0631af0305 | 37 | // loss of use, data, or profits; or business interruption) however caused |
| RyoheiHagimoto | 0:0e0631af0305 | 38 | // and on any theory of liability, whether in contract, strict liability, |
| RyoheiHagimoto | 0:0e0631af0305 | 39 | // or tort (including negligence or otherwise) arising in any way out of |
| RyoheiHagimoto | 0:0e0631af0305 | 40 | // the use of this software, even if advised of the possibility of such damage. |
| RyoheiHagimoto | 0:0e0631af0305 | 41 | // |
| RyoheiHagimoto | 0:0e0631af0305 | 42 | //M*/ |
| RyoheiHagimoto | 0:0e0631af0305 | 43 | |
| RyoheiHagimoto | 0:0e0631af0305 | 44 | #ifndef OPENCV_CORE_CVSTD_HPP |
| RyoheiHagimoto | 0:0e0631af0305 | 45 | #define OPENCV_CORE_CVSTD_HPP |
| RyoheiHagimoto | 0:0e0631af0305 | 46 | |
| RyoheiHagimoto | 0:0e0631af0305 | 47 | #ifndef __cplusplus |
| RyoheiHagimoto | 0:0e0631af0305 | 48 | # error cvstd.hpp header must be compiled as C++ |
| RyoheiHagimoto | 0:0e0631af0305 | 49 | #endif |
| RyoheiHagimoto | 0:0e0631af0305 | 50 | |
| RyoheiHagimoto | 0:0e0631af0305 | 51 | #include "opencv2/core/cvdef.h" |
| RyoheiHagimoto | 0:0e0631af0305 | 52 | |
| RyoheiHagimoto | 0:0e0631af0305 | 53 | #include <cstddef> |
| RyoheiHagimoto | 0:0e0631af0305 | 54 | #include <cstring> |
| RyoheiHagimoto | 0:0e0631af0305 | 55 | #include <cctype> |
| RyoheiHagimoto | 0:0e0631af0305 | 56 | |
| RyoheiHagimoto | 0:0e0631af0305 | 57 | #ifndef OPENCV_NOSTL |
| RyoheiHagimoto | 0:0e0631af0305 | 58 | # include <string> |
| RyoheiHagimoto | 0:0e0631af0305 | 59 | #endif |
| RyoheiHagimoto | 0:0e0631af0305 | 60 | |
| RyoheiHagimoto | 0:0e0631af0305 | 61 | // import useful primitives from stl |
| RyoheiHagimoto | 0:0e0631af0305 | 62 | #ifndef OPENCV_NOSTL_TRANSITIONAL |
| RyoheiHagimoto | 0:0e0631af0305 | 63 | # include <algorithm> |
| RyoheiHagimoto | 0:0e0631af0305 | 64 | # include <utility> |
| RyoheiHagimoto | 0:0e0631af0305 | 65 | # include <cstdlib> //for abs(int) |
| RyoheiHagimoto | 0:0e0631af0305 | 66 | # include <cmath> |
| RyoheiHagimoto | 0:0e0631af0305 | 67 | |
| RyoheiHagimoto | 0:0e0631af0305 | 68 | namespace cv |
| RyoheiHagimoto | 0:0e0631af0305 | 69 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 70 | static inline uchar abs(uchar a) { return a; } |
| RyoheiHagimoto | 0:0e0631af0305 | 71 | static inline ushort abs(ushort a) { return a; } |
| RyoheiHagimoto | 0:0e0631af0305 | 72 | static inline unsigned abs(unsigned a) { return a; } |
| RyoheiHagimoto | 0:0e0631af0305 | 73 | static inline uint64 abs(uint64 a) { return a; } |
| RyoheiHagimoto | 0:0e0631af0305 | 74 | |
| RyoheiHagimoto | 0:0e0631af0305 | 75 | using std::min; |
| RyoheiHagimoto | 0:0e0631af0305 | 76 | using std::max; |
| RyoheiHagimoto | 0:0e0631af0305 | 77 | using std::abs; |
| RyoheiHagimoto | 0:0e0631af0305 | 78 | using std::swap; |
| RyoheiHagimoto | 0:0e0631af0305 | 79 | using std::sqrt; |
| RyoheiHagimoto | 0:0e0631af0305 | 80 | using std::exp; |
| RyoheiHagimoto | 0:0e0631af0305 | 81 | using std::pow; |
| RyoheiHagimoto | 0:0e0631af0305 | 82 | using std::log; |
| RyoheiHagimoto | 0:0e0631af0305 | 83 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 84 | |
| RyoheiHagimoto | 0:0e0631af0305 | 85 | #else |
| RyoheiHagimoto | 0:0e0631af0305 | 86 | namespace cv |
| RyoheiHagimoto | 0:0e0631af0305 | 87 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 88 | template<typename T> static inline T min(T a, T b) { return a < b ? a : b; } |
| RyoheiHagimoto | 0:0e0631af0305 | 89 | template<typename T> static inline T max(T a, T b) { return a > b ? a : b; } |
| RyoheiHagimoto | 0:0e0631af0305 | 90 | template<typename T> static inline T abs(T a) { return a < 0 ? -a : a; } |
| RyoheiHagimoto | 0:0e0631af0305 | 91 | template<typename T> static inline void swap(T& a, T& b) { T tmp = a; a = b; b = tmp; } |
| RyoheiHagimoto | 0:0e0631af0305 | 92 | |
| RyoheiHagimoto | 0:0e0631af0305 | 93 | template<> inline uchar abs(uchar a) { return a; } |
| RyoheiHagimoto | 0:0e0631af0305 | 94 | template<> inline ushort abs(ushort a) { return a; } |
| RyoheiHagimoto | 0:0e0631af0305 | 95 | template<> inline unsigned abs(unsigned a) { return a; } |
| RyoheiHagimoto | 0:0e0631af0305 | 96 | template<> inline uint64 abs(uint64 a) { return a; } |
| RyoheiHagimoto | 0:0e0631af0305 | 97 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 98 | #endif |
| RyoheiHagimoto | 0:0e0631af0305 | 99 | |
| RyoheiHagimoto | 0:0e0631af0305 | 100 | namespace cv { |
| RyoheiHagimoto | 0:0e0631af0305 | 101 | |
| RyoheiHagimoto | 0:0e0631af0305 | 102 | //! @addtogroup core_utils |
| RyoheiHagimoto | 0:0e0631af0305 | 103 | //! @{ |
| RyoheiHagimoto | 0:0e0631af0305 | 104 | |
| RyoheiHagimoto | 0:0e0631af0305 | 105 | //////////////////////////// memory management functions //////////////////////////// |
| RyoheiHagimoto | 0:0e0631af0305 | 106 | |
| RyoheiHagimoto | 0:0e0631af0305 | 107 | /** @brief Allocates an aligned memory buffer. |
| RyoheiHagimoto | 0:0e0631af0305 | 108 | |
| RyoheiHagimoto | 0:0e0631af0305 | 109 | The function allocates the buffer of the specified size and returns it. When the buffer size is 16 |
| RyoheiHagimoto | 0:0e0631af0305 | 110 | bytes or more, the returned buffer is aligned to 16 bytes. |
| RyoheiHagimoto | 0:0e0631af0305 | 111 | @param bufSize Allocated buffer size. |
| RyoheiHagimoto | 0:0e0631af0305 | 112 | */ |
| RyoheiHagimoto | 0:0e0631af0305 | 113 | CV_EXPORTS void* fastMalloc(size_t bufSize); |
| RyoheiHagimoto | 0:0e0631af0305 | 114 | |
| RyoheiHagimoto | 0:0e0631af0305 | 115 | /** @brief Deallocates a memory buffer. |
| RyoheiHagimoto | 0:0e0631af0305 | 116 | |
| RyoheiHagimoto | 0:0e0631af0305 | 117 | The function deallocates the buffer allocated with fastMalloc . If NULL pointer is passed, the |
| RyoheiHagimoto | 0:0e0631af0305 | 118 | function does nothing. C version of the function clears the pointer *pptr* to avoid problems with |
| RyoheiHagimoto | 0:0e0631af0305 | 119 | double memory deallocation. |
| RyoheiHagimoto | 0:0e0631af0305 | 120 | @param ptr Pointer to the allocated buffer. |
| RyoheiHagimoto | 0:0e0631af0305 | 121 | */ |
| RyoheiHagimoto | 0:0e0631af0305 | 122 | CV_EXPORTS void fastFree(void* ptr); |
| RyoheiHagimoto | 0:0e0631af0305 | 123 | |
| RyoheiHagimoto | 0:0e0631af0305 | 124 | /*! |
| RyoheiHagimoto | 0:0e0631af0305 | 125 | The STL-compilant memory Allocator based on cv::fastMalloc() and cv::fastFree() |
| RyoheiHagimoto | 0:0e0631af0305 | 126 | */ |
| RyoheiHagimoto | 0:0e0631af0305 | 127 | template<typename _Tp> class Allocator |
| RyoheiHagimoto | 0:0e0631af0305 | 128 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 129 | public: |
| RyoheiHagimoto | 0:0e0631af0305 | 130 | typedef _Tp value_type; |
| RyoheiHagimoto | 0:0e0631af0305 | 131 | typedef value_type* pointer; |
| RyoheiHagimoto | 0:0e0631af0305 | 132 | typedef const value_type* const_pointer; |
| RyoheiHagimoto | 0:0e0631af0305 | 133 | typedef value_type& reference; |
| RyoheiHagimoto | 0:0e0631af0305 | 134 | typedef const value_type& const_reference; |
| RyoheiHagimoto | 0:0e0631af0305 | 135 | typedef size_t size_type; |
| RyoheiHagimoto | 0:0e0631af0305 | 136 | typedef ptrdiff_t difference_type; |
| RyoheiHagimoto | 0:0e0631af0305 | 137 | template<typename U> class rebind { typedef Allocator<U> other; }; |
| RyoheiHagimoto | 0:0e0631af0305 | 138 | |
| RyoheiHagimoto | 0:0e0631af0305 | 139 | explicit Allocator() {} |
| RyoheiHagimoto | 0:0e0631af0305 | 140 | ~Allocator() {} |
| RyoheiHagimoto | 0:0e0631af0305 | 141 | explicit Allocator(Allocator const&) {} |
| RyoheiHagimoto | 0:0e0631af0305 | 142 | template<typename U> |
| RyoheiHagimoto | 0:0e0631af0305 | 143 | explicit Allocator(Allocator<U> const&) {} |
| RyoheiHagimoto | 0:0e0631af0305 | 144 | |
| RyoheiHagimoto | 0:0e0631af0305 | 145 | // address |
| RyoheiHagimoto | 0:0e0631af0305 | 146 | pointer address(reference r) { return &r; } |
| RyoheiHagimoto | 0:0e0631af0305 | 147 | const_pointer address(const_reference r) { return &r; } |
| RyoheiHagimoto | 0:0e0631af0305 | 148 | |
| RyoheiHagimoto | 0:0e0631af0305 | 149 | pointer allocate(size_type count, const void* =0) { return reinterpret_cast<pointer>(fastMalloc(count * sizeof (_Tp))); } |
| RyoheiHagimoto | 0:0e0631af0305 | 150 | void deallocate(pointer p, size_type) { fastFree(p); } |
| RyoheiHagimoto | 0:0e0631af0305 | 151 | |
| RyoheiHagimoto | 0:0e0631af0305 | 152 | void construct(pointer p, const _Tp& v) { new(static_cast<void*>(p)) _Tp(v); } |
| RyoheiHagimoto | 0:0e0631af0305 | 153 | void destroy(pointer p) { p->~_Tp(); } |
| RyoheiHagimoto | 0:0e0631af0305 | 154 | |
| RyoheiHagimoto | 0:0e0631af0305 | 155 | size_type max_size() const { return cv::max(static_cast<_Tp>(-1)/sizeof(_Tp), 1); } |
| RyoheiHagimoto | 0:0e0631af0305 | 156 | }; |
| RyoheiHagimoto | 0:0e0631af0305 | 157 | |
| RyoheiHagimoto | 0:0e0631af0305 | 158 | //! @} core_utils |
| RyoheiHagimoto | 0:0e0631af0305 | 159 | |
| RyoheiHagimoto | 0:0e0631af0305 | 160 | //! @cond IGNORED |
| RyoheiHagimoto | 0:0e0631af0305 | 161 | |
| RyoheiHagimoto | 0:0e0631af0305 | 162 | namespace detail |
| RyoheiHagimoto | 0:0e0631af0305 | 163 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 164 | |
| RyoheiHagimoto | 0:0e0631af0305 | 165 | // Metafunction to avoid taking a reference to void. |
| RyoheiHagimoto | 0:0e0631af0305 | 166 | template<typename T> |
| RyoheiHagimoto | 0:0e0631af0305 | 167 | struct RefOrVoid { typedef T& type; }; |
| RyoheiHagimoto | 0:0e0631af0305 | 168 | |
| RyoheiHagimoto | 0:0e0631af0305 | 169 | template<> |
| RyoheiHagimoto | 0:0e0631af0305 | 170 | struct RefOrVoid<void>{ typedef void type; }; |
| RyoheiHagimoto | 0:0e0631af0305 | 171 | |
| RyoheiHagimoto | 0:0e0631af0305 | 172 | template<> |
| RyoheiHagimoto | 0:0e0631af0305 | 173 | struct RefOrVoid<const void>{ typedef const void type; }; |
| RyoheiHagimoto | 0:0e0631af0305 | 174 | |
| RyoheiHagimoto | 0:0e0631af0305 | 175 | template<> |
| RyoheiHagimoto | 0:0e0631af0305 | 176 | struct RefOrVoid<volatile void>{ typedef volatile void type; }; |
| RyoheiHagimoto | 0:0e0631af0305 | 177 | |
| RyoheiHagimoto | 0:0e0631af0305 | 178 | template<> |
| RyoheiHagimoto | 0:0e0631af0305 | 179 | struct RefOrVoid<const volatile void>{ typedef const volatile void type; }; |
| RyoheiHagimoto | 0:0e0631af0305 | 180 | |
| RyoheiHagimoto | 0:0e0631af0305 | 181 | // This class would be private to Ptr, if it didn't have to be a non-template. |
| RyoheiHagimoto | 0:0e0631af0305 | 182 | struct PtrOwner; |
| RyoheiHagimoto | 0:0e0631af0305 | 183 | |
| RyoheiHagimoto | 0:0e0631af0305 | 184 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 185 | |
| RyoheiHagimoto | 0:0e0631af0305 | 186 | template<typename Y> |
| RyoheiHagimoto | 0:0e0631af0305 | 187 | struct DefaultDeleter |
| RyoheiHagimoto | 0:0e0631af0305 | 188 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 189 | void operator () (Y* p) const; |
| RyoheiHagimoto | 0:0e0631af0305 | 190 | }; |
| RyoheiHagimoto | 0:0e0631af0305 | 191 | |
| RyoheiHagimoto | 0:0e0631af0305 | 192 | //! @endcond |
| RyoheiHagimoto | 0:0e0631af0305 | 193 | |
| RyoheiHagimoto | 0:0e0631af0305 | 194 | //! @addtogroup core_basic |
| RyoheiHagimoto | 0:0e0631af0305 | 195 | //! @{ |
| RyoheiHagimoto | 0:0e0631af0305 | 196 | |
| RyoheiHagimoto | 0:0e0631af0305 | 197 | /** @brief Template class for smart pointers with shared ownership |
| RyoheiHagimoto | 0:0e0631af0305 | 198 | |
| RyoheiHagimoto | 0:0e0631af0305 | 199 | A Ptr\<T\> pretends to be a pointer to an object of type T. Unlike an ordinary pointer, however, the |
| RyoheiHagimoto | 0:0e0631af0305 | 200 | object will be automatically cleaned up once all Ptr instances pointing to it are destroyed. |
| RyoheiHagimoto | 0:0e0631af0305 | 201 | |
| RyoheiHagimoto | 0:0e0631af0305 | 202 | Ptr is similar to boost::shared_ptr that is part of the Boost library |
| RyoheiHagimoto | 0:0e0631af0305 | 203 | (<http://www.boost.org/doc/libs/release/libs/smart_ptr/shared_ptr.htm>) and std::shared_ptr from |
| RyoheiHagimoto | 0:0e0631af0305 | 204 | the [C++11](http://en.wikipedia.org/wiki/C++11) standard. |
| RyoheiHagimoto | 0:0e0631af0305 | 205 | |
| RyoheiHagimoto | 0:0e0631af0305 | 206 | This class provides the following advantages: |
| RyoheiHagimoto | 0:0e0631af0305 | 207 | - Default constructor, copy constructor, and assignment operator for an arbitrary C++ class or C |
| RyoheiHagimoto | 0:0e0631af0305 | 208 | structure. For some objects, like files, windows, mutexes, sockets, and others, a copy |
| RyoheiHagimoto | 0:0e0631af0305 | 209 | constructor or an assignment operator are difficult to define. For some other objects, like |
| RyoheiHagimoto | 0:0e0631af0305 | 210 | complex classifiers in OpenCV, copy constructors are absent and not easy to implement. Finally, |
| RyoheiHagimoto | 0:0e0631af0305 | 211 | some of complex OpenCV and your own data structures may be written in C. However, copy |
| RyoheiHagimoto | 0:0e0631af0305 | 212 | constructors and default constructors can simplify programming a lot. Besides, they are often |
| RyoheiHagimoto | 0:0e0631af0305 | 213 | required (for example, by STL containers). By using a Ptr to such an object instead of the |
| RyoheiHagimoto | 0:0e0631af0305 | 214 | object itself, you automatically get all of the necessary constructors and the assignment |
| RyoheiHagimoto | 0:0e0631af0305 | 215 | operator. |
| RyoheiHagimoto | 0:0e0631af0305 | 216 | - *O(1)* complexity of the above-mentioned operations. While some structures, like std::vector, |
| RyoheiHagimoto | 0:0e0631af0305 | 217 | provide a copy constructor and an assignment operator, the operations may take a considerable |
| RyoheiHagimoto | 0:0e0631af0305 | 218 | amount of time if the data structures are large. But if the structures are put into a Ptr, the |
| RyoheiHagimoto | 0:0e0631af0305 | 219 | overhead is small and independent of the data size. |
| RyoheiHagimoto | 0:0e0631af0305 | 220 | - Automatic and customizable cleanup, even for C structures. See the example below with FILE\*. |
| RyoheiHagimoto | 0:0e0631af0305 | 221 | - Heterogeneous collections of objects. The standard STL and most other C++ and OpenCV containers |
| RyoheiHagimoto | 0:0e0631af0305 | 222 | can store only objects of the same type and the same size. The classical solution to store |
| RyoheiHagimoto | 0:0e0631af0305 | 223 | objects of different types in the same container is to store pointers to the base class (Base\*) |
| RyoheiHagimoto | 0:0e0631af0305 | 224 | instead but then you lose the automatic memory management. Again, by using Ptr\<Base\> instead |
| RyoheiHagimoto | 0:0e0631af0305 | 225 | of raw pointers, you can solve the problem. |
| RyoheiHagimoto | 0:0e0631af0305 | 226 | |
| RyoheiHagimoto | 0:0e0631af0305 | 227 | A Ptr is said to *own* a pointer - that is, for each Ptr there is a pointer that will be deleted |
| RyoheiHagimoto | 0:0e0631af0305 | 228 | once all Ptr instances that own it are destroyed. The owned pointer may be null, in which case |
| RyoheiHagimoto | 0:0e0631af0305 | 229 | nothing is deleted. Each Ptr also *stores* a pointer. The stored pointer is the pointer the Ptr |
| RyoheiHagimoto | 0:0e0631af0305 | 230 | pretends to be; that is, the one you get when you use Ptr::get or the conversion to T\*. It's |
| RyoheiHagimoto | 0:0e0631af0305 | 231 | usually the same as the owned pointer, but if you use casts or the general shared-ownership |
| RyoheiHagimoto | 0:0e0631af0305 | 232 | constructor, the two may diverge: the Ptr will still own the original pointer, but will itself point |
| RyoheiHagimoto | 0:0e0631af0305 | 233 | to something else. |
| RyoheiHagimoto | 0:0e0631af0305 | 234 | |
| RyoheiHagimoto | 0:0e0631af0305 | 235 | The owned pointer is treated as a black box. The only thing Ptr needs to know about it is how to |
| RyoheiHagimoto | 0:0e0631af0305 | 236 | delete it. This knowledge is encapsulated in the *deleter* - an auxiliary object that is associated |
| RyoheiHagimoto | 0:0e0631af0305 | 237 | with the owned pointer and shared between all Ptr instances that own it. The default deleter is an |
| RyoheiHagimoto | 0:0e0631af0305 | 238 | instance of DefaultDeleter, which uses the standard C++ delete operator; as such it will work with |
| RyoheiHagimoto | 0:0e0631af0305 | 239 | any pointer allocated with the standard new operator. |
| RyoheiHagimoto | 0:0e0631af0305 | 240 | |
| RyoheiHagimoto | 0:0e0631af0305 | 241 | However, if the pointer must be deleted in a different way, you must specify a custom deleter upon |
| RyoheiHagimoto | 0:0e0631af0305 | 242 | Ptr construction. A deleter is simply a callable object that accepts the pointer as its sole |
| RyoheiHagimoto | 0:0e0631af0305 | 243 | argument. For example, if you want to wrap FILE, you may do so as follows: |
| RyoheiHagimoto | 0:0e0631af0305 | 244 | @code |
| RyoheiHagimoto | 0:0e0631af0305 | 245 | Ptr<FILE> f(fopen("myfile.txt", "w"), fclose); |
| RyoheiHagimoto | 0:0e0631af0305 | 246 | if(!f) throw ...; |
| RyoheiHagimoto | 0:0e0631af0305 | 247 | fprintf(f, ....); |
| RyoheiHagimoto | 0:0e0631af0305 | 248 | ... |
| RyoheiHagimoto | 0:0e0631af0305 | 249 | // the file will be closed automatically by f's destructor. |
| RyoheiHagimoto | 0:0e0631af0305 | 250 | @endcode |
| RyoheiHagimoto | 0:0e0631af0305 | 251 | Alternatively, if you want all pointers of a particular type to be deleted the same way, you can |
| RyoheiHagimoto | 0:0e0631af0305 | 252 | specialize DefaultDeleter<T>::operator() for that type, like this: |
| RyoheiHagimoto | 0:0e0631af0305 | 253 | @code |
| RyoheiHagimoto | 0:0e0631af0305 | 254 | namespace cv { |
| RyoheiHagimoto | 0:0e0631af0305 | 255 | template<> void DefaultDeleter<FILE>::operator ()(FILE * obj) const |
| RyoheiHagimoto | 0:0e0631af0305 | 256 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 257 | fclose(obj); |
| RyoheiHagimoto | 0:0e0631af0305 | 258 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 259 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 260 | @endcode |
| RyoheiHagimoto | 0:0e0631af0305 | 261 | For convenience, the following types from the OpenCV C API already have such a specialization that |
| RyoheiHagimoto | 0:0e0631af0305 | 262 | calls the appropriate release function: |
| RyoheiHagimoto | 0:0e0631af0305 | 263 | - CvCapture |
| RyoheiHagimoto | 0:0e0631af0305 | 264 | - CvFileStorage |
| RyoheiHagimoto | 0:0e0631af0305 | 265 | - CvHaarClassifierCascade |
| RyoheiHagimoto | 0:0e0631af0305 | 266 | - CvMat |
| RyoheiHagimoto | 0:0e0631af0305 | 267 | - CvMatND |
| RyoheiHagimoto | 0:0e0631af0305 | 268 | - CvMemStorage |
| RyoheiHagimoto | 0:0e0631af0305 | 269 | - CvSparseMat |
| RyoheiHagimoto | 0:0e0631af0305 | 270 | - CvVideoWriter |
| RyoheiHagimoto | 0:0e0631af0305 | 271 | - IplImage |
| RyoheiHagimoto | 0:0e0631af0305 | 272 | @note The shared ownership mechanism is implemented with reference counting. As such, cyclic |
| RyoheiHagimoto | 0:0e0631af0305 | 273 | ownership (e.g. when object a contains a Ptr to object b, which contains a Ptr to object a) will |
| RyoheiHagimoto | 0:0e0631af0305 | 274 | lead to all involved objects never being cleaned up. Avoid such situations. |
| RyoheiHagimoto | 0:0e0631af0305 | 275 | @note It is safe to concurrently read (but not write) a Ptr instance from multiple threads and |
| RyoheiHagimoto | 0:0e0631af0305 | 276 | therefore it is normally safe to use it in multi-threaded applications. The same is true for Mat and |
| RyoheiHagimoto | 0:0e0631af0305 | 277 | other C++ OpenCV classes that use internal reference counts. |
| RyoheiHagimoto | 0:0e0631af0305 | 278 | */ |
| RyoheiHagimoto | 0:0e0631af0305 | 279 | template<typename T> |
| RyoheiHagimoto | 0:0e0631af0305 | 280 | struct Ptr |
| RyoheiHagimoto | 0:0e0631af0305 | 281 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 282 | /** Generic programming support. */ |
| RyoheiHagimoto | 0:0e0631af0305 | 283 | typedef T element_type; |
| RyoheiHagimoto | 0:0e0631af0305 | 284 | |
| RyoheiHagimoto | 0:0e0631af0305 | 285 | /** The default constructor creates a null Ptr - one that owns and stores a null pointer. |
| RyoheiHagimoto | 0:0e0631af0305 | 286 | */ |
| RyoheiHagimoto | 0:0e0631af0305 | 287 | Ptr(); |
| RyoheiHagimoto | 0:0e0631af0305 | 288 | |
| RyoheiHagimoto | 0:0e0631af0305 | 289 | /** |
| RyoheiHagimoto | 0:0e0631af0305 | 290 | If p is null, these are equivalent to the default constructor. |
| RyoheiHagimoto | 0:0e0631af0305 | 291 | Otherwise, these constructors assume ownership of p - that is, the created Ptr owns and stores p |
| RyoheiHagimoto | 0:0e0631af0305 | 292 | and assumes it is the sole owner of it. Don't use them if p is already owned by another Ptr, or |
| RyoheiHagimoto | 0:0e0631af0305 | 293 | else p will get deleted twice. |
| RyoheiHagimoto | 0:0e0631af0305 | 294 | With the first constructor, DefaultDeleter\<Y\>() becomes the associated deleter (so p will |
| RyoheiHagimoto | 0:0e0631af0305 | 295 | eventually be deleted with the standard delete operator). Y must be a complete type at the point |
| RyoheiHagimoto | 0:0e0631af0305 | 296 | of invocation. |
| RyoheiHagimoto | 0:0e0631af0305 | 297 | With the second constructor, d becomes the associated deleter. |
| RyoheiHagimoto | 0:0e0631af0305 | 298 | Y\* must be convertible to T\*. |
| RyoheiHagimoto | 0:0e0631af0305 | 299 | @param p Pointer to own. |
| RyoheiHagimoto | 0:0e0631af0305 | 300 | @note It is often easier to use makePtr instead. |
| RyoheiHagimoto | 0:0e0631af0305 | 301 | */ |
| RyoheiHagimoto | 0:0e0631af0305 | 302 | template<typename Y> |
| RyoheiHagimoto | 0:0e0631af0305 | 303 | #ifdef DISABLE_OPENCV_24_COMPATIBILITY |
| RyoheiHagimoto | 0:0e0631af0305 | 304 | explicit |
| RyoheiHagimoto | 0:0e0631af0305 | 305 | #endif |
| RyoheiHagimoto | 0:0e0631af0305 | 306 | Ptr(Y* p); |
| RyoheiHagimoto | 0:0e0631af0305 | 307 | |
| RyoheiHagimoto | 0:0e0631af0305 | 308 | /** @overload |
| RyoheiHagimoto | 0:0e0631af0305 | 309 | @param d Deleter to use for the owned pointer. |
| RyoheiHagimoto | 0:0e0631af0305 | 310 | @param p Pointer to own. |
| RyoheiHagimoto | 0:0e0631af0305 | 311 | */ |
| RyoheiHagimoto | 0:0e0631af0305 | 312 | template<typename Y, typename D> |
| RyoheiHagimoto | 0:0e0631af0305 | 313 | Ptr(Y* p, D d); |
| RyoheiHagimoto | 0:0e0631af0305 | 314 | |
| RyoheiHagimoto | 0:0e0631af0305 | 315 | /** |
| RyoheiHagimoto | 0:0e0631af0305 | 316 | These constructors create a Ptr that shares ownership with another Ptr - that is, own the same |
| RyoheiHagimoto | 0:0e0631af0305 | 317 | pointer as o. |
| RyoheiHagimoto | 0:0e0631af0305 | 318 | With the first two, the same pointer is stored, as well; for the second, Y\* must be convertible |
| RyoheiHagimoto | 0:0e0631af0305 | 319 | to T\*. |
| RyoheiHagimoto | 0:0e0631af0305 | 320 | With the third, p is stored, and Y may be any type. This constructor allows to have completely |
| RyoheiHagimoto | 0:0e0631af0305 | 321 | unrelated owned and stored pointers, and should be used with care to avoid confusion. A relatively |
| RyoheiHagimoto | 0:0e0631af0305 | 322 | benign use is to create a non-owning Ptr, like this: |
| RyoheiHagimoto | 0:0e0631af0305 | 323 | @code |
| RyoheiHagimoto | 0:0e0631af0305 | 324 | ptr = Ptr<T>(Ptr<T>(), dont_delete_me); // owns nothing; will not delete the pointer. |
| RyoheiHagimoto | 0:0e0631af0305 | 325 | @endcode |
| RyoheiHagimoto | 0:0e0631af0305 | 326 | @param o Ptr to share ownership with. |
| RyoheiHagimoto | 0:0e0631af0305 | 327 | */ |
| RyoheiHagimoto | 0:0e0631af0305 | 328 | Ptr(const Ptr& o); |
| RyoheiHagimoto | 0:0e0631af0305 | 329 | |
| RyoheiHagimoto | 0:0e0631af0305 | 330 | /** @overload |
| RyoheiHagimoto | 0:0e0631af0305 | 331 | @param o Ptr to share ownership with. |
| RyoheiHagimoto | 0:0e0631af0305 | 332 | */ |
| RyoheiHagimoto | 0:0e0631af0305 | 333 | template<typename Y> |
| RyoheiHagimoto | 0:0e0631af0305 | 334 | Ptr(const Ptr<Y>& o); |
| RyoheiHagimoto | 0:0e0631af0305 | 335 | |
| RyoheiHagimoto | 0:0e0631af0305 | 336 | /** @overload |
| RyoheiHagimoto | 0:0e0631af0305 | 337 | @param o Ptr to share ownership with. |
| RyoheiHagimoto | 0:0e0631af0305 | 338 | @param p Pointer to store. |
| RyoheiHagimoto | 0:0e0631af0305 | 339 | */ |
| RyoheiHagimoto | 0:0e0631af0305 | 340 | template<typename Y> |
| RyoheiHagimoto | 0:0e0631af0305 | 341 | Ptr(const Ptr<Y>& o, T* p); |
| RyoheiHagimoto | 0:0e0631af0305 | 342 | |
| RyoheiHagimoto | 0:0e0631af0305 | 343 | /** The destructor is equivalent to calling Ptr::release. */ |
| RyoheiHagimoto | 0:0e0631af0305 | 344 | ~Ptr(); |
| RyoheiHagimoto | 0:0e0631af0305 | 345 | |
| RyoheiHagimoto | 0:0e0631af0305 | 346 | /** |
| RyoheiHagimoto | 0:0e0631af0305 | 347 | Assignment replaces the current Ptr instance with one that owns and stores same pointers as o and |
| RyoheiHagimoto | 0:0e0631af0305 | 348 | then destroys the old instance. |
| RyoheiHagimoto | 0:0e0631af0305 | 349 | @param o Ptr to share ownership with. |
| RyoheiHagimoto | 0:0e0631af0305 | 350 | */ |
| RyoheiHagimoto | 0:0e0631af0305 | 351 | Ptr& operator = (const Ptr& o); |
| RyoheiHagimoto | 0:0e0631af0305 | 352 | |
| RyoheiHagimoto | 0:0e0631af0305 | 353 | /** @overload */ |
| RyoheiHagimoto | 0:0e0631af0305 | 354 | template<typename Y> |
| RyoheiHagimoto | 0:0e0631af0305 | 355 | Ptr& operator = (const Ptr<Y>& o); |
| RyoheiHagimoto | 0:0e0631af0305 | 356 | |
| RyoheiHagimoto | 0:0e0631af0305 | 357 | /** If no other Ptr instance owns the owned pointer, deletes it with the associated deleter. Then sets |
| RyoheiHagimoto | 0:0e0631af0305 | 358 | both the owned and the stored pointers to NULL. |
| RyoheiHagimoto | 0:0e0631af0305 | 359 | */ |
| RyoheiHagimoto | 0:0e0631af0305 | 360 | void release(); |
| RyoheiHagimoto | 0:0e0631af0305 | 361 | |
| RyoheiHagimoto | 0:0e0631af0305 | 362 | /** |
| RyoheiHagimoto | 0:0e0631af0305 | 363 | `ptr.reset(...)` is equivalent to `ptr = Ptr<T>(...)`. |
| RyoheiHagimoto | 0:0e0631af0305 | 364 | @param p Pointer to own. |
| RyoheiHagimoto | 0:0e0631af0305 | 365 | */ |
| RyoheiHagimoto | 0:0e0631af0305 | 366 | template<typename Y> |
| RyoheiHagimoto | 0:0e0631af0305 | 367 | void reset(Y* p); |
| RyoheiHagimoto | 0:0e0631af0305 | 368 | |
| RyoheiHagimoto | 0:0e0631af0305 | 369 | /** @overload |
| RyoheiHagimoto | 0:0e0631af0305 | 370 | @param d Deleter to use for the owned pointer. |
| RyoheiHagimoto | 0:0e0631af0305 | 371 | @param p Pointer to own. |
| RyoheiHagimoto | 0:0e0631af0305 | 372 | */ |
| RyoheiHagimoto | 0:0e0631af0305 | 373 | template<typename Y, typename D> |
| RyoheiHagimoto | 0:0e0631af0305 | 374 | void reset(Y* p, D d); |
| RyoheiHagimoto | 0:0e0631af0305 | 375 | |
| RyoheiHagimoto | 0:0e0631af0305 | 376 | /** |
| RyoheiHagimoto | 0:0e0631af0305 | 377 | Swaps the owned and stored pointers (and deleters, if any) of this and o. |
| RyoheiHagimoto | 0:0e0631af0305 | 378 | @param o Ptr to swap with. |
| RyoheiHagimoto | 0:0e0631af0305 | 379 | */ |
| RyoheiHagimoto | 0:0e0631af0305 | 380 | void swap(Ptr& o); |
| RyoheiHagimoto | 0:0e0631af0305 | 381 | |
| RyoheiHagimoto | 0:0e0631af0305 | 382 | /** Returns the stored pointer. */ |
| RyoheiHagimoto | 0:0e0631af0305 | 383 | T* get() const; |
| RyoheiHagimoto | 0:0e0631af0305 | 384 | |
| RyoheiHagimoto | 0:0e0631af0305 | 385 | /** Ordinary pointer emulation. */ |
| RyoheiHagimoto | 0:0e0631af0305 | 386 | typename detail::RefOrVoid<T>::type operator * () const; |
| RyoheiHagimoto | 0:0e0631af0305 | 387 | |
| RyoheiHagimoto | 0:0e0631af0305 | 388 | /** Ordinary pointer emulation. */ |
| RyoheiHagimoto | 0:0e0631af0305 | 389 | T* operator -> () const; |
| RyoheiHagimoto | 0:0e0631af0305 | 390 | |
| RyoheiHagimoto | 0:0e0631af0305 | 391 | /** Equivalent to get(). */ |
| RyoheiHagimoto | 0:0e0631af0305 | 392 | operator T* () const; |
| RyoheiHagimoto | 0:0e0631af0305 | 393 | |
| RyoheiHagimoto | 0:0e0631af0305 | 394 | /** ptr.empty() is equivalent to `!ptr.get()`. */ |
| RyoheiHagimoto | 0:0e0631af0305 | 395 | bool empty() const; |
| RyoheiHagimoto | 0:0e0631af0305 | 396 | |
| RyoheiHagimoto | 0:0e0631af0305 | 397 | /** Returns a Ptr that owns the same pointer as this, and stores the same |
| RyoheiHagimoto | 0:0e0631af0305 | 398 | pointer as this, except converted via static_cast to Y*. |
| RyoheiHagimoto | 0:0e0631af0305 | 399 | */ |
| RyoheiHagimoto | 0:0e0631af0305 | 400 | template<typename Y> |
| RyoheiHagimoto | 0:0e0631af0305 | 401 | Ptr<Y> staticCast() const; |
| RyoheiHagimoto | 0:0e0631af0305 | 402 | |
| RyoheiHagimoto | 0:0e0631af0305 | 403 | /** Ditto for const_cast. */ |
| RyoheiHagimoto | 0:0e0631af0305 | 404 | template<typename Y> |
| RyoheiHagimoto | 0:0e0631af0305 | 405 | Ptr<Y> constCast() const; |
| RyoheiHagimoto | 0:0e0631af0305 | 406 | |
| RyoheiHagimoto | 0:0e0631af0305 | 407 | /** Ditto for dynamic_cast. */ |
| RyoheiHagimoto | 0:0e0631af0305 | 408 | template<typename Y> |
| RyoheiHagimoto | 0:0e0631af0305 | 409 | Ptr<Y> dynamicCast() const; |
| RyoheiHagimoto | 0:0e0631af0305 | 410 | |
| RyoheiHagimoto | 0:0e0631af0305 | 411 | #ifdef CV_CXX_MOVE_SEMANTICS |
| RyoheiHagimoto | 0:0e0631af0305 | 412 | Ptr(Ptr&& o); |
| RyoheiHagimoto | 0:0e0631af0305 | 413 | Ptr& operator = (Ptr&& o); |
| RyoheiHagimoto | 0:0e0631af0305 | 414 | #endif |
| RyoheiHagimoto | 0:0e0631af0305 | 415 | |
| RyoheiHagimoto | 0:0e0631af0305 | 416 | private: |
| RyoheiHagimoto | 0:0e0631af0305 | 417 | detail::PtrOwner* owner; |
| RyoheiHagimoto | 0:0e0631af0305 | 418 | T* stored; |
| RyoheiHagimoto | 0:0e0631af0305 | 419 | |
| RyoheiHagimoto | 0:0e0631af0305 | 420 | template<typename Y> |
| RyoheiHagimoto | 0:0e0631af0305 | 421 | friend struct Ptr; // have to do this for the cross-type copy constructor |
| RyoheiHagimoto | 0:0e0631af0305 | 422 | }; |
| RyoheiHagimoto | 0:0e0631af0305 | 423 | |
| RyoheiHagimoto | 0:0e0631af0305 | 424 | /** Equivalent to ptr1.swap(ptr2). Provided to help write generic algorithms. */ |
| RyoheiHagimoto | 0:0e0631af0305 | 425 | template<typename T> |
| RyoheiHagimoto | 0:0e0631af0305 | 426 | void swap(Ptr<T>& ptr1, Ptr<T>& ptr2); |
| RyoheiHagimoto | 0:0e0631af0305 | 427 | |
| RyoheiHagimoto | 0:0e0631af0305 | 428 | /** Return whether ptr1.get() and ptr2.get() are equal and not equal, respectively. */ |
| RyoheiHagimoto | 0:0e0631af0305 | 429 | template<typename T> |
| RyoheiHagimoto | 0:0e0631af0305 | 430 | bool operator == (const Ptr<T>& ptr1, const Ptr<T>& ptr2); |
| RyoheiHagimoto | 0:0e0631af0305 | 431 | template<typename T> |
| RyoheiHagimoto | 0:0e0631af0305 | 432 | bool operator != (const Ptr<T>& ptr1, const Ptr<T>& ptr2); |
| RyoheiHagimoto | 0:0e0631af0305 | 433 | |
| RyoheiHagimoto | 0:0e0631af0305 | 434 | /** `makePtr<T>(...)` is equivalent to `Ptr<T>(new T(...))`. It is shorter than the latter, and it's |
| RyoheiHagimoto | 0:0e0631af0305 | 435 | marginally safer than using a constructor or Ptr::reset, since it ensures that the owned pointer |
| RyoheiHagimoto | 0:0e0631af0305 | 436 | is new and thus not owned by any other Ptr instance. |
| RyoheiHagimoto | 0:0e0631af0305 | 437 | Unfortunately, perfect forwarding is impossible to implement in C++03, and so makePtr is limited |
| RyoheiHagimoto | 0:0e0631af0305 | 438 | to constructors of T that have up to 10 arguments, none of which are non-const references. |
| RyoheiHagimoto | 0:0e0631af0305 | 439 | */ |
| RyoheiHagimoto | 0:0e0631af0305 | 440 | template<typename T> |
| RyoheiHagimoto | 0:0e0631af0305 | 441 | Ptr<T> makePtr(); |
| RyoheiHagimoto | 0:0e0631af0305 | 442 | /** @overload */ |
| RyoheiHagimoto | 0:0e0631af0305 | 443 | template<typename T, typename A1> |
| RyoheiHagimoto | 0:0e0631af0305 | 444 | Ptr<T> makePtr(const A1& a1); |
| RyoheiHagimoto | 0:0e0631af0305 | 445 | /** @overload */ |
| RyoheiHagimoto | 0:0e0631af0305 | 446 | template<typename T, typename A1, typename A2> |
| RyoheiHagimoto | 0:0e0631af0305 | 447 | Ptr<T> makePtr(const A1& a1, const A2& a2); |
| RyoheiHagimoto | 0:0e0631af0305 | 448 | /** @overload */ |
| RyoheiHagimoto | 0:0e0631af0305 | 449 | template<typename T, typename A1, typename A2, typename A3> |
| RyoheiHagimoto | 0:0e0631af0305 | 450 | Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3); |
| RyoheiHagimoto | 0:0e0631af0305 | 451 | /** @overload */ |
| RyoheiHagimoto | 0:0e0631af0305 | 452 | template<typename T, typename A1, typename A2, typename A3, typename A4> |
| RyoheiHagimoto | 0:0e0631af0305 | 453 | Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4); |
| RyoheiHagimoto | 0:0e0631af0305 | 454 | /** @overload */ |
| RyoheiHagimoto | 0:0e0631af0305 | 455 | template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5> |
| RyoheiHagimoto | 0:0e0631af0305 | 456 | Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5); |
| RyoheiHagimoto | 0:0e0631af0305 | 457 | /** @overload */ |
| RyoheiHagimoto | 0:0e0631af0305 | 458 | template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6> |
| RyoheiHagimoto | 0:0e0631af0305 | 459 | Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6); |
| RyoheiHagimoto | 0:0e0631af0305 | 460 | /** @overload */ |
| RyoheiHagimoto | 0:0e0631af0305 | 461 | template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7> |
| RyoheiHagimoto | 0:0e0631af0305 | 462 | Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7); |
| RyoheiHagimoto | 0:0e0631af0305 | 463 | /** @overload */ |
| RyoheiHagimoto | 0:0e0631af0305 | 464 | template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8> |
| RyoheiHagimoto | 0:0e0631af0305 | 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, const A8& a8); |
| RyoheiHagimoto | 0:0e0631af0305 | 466 | /** @overload */ |
| RyoheiHagimoto | 0:0e0631af0305 | 467 | template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9> |
| RyoheiHagimoto | 0:0e0631af0305 | 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, const A9& a9); |
| RyoheiHagimoto | 0:0e0631af0305 | 469 | /** @overload */ |
| RyoheiHagimoto | 0:0e0631af0305 | 470 | template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9, typename A10> |
| RyoheiHagimoto | 0:0e0631af0305 | 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, const A10& a10); |
| RyoheiHagimoto | 0:0e0631af0305 | 472 | |
| RyoheiHagimoto | 0:0e0631af0305 | 473 | //////////////////////////////// string class //////////////////////////////// |
| RyoheiHagimoto | 0:0e0631af0305 | 474 | |
| RyoheiHagimoto | 0:0e0631af0305 | 475 | class CV_EXPORTS FileNode; //for string constructor from FileNode |
| RyoheiHagimoto | 0:0e0631af0305 | 476 | |
| RyoheiHagimoto | 0:0e0631af0305 | 477 | class CV_EXPORTS String |
| RyoheiHagimoto | 0:0e0631af0305 | 478 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 479 | public: |
| RyoheiHagimoto | 0:0e0631af0305 | 480 | typedef char value_type; |
| RyoheiHagimoto | 0:0e0631af0305 | 481 | typedef char& reference; |
| RyoheiHagimoto | 0:0e0631af0305 | 482 | typedef const char& const_reference; |
| RyoheiHagimoto | 0:0e0631af0305 | 483 | typedef char* pointer; |
| RyoheiHagimoto | 0:0e0631af0305 | 484 | typedef const char* const_pointer; |
| RyoheiHagimoto | 0:0e0631af0305 | 485 | typedef ptrdiff_t difference_type; |
| RyoheiHagimoto | 0:0e0631af0305 | 486 | typedef size_t size_type; |
| RyoheiHagimoto | 0:0e0631af0305 | 487 | typedef char* iterator; |
| RyoheiHagimoto | 0:0e0631af0305 | 488 | typedef const char* const_iterator; |
| RyoheiHagimoto | 0:0e0631af0305 | 489 | |
| RyoheiHagimoto | 0:0e0631af0305 | 490 | static const size_t npos = size_t(-1); |
| RyoheiHagimoto | 0:0e0631af0305 | 491 | |
| RyoheiHagimoto | 0:0e0631af0305 | 492 | explicit String(); |
| RyoheiHagimoto | 0:0e0631af0305 | 493 | String(const String& str); |
| RyoheiHagimoto | 0:0e0631af0305 | 494 | String(const String& str, size_t pos, size_t len = npos); |
| RyoheiHagimoto | 0:0e0631af0305 | 495 | String(const char* s); |
| RyoheiHagimoto | 0:0e0631af0305 | 496 | String(const char* s, size_t n); |
| RyoheiHagimoto | 0:0e0631af0305 | 497 | String(size_t n, char c); |
| RyoheiHagimoto | 0:0e0631af0305 | 498 | String(const char* first, const char* last); |
| RyoheiHagimoto | 0:0e0631af0305 | 499 | template<typename Iterator> String(Iterator first, Iterator last); |
| RyoheiHagimoto | 0:0e0631af0305 | 500 | explicit String(const FileNode& fn); |
| RyoheiHagimoto | 0:0e0631af0305 | 501 | ~String(); |
| RyoheiHagimoto | 0:0e0631af0305 | 502 | |
| RyoheiHagimoto | 0:0e0631af0305 | 503 | String& operator=(const String& str); |
| RyoheiHagimoto | 0:0e0631af0305 | 504 | String& operator=(const char* s); |
| RyoheiHagimoto | 0:0e0631af0305 | 505 | String& operator=(char c); |
| RyoheiHagimoto | 0:0e0631af0305 | 506 | |
| RyoheiHagimoto | 0:0e0631af0305 | 507 | String& operator+=(const String& str); |
| RyoheiHagimoto | 0:0e0631af0305 | 508 | String& operator+=(const char* s); |
| RyoheiHagimoto | 0:0e0631af0305 | 509 | String& operator+=(char c); |
| RyoheiHagimoto | 0:0e0631af0305 | 510 | |
| RyoheiHagimoto | 0:0e0631af0305 | 511 | size_t size() const; |
| RyoheiHagimoto | 0:0e0631af0305 | 512 | size_t length() const; |
| RyoheiHagimoto | 0:0e0631af0305 | 513 | |
| RyoheiHagimoto | 0:0e0631af0305 | 514 | char operator[](size_t idx) const; |
| RyoheiHagimoto | 0:0e0631af0305 | 515 | char operator[](int idx) const; |
| RyoheiHagimoto | 0:0e0631af0305 | 516 | |
| RyoheiHagimoto | 0:0e0631af0305 | 517 | const char* begin() const; |
| RyoheiHagimoto | 0:0e0631af0305 | 518 | const char* end() const; |
| RyoheiHagimoto | 0:0e0631af0305 | 519 | |
| RyoheiHagimoto | 0:0e0631af0305 | 520 | const char* c_str() const; |
| RyoheiHagimoto | 0:0e0631af0305 | 521 | |
| RyoheiHagimoto | 0:0e0631af0305 | 522 | bool empty() const; |
| RyoheiHagimoto | 0:0e0631af0305 | 523 | void clear(); |
| RyoheiHagimoto | 0:0e0631af0305 | 524 | |
| RyoheiHagimoto | 0:0e0631af0305 | 525 | int compare(const char* s) const; |
| RyoheiHagimoto | 0:0e0631af0305 | 526 | int compare(const String& str) const; |
| RyoheiHagimoto | 0:0e0631af0305 | 527 | |
| RyoheiHagimoto | 0:0e0631af0305 | 528 | void swap(String& str); |
| RyoheiHagimoto | 0:0e0631af0305 | 529 | String substr(size_t pos = 0, size_t len = npos) const; |
| RyoheiHagimoto | 0:0e0631af0305 | 530 | |
| RyoheiHagimoto | 0:0e0631af0305 | 531 | size_t find(const char* s, size_t pos, size_t n) const; |
| RyoheiHagimoto | 0:0e0631af0305 | 532 | size_t find(char c, size_t pos = 0) const; |
| RyoheiHagimoto | 0:0e0631af0305 | 533 | size_t find(const String& str, size_t pos = 0) const; |
| RyoheiHagimoto | 0:0e0631af0305 | 534 | size_t find(const char* s, size_t pos = 0) const; |
| RyoheiHagimoto | 0:0e0631af0305 | 535 | |
| RyoheiHagimoto | 0:0e0631af0305 | 536 | size_t rfind(const char* s, size_t pos, size_t n) const; |
| RyoheiHagimoto | 0:0e0631af0305 | 537 | size_t rfind(char c, size_t pos = npos) const; |
| RyoheiHagimoto | 0:0e0631af0305 | 538 | size_t rfind(const String& str, size_t pos = npos) const; |
| RyoheiHagimoto | 0:0e0631af0305 | 539 | size_t rfind(const char* s, size_t pos = npos) const; |
| RyoheiHagimoto | 0:0e0631af0305 | 540 | |
| RyoheiHagimoto | 0:0e0631af0305 | 541 | size_t find_first_of(const char* s, size_t pos, size_t n) const; |
| RyoheiHagimoto | 0:0e0631af0305 | 542 | size_t find_first_of(char c, size_t pos = 0) const; |
| RyoheiHagimoto | 0:0e0631af0305 | 543 | size_t find_first_of(const String& str, size_t pos = 0) const; |
| RyoheiHagimoto | 0:0e0631af0305 | 544 | size_t find_first_of(const char* s, size_t pos = 0) const; |
| RyoheiHagimoto | 0:0e0631af0305 | 545 | |
| RyoheiHagimoto | 0:0e0631af0305 | 546 | size_t find_last_of(const char* s, size_t pos, size_t n) const; |
| RyoheiHagimoto | 0:0e0631af0305 | 547 | size_t find_last_of(char c, size_t pos = npos) const; |
| RyoheiHagimoto | 0:0e0631af0305 | 548 | size_t find_last_of(const String& str, size_t pos = npos) const; |
| RyoheiHagimoto | 0:0e0631af0305 | 549 | size_t find_last_of(const char* s, size_t pos = npos) const; |
| RyoheiHagimoto | 0:0e0631af0305 | 550 | |
| RyoheiHagimoto | 0:0e0631af0305 | 551 | friend String operator+ (const String& lhs, const String& rhs); |
| RyoheiHagimoto | 0:0e0631af0305 | 552 | friend String operator+ (const String& lhs, const char* rhs); |
| RyoheiHagimoto | 0:0e0631af0305 | 553 | friend String operator+ (const char* lhs, const String& rhs); |
| RyoheiHagimoto | 0:0e0631af0305 | 554 | friend String operator+ (const String& lhs, char rhs); |
| RyoheiHagimoto | 0:0e0631af0305 | 555 | friend String operator+ (char lhs, const String& rhs); |
| RyoheiHagimoto | 0:0e0631af0305 | 556 | |
| RyoheiHagimoto | 0:0e0631af0305 | 557 | String toLowerCase() const; |
| RyoheiHagimoto | 0:0e0631af0305 | 558 | |
| RyoheiHagimoto | 0:0e0631af0305 | 559 | #ifndef OPENCV_NOSTL |
| RyoheiHagimoto | 0:0e0631af0305 | 560 | String(const std::string& str); |
| RyoheiHagimoto | 0:0e0631af0305 | 561 | String(const std::string& str, size_t pos, size_t len = npos); |
| RyoheiHagimoto | 0:0e0631af0305 | 562 | String& operator=(const std::string& str); |
| RyoheiHagimoto | 0:0e0631af0305 | 563 | String& operator+=(const std::string& str); |
| RyoheiHagimoto | 0:0e0631af0305 | 564 | operator std::string() const; |
| RyoheiHagimoto | 0:0e0631af0305 | 565 | |
| RyoheiHagimoto | 0:0e0631af0305 | 566 | friend String operator+ (const String& lhs, const std::string& rhs); |
| RyoheiHagimoto | 0:0e0631af0305 | 567 | friend String operator+ (const std::string& lhs, const String& rhs); |
| RyoheiHagimoto | 0:0e0631af0305 | 568 | #endif |
| RyoheiHagimoto | 0:0e0631af0305 | 569 | |
| RyoheiHagimoto | 0:0e0631af0305 | 570 | private: |
| RyoheiHagimoto | 0:0e0631af0305 | 571 | char* cstr_; |
| RyoheiHagimoto | 0:0e0631af0305 | 572 | size_t len_; |
| RyoheiHagimoto | 0:0e0631af0305 | 573 | |
| RyoheiHagimoto | 0:0e0631af0305 | 574 | char* allocate(size_t len); // len without trailing 0 |
| RyoheiHagimoto | 0:0e0631af0305 | 575 | void deallocate(); |
| RyoheiHagimoto | 0:0e0631af0305 | 576 | |
| RyoheiHagimoto | 0:0e0631af0305 | 577 | String(int); // disabled and invalid. Catch invalid usages like, commandLineParser.has(0) problem |
| RyoheiHagimoto | 0:0e0631af0305 | 578 | }; |
| RyoheiHagimoto | 0:0e0631af0305 | 579 | |
| RyoheiHagimoto | 0:0e0631af0305 | 580 | //! @} core_basic |
| RyoheiHagimoto | 0:0e0631af0305 | 581 | |
| RyoheiHagimoto | 0:0e0631af0305 | 582 | ////////////////////////// cv::String implementation ///////////////////////// |
| RyoheiHagimoto | 0:0e0631af0305 | 583 | |
| RyoheiHagimoto | 0:0e0631af0305 | 584 | //! @cond IGNORED |
| RyoheiHagimoto | 0:0e0631af0305 | 585 | |
| RyoheiHagimoto | 0:0e0631af0305 | 586 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 587 | String::String() |
| RyoheiHagimoto | 0:0e0631af0305 | 588 | : cstr_(0), len_(0) |
| RyoheiHagimoto | 0:0e0631af0305 | 589 | {} |
| RyoheiHagimoto | 0:0e0631af0305 | 590 | |
| RyoheiHagimoto | 0:0e0631af0305 | 591 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 592 | String::String(const String& str) |
| RyoheiHagimoto | 0:0e0631af0305 | 593 | : cstr_(str.cstr_), len_(str.len_) |
| RyoheiHagimoto | 0:0e0631af0305 | 594 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 595 | if (cstr_) |
| RyoheiHagimoto | 0:0e0631af0305 | 596 | CV_XADD(((int*)cstr_)-1, 1); |
| RyoheiHagimoto | 0:0e0631af0305 | 597 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 598 | |
| RyoheiHagimoto | 0:0e0631af0305 | 599 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 600 | String::String(const String& str, size_t pos, size_t len) |
| RyoheiHagimoto | 0:0e0631af0305 | 601 | : cstr_(0), len_(0) |
| RyoheiHagimoto | 0:0e0631af0305 | 602 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 603 | pos = min(pos, str.len_); |
| RyoheiHagimoto | 0:0e0631af0305 | 604 | len = min(str.len_ - pos, len); |
| RyoheiHagimoto | 0:0e0631af0305 | 605 | if (!len) return; |
| RyoheiHagimoto | 0:0e0631af0305 | 606 | if (len == str.len_) |
| RyoheiHagimoto | 0:0e0631af0305 | 607 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 608 | CV_XADD(((int*)str.cstr_)-1, 1); |
| RyoheiHagimoto | 0:0e0631af0305 | 609 | cstr_ = str.cstr_; |
| RyoheiHagimoto | 0:0e0631af0305 | 610 | len_ = str.len_; |
| RyoheiHagimoto | 0:0e0631af0305 | 611 | return; |
| RyoheiHagimoto | 0:0e0631af0305 | 612 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 613 | memcpy(allocate(len), str.cstr_ + pos, len); |
| RyoheiHagimoto | 0:0e0631af0305 | 614 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 615 | |
| RyoheiHagimoto | 0:0e0631af0305 | 616 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 617 | String::String(const char* s) |
| RyoheiHagimoto | 0:0e0631af0305 | 618 | : cstr_(0), len_(0) |
| RyoheiHagimoto | 0:0e0631af0305 | 619 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 620 | if (!s) return; |
| RyoheiHagimoto | 0:0e0631af0305 | 621 | size_t len = strlen(s); |
| RyoheiHagimoto | 0:0e0631af0305 | 622 | memcpy(allocate(len), s, len); |
| RyoheiHagimoto | 0:0e0631af0305 | 623 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 624 | |
| RyoheiHagimoto | 0:0e0631af0305 | 625 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 626 | String::String(const char* s, size_t n) |
| RyoheiHagimoto | 0:0e0631af0305 | 627 | : cstr_(0), len_(0) |
| RyoheiHagimoto | 0:0e0631af0305 | 628 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 629 | if (!n) return; |
| RyoheiHagimoto | 0:0e0631af0305 | 630 | memcpy(allocate(n), s, n); |
| RyoheiHagimoto | 0:0e0631af0305 | 631 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 632 | |
| RyoheiHagimoto | 0:0e0631af0305 | 633 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 634 | String::String(size_t n, char c) |
| RyoheiHagimoto | 0:0e0631af0305 | 635 | : cstr_(0), len_(0) |
| RyoheiHagimoto | 0:0e0631af0305 | 636 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 637 | memset(allocate(n), c, n); |
| RyoheiHagimoto | 0:0e0631af0305 | 638 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 639 | |
| RyoheiHagimoto | 0:0e0631af0305 | 640 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 641 | String::String(const char* first, const char* last) |
| RyoheiHagimoto | 0:0e0631af0305 | 642 | : cstr_(0), len_(0) |
| RyoheiHagimoto | 0:0e0631af0305 | 643 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 644 | size_t len = (size_t)(last - first); |
| RyoheiHagimoto | 0:0e0631af0305 | 645 | memcpy(allocate(len), first, len); |
| RyoheiHagimoto | 0:0e0631af0305 | 646 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 647 | |
| RyoheiHagimoto | 0:0e0631af0305 | 648 | template<typename Iterator> inline |
| RyoheiHagimoto | 0:0e0631af0305 | 649 | String::String(Iterator first, Iterator last) |
| RyoheiHagimoto | 0:0e0631af0305 | 650 | : cstr_(0), len_(0) |
| RyoheiHagimoto | 0:0e0631af0305 | 651 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 652 | size_t len = (size_t)(last - first); |
| RyoheiHagimoto | 0:0e0631af0305 | 653 | char* str = allocate(len); |
| RyoheiHagimoto | 0:0e0631af0305 | 654 | while (first != last) |
| RyoheiHagimoto | 0:0e0631af0305 | 655 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 656 | *str++ = *first; |
| RyoheiHagimoto | 0:0e0631af0305 | 657 | ++first; |
| RyoheiHagimoto | 0:0e0631af0305 | 658 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 659 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 660 | |
| RyoheiHagimoto | 0:0e0631af0305 | 661 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 662 | String::~String() |
| RyoheiHagimoto | 0:0e0631af0305 | 663 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 664 | deallocate(); |
| RyoheiHagimoto | 0:0e0631af0305 | 665 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 666 | |
| RyoheiHagimoto | 0:0e0631af0305 | 667 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 668 | String& String::operator=(const String& str) |
| RyoheiHagimoto | 0:0e0631af0305 | 669 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 670 | if (&str == this) return *this; |
| RyoheiHagimoto | 0:0e0631af0305 | 671 | |
| RyoheiHagimoto | 0:0e0631af0305 | 672 | deallocate(); |
| RyoheiHagimoto | 0:0e0631af0305 | 673 | if (str.cstr_) CV_XADD(((int*)str.cstr_)-1, 1); |
| RyoheiHagimoto | 0:0e0631af0305 | 674 | cstr_ = str.cstr_; |
| RyoheiHagimoto | 0:0e0631af0305 | 675 | len_ = str.len_; |
| RyoheiHagimoto | 0:0e0631af0305 | 676 | return *this; |
| RyoheiHagimoto | 0:0e0631af0305 | 677 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 678 | |
| RyoheiHagimoto | 0:0e0631af0305 | 679 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 680 | String& String::operator=(const char* s) |
| RyoheiHagimoto | 0:0e0631af0305 | 681 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 682 | deallocate(); |
| RyoheiHagimoto | 0:0e0631af0305 | 683 | if (!s) return *this; |
| RyoheiHagimoto | 0:0e0631af0305 | 684 | size_t len = strlen(s); |
| RyoheiHagimoto | 0:0e0631af0305 | 685 | memcpy(allocate(len), s, len); |
| RyoheiHagimoto | 0:0e0631af0305 | 686 | return *this; |
| RyoheiHagimoto | 0:0e0631af0305 | 687 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 688 | |
| RyoheiHagimoto | 0:0e0631af0305 | 689 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 690 | String& String::operator=(char c) |
| RyoheiHagimoto | 0:0e0631af0305 | 691 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 692 | deallocate(); |
| RyoheiHagimoto | 0:0e0631af0305 | 693 | allocate(1)[0] = c; |
| RyoheiHagimoto | 0:0e0631af0305 | 694 | return *this; |
| RyoheiHagimoto | 0:0e0631af0305 | 695 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 696 | |
| RyoheiHagimoto | 0:0e0631af0305 | 697 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 698 | String& String::operator+=(const String& str) |
| RyoheiHagimoto | 0:0e0631af0305 | 699 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 700 | *this = *this + str; |
| RyoheiHagimoto | 0:0e0631af0305 | 701 | return *this; |
| RyoheiHagimoto | 0:0e0631af0305 | 702 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 703 | |
| RyoheiHagimoto | 0:0e0631af0305 | 704 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 705 | String& String::operator+=(const char* s) |
| RyoheiHagimoto | 0:0e0631af0305 | 706 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 707 | *this = *this + s; |
| RyoheiHagimoto | 0:0e0631af0305 | 708 | return *this; |
| RyoheiHagimoto | 0:0e0631af0305 | 709 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 710 | |
| RyoheiHagimoto | 0:0e0631af0305 | 711 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 712 | String& String::operator+=(char c) |
| RyoheiHagimoto | 0:0e0631af0305 | 713 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 714 | *this = *this + c; |
| RyoheiHagimoto | 0:0e0631af0305 | 715 | return *this; |
| RyoheiHagimoto | 0:0e0631af0305 | 716 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 717 | |
| RyoheiHagimoto | 0:0e0631af0305 | 718 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 719 | size_t String::size() const |
| RyoheiHagimoto | 0:0e0631af0305 | 720 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 721 | return len_; |
| RyoheiHagimoto | 0:0e0631af0305 | 722 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 723 | |
| RyoheiHagimoto | 0:0e0631af0305 | 724 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 725 | size_t String::length() const |
| RyoheiHagimoto | 0:0e0631af0305 | 726 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 727 | return len_; |
| RyoheiHagimoto | 0:0e0631af0305 | 728 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 729 | |
| RyoheiHagimoto | 0:0e0631af0305 | 730 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 731 | char String::operator[](size_t idx) const |
| RyoheiHagimoto | 0:0e0631af0305 | 732 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 733 | return cstr_[idx]; |
| RyoheiHagimoto | 0:0e0631af0305 | 734 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 735 | |
| RyoheiHagimoto | 0:0e0631af0305 | 736 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 737 | char String::operator[](int idx) const |
| RyoheiHagimoto | 0:0e0631af0305 | 738 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 739 | return cstr_[idx]; |
| RyoheiHagimoto | 0:0e0631af0305 | 740 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 741 | |
| RyoheiHagimoto | 0:0e0631af0305 | 742 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 743 | const char* String::begin() const |
| RyoheiHagimoto | 0:0e0631af0305 | 744 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 745 | return cstr_; |
| RyoheiHagimoto | 0:0e0631af0305 | 746 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 747 | |
| RyoheiHagimoto | 0:0e0631af0305 | 748 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 749 | const char* String::end() const |
| RyoheiHagimoto | 0:0e0631af0305 | 750 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 751 | return len_ ? cstr_ + 1 : 0; |
| RyoheiHagimoto | 0:0e0631af0305 | 752 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 753 | |
| RyoheiHagimoto | 0:0e0631af0305 | 754 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 755 | bool String::empty() const |
| RyoheiHagimoto | 0:0e0631af0305 | 756 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 757 | return len_ == 0; |
| RyoheiHagimoto | 0:0e0631af0305 | 758 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 759 | |
| RyoheiHagimoto | 0:0e0631af0305 | 760 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 761 | const char* String::c_str() const |
| RyoheiHagimoto | 0:0e0631af0305 | 762 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 763 | return cstr_ ? cstr_ : ""; |
| RyoheiHagimoto | 0:0e0631af0305 | 764 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 765 | |
| RyoheiHagimoto | 0:0e0631af0305 | 766 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 767 | void String::swap(String& str) |
| RyoheiHagimoto | 0:0e0631af0305 | 768 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 769 | cv::swap(cstr_, str.cstr_); |
| RyoheiHagimoto | 0:0e0631af0305 | 770 | cv::swap(len_, str.len_); |
| RyoheiHagimoto | 0:0e0631af0305 | 771 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 772 | |
| RyoheiHagimoto | 0:0e0631af0305 | 773 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 774 | void String::clear() |
| RyoheiHagimoto | 0:0e0631af0305 | 775 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 776 | deallocate(); |
| RyoheiHagimoto | 0:0e0631af0305 | 777 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 778 | |
| RyoheiHagimoto | 0:0e0631af0305 | 779 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 780 | int String::compare(const char* s) const |
| RyoheiHagimoto | 0:0e0631af0305 | 781 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 782 | if (cstr_ == s) return 0; |
| RyoheiHagimoto | 0:0e0631af0305 | 783 | return strcmp(c_str(), s); |
| RyoheiHagimoto | 0:0e0631af0305 | 784 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 785 | |
| RyoheiHagimoto | 0:0e0631af0305 | 786 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 787 | int String::compare(const String& str) const |
| RyoheiHagimoto | 0:0e0631af0305 | 788 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 789 | if (cstr_ == str.cstr_) return 0; |
| RyoheiHagimoto | 0:0e0631af0305 | 790 | return strcmp(c_str(), str.c_str()); |
| RyoheiHagimoto | 0:0e0631af0305 | 791 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 792 | |
| RyoheiHagimoto | 0:0e0631af0305 | 793 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 794 | String String::substr(size_t pos, size_t len) const |
| RyoheiHagimoto | 0:0e0631af0305 | 795 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 796 | return String(*this, pos, len); |
| RyoheiHagimoto | 0:0e0631af0305 | 797 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 798 | |
| RyoheiHagimoto | 0:0e0631af0305 | 799 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 800 | size_t String::find(const char* s, size_t pos, size_t n) const |
| RyoheiHagimoto | 0:0e0631af0305 | 801 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 802 | if (n == 0 || pos + n > len_) return npos; |
| RyoheiHagimoto | 0:0e0631af0305 | 803 | const char* lmax = cstr_ + len_ - n; |
| RyoheiHagimoto | 0:0e0631af0305 | 804 | for (const char* i = cstr_ + pos; i <= lmax; ++i) |
| RyoheiHagimoto | 0:0e0631af0305 | 805 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 806 | size_t j = 0; |
| RyoheiHagimoto | 0:0e0631af0305 | 807 | while (j < n && s[j] == i[j]) ++j; |
| RyoheiHagimoto | 0:0e0631af0305 | 808 | if (j == n) return (size_t)(i - cstr_); |
| RyoheiHagimoto | 0:0e0631af0305 | 809 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 810 | return npos; |
| RyoheiHagimoto | 0:0e0631af0305 | 811 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 812 | |
| RyoheiHagimoto | 0:0e0631af0305 | 813 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 814 | size_t String::find(char c, size_t pos) const |
| RyoheiHagimoto | 0:0e0631af0305 | 815 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 816 | return find(&c, pos, 1); |
| RyoheiHagimoto | 0:0e0631af0305 | 817 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 818 | |
| RyoheiHagimoto | 0:0e0631af0305 | 819 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 820 | size_t String::find(const String& str, size_t pos) const |
| RyoheiHagimoto | 0:0e0631af0305 | 821 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 822 | return find(str.c_str(), pos, str.len_); |
| RyoheiHagimoto | 0:0e0631af0305 | 823 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 824 | |
| RyoheiHagimoto | 0:0e0631af0305 | 825 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 826 | size_t String::find(const char* s, size_t pos) const |
| RyoheiHagimoto | 0:0e0631af0305 | 827 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 828 | if (pos >= len_ || !s[0]) return npos; |
| RyoheiHagimoto | 0:0e0631af0305 | 829 | const char* lmax = cstr_ + len_; |
| RyoheiHagimoto | 0:0e0631af0305 | 830 | for (const char* i = cstr_ + pos; i < lmax; ++i) |
| RyoheiHagimoto | 0:0e0631af0305 | 831 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 832 | size_t j = 0; |
| RyoheiHagimoto | 0:0e0631af0305 | 833 | while (s[j] && s[j] == i[j]) |
| RyoheiHagimoto | 0:0e0631af0305 | 834 | { if(i + j >= lmax) return npos; |
| RyoheiHagimoto | 0:0e0631af0305 | 835 | ++j; |
| RyoheiHagimoto | 0:0e0631af0305 | 836 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 837 | if (!s[j]) return (size_t)(i - cstr_); |
| RyoheiHagimoto | 0:0e0631af0305 | 838 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 839 | return npos; |
| RyoheiHagimoto | 0:0e0631af0305 | 840 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 841 | |
| RyoheiHagimoto | 0:0e0631af0305 | 842 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 843 | size_t String::rfind(const char* s, size_t pos, size_t n) const |
| RyoheiHagimoto | 0:0e0631af0305 | 844 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 845 | if (n > len_) return npos; |
| RyoheiHagimoto | 0:0e0631af0305 | 846 | if (pos > len_ - n) pos = len_ - n; |
| RyoheiHagimoto | 0:0e0631af0305 | 847 | for (const char* i = cstr_ + pos; i >= cstr_; --i) |
| RyoheiHagimoto | 0:0e0631af0305 | 848 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 849 | size_t j = 0; |
| RyoheiHagimoto | 0:0e0631af0305 | 850 | while (j < n && s[j] == i[j]) ++j; |
| RyoheiHagimoto | 0:0e0631af0305 | 851 | if (j == n) return (size_t)(i - cstr_); |
| RyoheiHagimoto | 0:0e0631af0305 | 852 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 853 | return npos; |
| RyoheiHagimoto | 0:0e0631af0305 | 854 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 855 | |
| RyoheiHagimoto | 0:0e0631af0305 | 856 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 857 | size_t String::rfind(char c, size_t pos) const |
| RyoheiHagimoto | 0:0e0631af0305 | 858 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 859 | return rfind(&c, pos, 1); |
| RyoheiHagimoto | 0:0e0631af0305 | 860 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 861 | |
| RyoheiHagimoto | 0:0e0631af0305 | 862 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 863 | size_t String::rfind(const String& str, size_t pos) const |
| RyoheiHagimoto | 0:0e0631af0305 | 864 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 865 | return rfind(str.c_str(), pos, str.len_); |
| RyoheiHagimoto | 0:0e0631af0305 | 866 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 867 | |
| RyoheiHagimoto | 0:0e0631af0305 | 868 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 869 | size_t String::rfind(const char* s, size_t pos) const |
| RyoheiHagimoto | 0:0e0631af0305 | 870 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 871 | return rfind(s, pos, strlen(s)); |
| RyoheiHagimoto | 0:0e0631af0305 | 872 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 873 | |
| RyoheiHagimoto | 0:0e0631af0305 | 874 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 875 | size_t String::find_first_of(const char* s, size_t pos, size_t n) const |
| RyoheiHagimoto | 0:0e0631af0305 | 876 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 877 | if (n == 0 || pos + n > len_) return npos; |
| RyoheiHagimoto | 0:0e0631af0305 | 878 | const char* lmax = cstr_ + len_; |
| RyoheiHagimoto | 0:0e0631af0305 | 879 | for (const char* i = cstr_ + pos; i < lmax; ++i) |
| RyoheiHagimoto | 0:0e0631af0305 | 880 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 881 | for (size_t j = 0; j < n; ++j) |
| RyoheiHagimoto | 0:0e0631af0305 | 882 | if (s[j] == *i) |
| RyoheiHagimoto | 0:0e0631af0305 | 883 | return (size_t)(i - cstr_); |
| RyoheiHagimoto | 0:0e0631af0305 | 884 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 885 | return npos; |
| RyoheiHagimoto | 0:0e0631af0305 | 886 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 887 | |
| RyoheiHagimoto | 0:0e0631af0305 | 888 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 889 | size_t String::find_first_of(char c, size_t pos) const |
| RyoheiHagimoto | 0:0e0631af0305 | 890 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 891 | return find_first_of(&c, pos, 1); |
| RyoheiHagimoto | 0:0e0631af0305 | 892 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 893 | |
| RyoheiHagimoto | 0:0e0631af0305 | 894 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 895 | size_t String::find_first_of(const String& str, size_t pos) const |
| RyoheiHagimoto | 0:0e0631af0305 | 896 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 897 | return find_first_of(str.c_str(), pos, str.len_); |
| RyoheiHagimoto | 0:0e0631af0305 | 898 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 899 | |
| RyoheiHagimoto | 0:0e0631af0305 | 900 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 901 | size_t String::find_first_of(const char* s, size_t pos) const |
| RyoheiHagimoto | 0:0e0631af0305 | 902 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 903 | if (len_ == 0) return npos; |
| RyoheiHagimoto | 0:0e0631af0305 | 904 | if (pos >= len_ || !s[0]) return npos; |
| RyoheiHagimoto | 0:0e0631af0305 | 905 | const char* lmax = cstr_ + len_; |
| RyoheiHagimoto | 0:0e0631af0305 | 906 | for (const char* i = cstr_ + pos; i < lmax; ++i) |
| RyoheiHagimoto | 0:0e0631af0305 | 907 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 908 | for (size_t j = 0; s[j]; ++j) |
| RyoheiHagimoto | 0:0e0631af0305 | 909 | if (s[j] == *i) |
| RyoheiHagimoto | 0:0e0631af0305 | 910 | return (size_t)(i - cstr_); |
| RyoheiHagimoto | 0:0e0631af0305 | 911 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 912 | return npos; |
| RyoheiHagimoto | 0:0e0631af0305 | 913 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 914 | |
| RyoheiHagimoto | 0:0e0631af0305 | 915 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 916 | size_t String::find_last_of(const char* s, size_t pos, size_t n) const |
| RyoheiHagimoto | 0:0e0631af0305 | 917 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 918 | if (len_ == 0) return npos; |
| RyoheiHagimoto | 0:0e0631af0305 | 919 | if (pos >= len_) pos = len_ - 1; |
| RyoheiHagimoto | 0:0e0631af0305 | 920 | for (const char* i = cstr_ + pos; i >= cstr_; --i) |
| RyoheiHagimoto | 0:0e0631af0305 | 921 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 922 | for (size_t j = 0; j < n; ++j) |
| RyoheiHagimoto | 0:0e0631af0305 | 923 | if (s[j] == *i) |
| RyoheiHagimoto | 0:0e0631af0305 | 924 | return (size_t)(i - cstr_); |
| RyoheiHagimoto | 0:0e0631af0305 | 925 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 926 | return npos; |
| RyoheiHagimoto | 0:0e0631af0305 | 927 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 928 | |
| RyoheiHagimoto | 0:0e0631af0305 | 929 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 930 | size_t String::find_last_of(char c, size_t pos) const |
| RyoheiHagimoto | 0:0e0631af0305 | 931 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 932 | return find_last_of(&c, pos, 1); |
| RyoheiHagimoto | 0:0e0631af0305 | 933 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 934 | |
| RyoheiHagimoto | 0:0e0631af0305 | 935 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 936 | size_t String::find_last_of(const String& str, size_t pos) const |
| RyoheiHagimoto | 0:0e0631af0305 | 937 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 938 | return find_last_of(str.c_str(), pos, str.len_); |
| RyoheiHagimoto | 0:0e0631af0305 | 939 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 940 | |
| RyoheiHagimoto | 0:0e0631af0305 | 941 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 942 | size_t String::find_last_of(const char* s, size_t pos) const |
| RyoheiHagimoto | 0:0e0631af0305 | 943 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 944 | if (len_ == 0) return npos; |
| RyoheiHagimoto | 0:0e0631af0305 | 945 | if (pos >= len_) pos = len_ - 1; |
| RyoheiHagimoto | 0:0e0631af0305 | 946 | for (const char* i = cstr_ + pos; i >= cstr_; --i) |
| RyoheiHagimoto | 0:0e0631af0305 | 947 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 948 | for (size_t j = 0; s[j]; ++j) |
| RyoheiHagimoto | 0:0e0631af0305 | 949 | if (s[j] == *i) |
| RyoheiHagimoto | 0:0e0631af0305 | 950 | return (size_t)(i - cstr_); |
| RyoheiHagimoto | 0:0e0631af0305 | 951 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 952 | return npos; |
| RyoheiHagimoto | 0:0e0631af0305 | 953 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 954 | |
| RyoheiHagimoto | 0:0e0631af0305 | 955 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 956 | String String::toLowerCase() const |
| RyoheiHagimoto | 0:0e0631af0305 | 957 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 958 | String res(cstr_, len_); |
| RyoheiHagimoto | 0:0e0631af0305 | 959 | |
| RyoheiHagimoto | 0:0e0631af0305 | 960 | for (size_t i = 0; i < len_; ++i) |
| RyoheiHagimoto | 0:0e0631af0305 | 961 | res.cstr_[i] = (char) ::tolower(cstr_[i]); |
| RyoheiHagimoto | 0:0e0631af0305 | 962 | |
| RyoheiHagimoto | 0:0e0631af0305 | 963 | return res; |
| RyoheiHagimoto | 0:0e0631af0305 | 964 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 965 | |
| RyoheiHagimoto | 0:0e0631af0305 | 966 | //! @endcond |
| RyoheiHagimoto | 0:0e0631af0305 | 967 | |
| RyoheiHagimoto | 0:0e0631af0305 | 968 | // ************************* cv::String non-member functions ************************* |
| RyoheiHagimoto | 0:0e0631af0305 | 969 | |
| RyoheiHagimoto | 0:0e0631af0305 | 970 | //! @relates cv::String |
| RyoheiHagimoto | 0:0e0631af0305 | 971 | //! @{ |
| RyoheiHagimoto | 0:0e0631af0305 | 972 | |
| RyoheiHagimoto | 0:0e0631af0305 | 973 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 974 | String operator + (const String& lhs, const String& rhs) |
| RyoheiHagimoto | 0:0e0631af0305 | 975 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 976 | String s; |
| RyoheiHagimoto | 0:0e0631af0305 | 977 | s.allocate(lhs.len_ + rhs.len_); |
| RyoheiHagimoto | 0:0e0631af0305 | 978 | memcpy(s.cstr_, lhs.cstr_, lhs.len_); |
| RyoheiHagimoto | 0:0e0631af0305 | 979 | memcpy(s.cstr_ + lhs.len_, rhs.cstr_, rhs.len_); |
| RyoheiHagimoto | 0:0e0631af0305 | 980 | return s; |
| RyoheiHagimoto | 0:0e0631af0305 | 981 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 982 | |
| RyoheiHagimoto | 0:0e0631af0305 | 983 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 984 | String operator + (const String& lhs, const char* rhs) |
| RyoheiHagimoto | 0:0e0631af0305 | 985 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 986 | String s; |
| RyoheiHagimoto | 0:0e0631af0305 | 987 | size_t rhslen = strlen(rhs); |
| RyoheiHagimoto | 0:0e0631af0305 | 988 | s.allocate(lhs.len_ + rhslen); |
| RyoheiHagimoto | 0:0e0631af0305 | 989 | memcpy(s.cstr_, lhs.cstr_, lhs.len_); |
| RyoheiHagimoto | 0:0e0631af0305 | 990 | memcpy(s.cstr_ + lhs.len_, rhs, rhslen); |
| RyoheiHagimoto | 0:0e0631af0305 | 991 | return s; |
| RyoheiHagimoto | 0:0e0631af0305 | 992 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 993 | |
| RyoheiHagimoto | 0:0e0631af0305 | 994 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 995 | String operator + (const char* lhs, const String& rhs) |
| RyoheiHagimoto | 0:0e0631af0305 | 996 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 997 | String s; |
| RyoheiHagimoto | 0:0e0631af0305 | 998 | size_t lhslen = strlen(lhs); |
| RyoheiHagimoto | 0:0e0631af0305 | 999 | s.allocate(lhslen + rhs.len_); |
| RyoheiHagimoto | 0:0e0631af0305 | 1000 | memcpy(s.cstr_, lhs, lhslen); |
| RyoheiHagimoto | 0:0e0631af0305 | 1001 | memcpy(s.cstr_ + lhslen, rhs.cstr_, rhs.len_); |
| RyoheiHagimoto | 0:0e0631af0305 | 1002 | return s; |
| RyoheiHagimoto | 0:0e0631af0305 | 1003 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 1004 | |
| RyoheiHagimoto | 0:0e0631af0305 | 1005 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 1006 | String operator + (const String& lhs, char rhs) |
| RyoheiHagimoto | 0:0e0631af0305 | 1007 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 1008 | String s; |
| RyoheiHagimoto | 0:0e0631af0305 | 1009 | s.allocate(lhs.len_ + 1); |
| RyoheiHagimoto | 0:0e0631af0305 | 1010 | memcpy(s.cstr_, lhs.cstr_, lhs.len_); |
| RyoheiHagimoto | 0:0e0631af0305 | 1011 | s.cstr_[lhs.len_] = rhs; |
| RyoheiHagimoto | 0:0e0631af0305 | 1012 | return s; |
| RyoheiHagimoto | 0:0e0631af0305 | 1013 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 1014 | |
| RyoheiHagimoto | 0:0e0631af0305 | 1015 | inline |
| RyoheiHagimoto | 0:0e0631af0305 | 1016 | String operator + (char lhs, const String& rhs) |
| RyoheiHagimoto | 0:0e0631af0305 | 1017 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 1018 | String s; |
| RyoheiHagimoto | 0:0e0631af0305 | 1019 | s.allocate(rhs.len_ + 1); |
| RyoheiHagimoto | 0:0e0631af0305 | 1020 | s.cstr_[0] = lhs; |
| RyoheiHagimoto | 0:0e0631af0305 | 1021 | memcpy(s.cstr_ + 1, rhs.cstr_, rhs.len_); |
| RyoheiHagimoto | 0:0e0631af0305 | 1022 | return s; |
| RyoheiHagimoto | 0:0e0631af0305 | 1023 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 1024 | |
| RyoheiHagimoto | 0:0e0631af0305 | 1025 | static inline bool operator== (const String& lhs, const String& rhs) { return 0 == lhs.compare(rhs); } |
| RyoheiHagimoto | 0:0e0631af0305 | 1026 | static inline bool operator== (const char* lhs, const String& rhs) { return 0 == rhs.compare(lhs); } |
| RyoheiHagimoto | 0:0e0631af0305 | 1027 | static inline bool operator== (const String& lhs, const char* rhs) { return 0 == lhs.compare(rhs); } |
| RyoheiHagimoto | 0:0e0631af0305 | 1028 | static inline bool operator!= (const String& lhs, const String& rhs) { return 0 != lhs.compare(rhs); } |
| RyoheiHagimoto | 0:0e0631af0305 | 1029 | static inline bool operator!= (const char* lhs, const String& rhs) { return 0 != rhs.compare(lhs); } |
| RyoheiHagimoto | 0:0e0631af0305 | 1030 | static inline bool operator!= (const String& lhs, const char* rhs) { return 0 != lhs.compare(rhs); } |
| RyoheiHagimoto | 0:0e0631af0305 | 1031 | static inline bool operator< (const String& lhs, const String& rhs) { return lhs.compare(rhs) < 0; } |
| RyoheiHagimoto | 0:0e0631af0305 | 1032 | static inline bool operator< (const char* lhs, const String& rhs) { return rhs.compare(lhs) > 0; } |
| RyoheiHagimoto | 0:0e0631af0305 | 1033 | static inline bool operator< (const String& lhs, const char* rhs) { return lhs.compare(rhs) < 0; } |
| RyoheiHagimoto | 0:0e0631af0305 | 1034 | static inline bool operator<= (const String& lhs, const String& rhs) { return lhs.compare(rhs) <= 0; } |
| RyoheiHagimoto | 0:0e0631af0305 | 1035 | static inline bool operator<= (const char* lhs, const String& rhs) { return rhs.compare(lhs) >= 0; } |
| RyoheiHagimoto | 0:0e0631af0305 | 1036 | static inline bool operator<= (const String& lhs, const char* rhs) { return lhs.compare(rhs) <= 0; } |
| RyoheiHagimoto | 0:0e0631af0305 | 1037 | static inline bool operator> (const String& lhs, const String& rhs) { return lhs.compare(rhs) > 0; } |
| RyoheiHagimoto | 0:0e0631af0305 | 1038 | static inline bool operator> (const char* lhs, const String& rhs) { return rhs.compare(lhs) < 0; } |
| RyoheiHagimoto | 0:0e0631af0305 | 1039 | static inline bool operator> (const String& lhs, const char* rhs) { return lhs.compare(rhs) > 0; } |
| RyoheiHagimoto | 0:0e0631af0305 | 1040 | static inline bool operator>= (const String& lhs, const String& rhs) { return lhs.compare(rhs) >= 0; } |
| RyoheiHagimoto | 0:0e0631af0305 | 1041 | static inline bool operator>= (const char* lhs, const String& rhs) { return rhs.compare(lhs) <= 0; } |
| RyoheiHagimoto | 0:0e0631af0305 | 1042 | static inline bool operator>= (const String& lhs, const char* rhs) { return lhs.compare(rhs) >= 0; } |
| RyoheiHagimoto | 0:0e0631af0305 | 1043 | |
| RyoheiHagimoto | 0:0e0631af0305 | 1044 | //! @} relates cv::String |
| RyoheiHagimoto | 0:0e0631af0305 | 1045 | |
| RyoheiHagimoto | 0:0e0631af0305 | 1046 | } // cv |
| RyoheiHagimoto | 0:0e0631af0305 | 1047 | |
| RyoheiHagimoto | 0:0e0631af0305 | 1048 | #ifndef OPENCV_NOSTL_TRANSITIONAL |
| RyoheiHagimoto | 0:0e0631af0305 | 1049 | namespace std |
| RyoheiHagimoto | 0:0e0631af0305 | 1050 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 1051 | static inline void swap(cv::String& a, cv::String& b) { a.swap(b); } |
| RyoheiHagimoto | 0:0e0631af0305 | 1052 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 1053 | #else |
| RyoheiHagimoto | 0:0e0631af0305 | 1054 | namespace cv |
| RyoheiHagimoto | 0:0e0631af0305 | 1055 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 1056 | template<> inline |
| RyoheiHagimoto | 0:0e0631af0305 | 1057 | void swap<cv::String>(cv::String& a, cv::String& b) |
| RyoheiHagimoto | 0:0e0631af0305 | 1058 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 1059 | a.swap(b); |
| RyoheiHagimoto | 0:0e0631af0305 | 1060 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 1061 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 1062 | #endif |
| RyoheiHagimoto | 0:0e0631af0305 | 1063 | |
| RyoheiHagimoto | 0:0e0631af0305 | 1064 | #include "opencv2/core/ptr.inl.hpp" |
| RyoheiHagimoto | 0:0e0631af0305 | 1065 | |
| RyoheiHagimoto | 0:0e0631af0305 | 1066 | #endif //OPENCV_CORE_CVSTD_HPP |