1/*M///////////////////////////////////////////////////////////////////////////////////////
2//
3// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4//
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.
8//
9//
10// License Agreement
11// For Open Source Computer Vision Library
12//
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.
17//
18// Redistribution and use in source and binary forms, with or without modification,
19// are permitted provided that the following conditions are met:
20//
21// * Redistribution's of source code must retain the above copyright notice,
22// this list of conditions and the following disclaimer.
23//
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.
27//
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.
30//
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.
41//
42//M*/
43
44#ifndef OPENCV_CORE_CVSTD_HPP
45#define OPENCV_CORE_CVSTD_HPP
46
47#ifndef __cplusplus
48# error cvstd.hpp header must be compiled as C++
49#endif
50
51#include "opencv2/core/cvdef.h"
52#include <cstddef>
53#include <cstring>
54#include <cctype>
55
56#include <string>
57
58// import useful primitives from stl
59# include <algorithm>
60# include <utility>
61# include <cstdlib> //for abs(int)
62# include <cmath>
63
64namespace cv
65{
66 static inline uchar abs(uchar a) { return a; }
67 static inline ushort abs(ushort a) { return a; }
68 static inline unsigned abs(unsigned a) { return a; }
69 static inline uint64 abs(uint64 a) { return a; }
70
71 using std::min;
72 using std::max;
73 using std::abs;
74 using std::swap;
75 using std::sqrt;
76 using std::exp;
77 using std::pow;
78 using std::log;
79}
80
81#include "cvstd_wrapper.hpp"
82
83namespace cv {
84
85//! @addtogroup core_utils
86//! @{
87
88//////////////////////////// memory management functions ////////////////////////////
89
90/** @brief Allocates an aligned memory buffer.
91
92The function allocates the buffer of the specified size and returns it. When the buffer size is 16
93bytes or more, the returned buffer is aligned to 16 bytes.
94@param bufSize Allocated buffer size.
95 */
96CV_EXPORTS void* fastMalloc(size_t bufSize);
97
98/** @brief Deallocates a memory buffer.
99
100The function deallocates the buffer allocated with fastMalloc . If NULL pointer is passed, the
101function does nothing. C version of the function clears the pointer *pptr* to avoid problems with
102double memory deallocation.
103@param ptr Pointer to the allocated buffer.
104 */
105CV_EXPORTS void fastFree(void* ptr);
106
107/*!
108 The STL-compliant memory Allocator based on cv::fastMalloc() and cv::fastFree()
109*/
110template<typename _Tp> class Allocator
111{
112public:
113 typedef _Tp value_type;
114 typedef value_type* pointer;
115 typedef const value_type* const_pointer;
116 typedef value_type& reference;
117 typedef const value_type& const_reference;
118 typedef size_t size_type;
119 typedef ptrdiff_t difference_type;
120 template<typename U> class rebind { typedef Allocator<U> other; };
121
122 explicit Allocator() {}
123 ~Allocator() {}
124 explicit Allocator(Allocator const&) {}
125 template<typename U>
126 explicit Allocator(Allocator<U> const&) {}
127
128 // address
129 pointer address(reference r) { return &r; }
130 const_pointer address(const_reference r) { return &r; }
131
132 pointer allocate(size_type count, const void* =0) { return reinterpret_cast<pointer>(fastMalloc(bufSize: count * sizeof (_Tp))); }
133 void deallocate(pointer p, size_type) { fastFree(p); }
134
135 void construct(pointer p, const _Tp& v) { new(static_cast<void*>(p)) _Tp(v); }
136 void destroy(pointer p) { p->~_Tp(); }
137
138 size_type max_size() const { return cv::max(static_cast<_Tp>(-1)/sizeof(_Tp), 1); }
139};
140
141//! @} core_utils
142
143
144//! @addtogroup core_basic
145//! @{
146
147//////////////////////////////// string class ////////////////////////////////
148
149class CV_EXPORTS FileNode; //for string constructor from FileNode
150
151typedef std::string String;
152
153#ifndef OPENCV_DISABLE_STRING_LOWER_UPPER_CONVERSIONS
154
155//! @cond IGNORED
156namespace details {
157// std::tolower is int->int
158static inline char char_tolower(char ch)
159{
160 return (char)std::tolower(c: (int)ch);
161}
162// std::toupper is int->int
163static inline char char_toupper(char ch)
164{
165 return (char)std::toupper(c: (int)ch);
166}
167} // namespace details
168//! @endcond
169
170static inline std::string toLowerCase(const std::string& str)
171{
172 std::string result(str);
173 std::transform(first: result.begin(), last: result.end(), result: result.begin(), unary_op: details::char_tolower);
174 return result;
175}
176
177static inline std::string toUpperCase(const std::string& str)
178{
179 std::string result(str);
180 std::transform(first: result.begin(), last: result.end(), result: result.begin(), unary_op: details::char_toupper);
181 return result;
182}
183
184#endif // OPENCV_DISABLE_STRING_LOWER_UPPER_CONVERSIONS
185
186//! @} core_basic
187} // cv
188
189#endif //OPENCV_CORE_CVSTD_HPP
190

source code of opencv/modules/core/include/opencv2/core/cvstd.hpp