opencv on mbed

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers cvstd.inl.hpp Source File

cvstd.inl.hpp

00001 /*M///////////////////////////////////////////////////////////////////////////////////////
00002 //
00003 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
00004 //
00005 //  By downloading, copying, installing or using the software you agree to this license.
00006 //  If you do not agree to this license, do not download, install,
00007 //  copy or use the software.
00008 //
00009 //
00010 //                          License Agreement
00011 //                For Open Source Computer Vision Library
00012 //
00013 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
00014 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
00015 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
00016 // Third party copyrights are property of their respective owners.
00017 //
00018 // Redistribution and use in source and binary forms, with or without modification,
00019 // are permitted provided that the following conditions are met:
00020 //
00021 //   * Redistribution's of source code must retain the above copyright notice,
00022 //     this list of conditions and the following disclaimer.
00023 //
00024 //   * Redistribution's in binary form must reproduce the above copyright notice,
00025 //     this list of conditions and the following disclaimer in the documentation
00026 //     and/or other materials provided with the distribution.
00027 //
00028 //   * The name of the copyright holders may not be used to endorse or promote products
00029 //     derived from this software without specific prior written permission.
00030 //
00031 // This software is provided by the copyright holders and contributors "as is" and
00032 // any express or implied warranties, including, but not limited to, the implied
00033 // warranties of merchantability and fitness for a particular purpose are disclaimed.
00034 // In no event shall the Intel Corporation or contributors be liable for any direct,
00035 // indirect, incidental, special, exemplary, or consequential damages
00036 // (including, but not limited to, procurement of substitute goods or services;
00037 // loss of use, data, or profits; or business interruption) however caused
00038 // and on any theory of liability, whether in contract, strict liability,
00039 // or tort (including negligence or otherwise) arising in any way out of
00040 // the use of this software, even if advised of the possibility of such damage.
00041 //
00042 //M*/
00043 
00044 #ifndef __OPENCV_CORE_CVSTDINL_HPP__
00045 #define __OPENCV_CORE_CVSTDINL_HPP__
00046 
00047 #ifndef OPENCV_NOSTL
00048 #  include <complex>
00049 #  include <ostream>
00050 #endif
00051 
00052 //! @cond IGNORED
00053 
00054 namespace cv
00055 {
00056 #ifndef OPENCV_NOSTL
00057 
00058 template<typename _Tp> class DataType< std::complex<_Tp> >
00059 {
00060 public:
00061     typedef std::complex<_Tp>  value_type;
00062     typedef value_type         work_type;
00063     typedef _Tp                channel_type;
00064 
00065     enum { generic_type = 0,
00066            depth        = DataType<channel_type>::depth,
00067            channels     = 2,
00068            fmt          = DataType<channel_type>::fmt + ((channels - 1) << 8),
00069            type         = CV_MAKETYPE(depth, channels) };
00070 
00071     typedef Vec<channel_type, channels> vec_type;
00072 };
00073 
00074 inline
00075 String::String(const std::string& str)
00076     : cstr_(0), len_(0)
00077 {
00078     if (!str.empty())
00079     {
00080         size_t len = str.size();
00081         std::memcpy(allocate(len), str.c_str(), len);
00082     }
00083 }
00084 
00085 inline
00086 String::String(const std::string& str, size_t pos, size_t len)
00087     : cstr_(0), len_(0)
00088 {
00089     size_t strlen = str.size();
00090     pos = min(pos, strlen);
00091     len = min(strlen - pos, len);
00092     if (!len) return;
00093     std::memcpy(allocate(len), str.c_str() + pos, len);
00094 }
00095 
00096 inline
00097 String& String::operator = (const std::string& str)
00098 {
00099     deallocate();
00100     if (!str.empty())
00101     {
00102         size_t len = str.size();
00103         std::memcpy(allocate(len), str.c_str(), len);
00104     }
00105     return *this;
00106 }
00107 
00108 inline
00109 String& String::operator += (const std::string& str)
00110 {
00111     *this = *this + str;
00112     return *this;
00113 }
00114 
00115 inline
00116 String::operator std::string() const
00117 {
00118     return std::string(cstr_, len_);
00119 }
00120 
00121 inline
00122 String operator + (const String& lhs, const std::string& rhs)
00123 {
00124     String s;
00125     size_t rhslen = rhs.size();
00126     s.allocate(lhs.len_ + rhslen);
00127     std::memcpy(s.cstr_, lhs.cstr_, lhs.len_);
00128     memcpy(s.cstr_ + lhs.len_, rhs.c_str(), rhslen);
00129     return s;
00130 }
00131 
00132 inline
00133 String operator + (const std::string& lhs, const String& rhs)
00134 {
00135     String s;
00136     size_t lhslen = lhs.size();
00137     s.allocate(lhslen + rhs.len_);
00138     std::memcpy(s.cstr_, lhs.c_str(), lhslen);
00139     memcpy(s.cstr_ + lhslen, rhs.cstr_, rhs.len_);
00140     return s;
00141 }
00142 
00143 inline
00144 FileNode::operator std::string() const
00145 {
00146     String value;
00147     read(*this, value, value);
00148     return value;
00149 }
00150 
00151 template<> inline
00152 void operator >> (const FileNode& n, std::string& value)
00153 {
00154     String val;
00155     read(n, val, val);
00156     value = val;
00157 }
00158 
00159 template<> inline
00160 FileStorage& operator << (FileStorage& fs, const std::string& value)
00161 {
00162     return fs << cv::String(value);
00163 }
00164 
00165 static inline
00166 std::ostream& operator << (std::ostream& os, const String& str)
00167 {
00168     return os << str.c_str();
00169 }
00170 
00171 static inline
00172 std::ostream& operator << (std::ostream& out, Ptr<Formatted> fmtd)
00173 {
00174     fmtd->reset();
00175     for(const char* str = fmtd->next(); str; str = fmtd->next())
00176         out << str;
00177     return out;
00178 }
00179 
00180 static inline
00181 std::ostream& operator << (std::ostream& out, const Mat& mtx)
00182 {
00183     return out << Formatter::get()->format(mtx);
00184 }
00185 
00186 template<typename _Tp> static inline
00187 std::ostream& operator << (std::ostream& out, const std::vector<Point_<_Tp> >& vec)
00188 {
00189     return out << Formatter::get()->format(Mat(vec));
00190 }
00191 
00192 
00193 template<typename _Tp> static inline
00194 std::ostream& operator << (std::ostream& out, const std::vector<Point3_<_Tp> >& vec)
00195 {
00196     return out << Formatter::get()->format(Mat(vec));
00197 }
00198 
00199 
00200 template<typename _Tp, int m, int n> static inline
00201 std::ostream& operator << (std::ostream& out, const Matx<_Tp, m, n>& matx)
00202 {
00203     return out << Formatter::get()->format(Mat(matx));
00204 }
00205 
00206 template<typename _Tp> static inline
00207 std::ostream& operator << (std::ostream& out, const Point_<_Tp>& p)
00208 {
00209     out << "[" << p.x << ", " << p.y << "]";
00210     return out;
00211 }
00212 
00213 template<typename _Tp> static inline
00214 std::ostream& operator << (std::ostream& out, const Point3_<_Tp>& p)
00215 {
00216     out << "[" << p.x << ", " << p.y << ", " << p.z << "]";
00217     return out;
00218 }
00219 
00220 template<typename _Tp, int n> static inline
00221 std::ostream& operator << (std::ostream& out, const Vec<_Tp, n>& vec)
00222 {
00223     out << "[";
00224 #ifdef _MSC_VER
00225 #pragma warning( push )
00226 #pragma warning( disable: 4127 )
00227 #endif
00228     if(Vec<_Tp, n>::depth < CV_32F)
00229 #ifdef _MSC_VER
00230 #pragma warning( pop )
00231 #endif
00232     {
00233         for (int i = 0; i < n - 1; ++i) {
00234             out << (int)vec[i] << ", ";
00235         }
00236         out << (int)vec[n-1] << "]";
00237     }
00238     else
00239     {
00240         for (int i = 0; i < n - 1; ++i) {
00241             out << vec[i] << ", ";
00242         }
00243         out << vec[n-1] << "]";
00244     }
00245 
00246     return out;
00247 }
00248 
00249 template<typename _Tp> static inline
00250 std::ostream& operator << (std::ostream& out, const Size_<_Tp>& size)
00251 {
00252     return out << "[" << size.width << " x " << size.height << "]";
00253 }
00254 
00255 template<typename _Tp> static inline
00256 std::ostream& operator << (std::ostream& out, const Rect_<_Tp>& rect)
00257 {
00258     return out << "[" << rect.width << " x " << rect.height << " from (" << rect.x << ", " << rect.y << ")]";
00259 }
00260 
00261 
00262 #endif // OPENCV_NOSTL
00263 } // cv
00264 
00265 //! @endcond
00266 
00267 #endif // __OPENCV_CORE_CVSTDINL_HPP__
00268