ivl 679
|
00001 /* This file is part of the ivl C++ library <http://image.ntua.gr/ivl>. 00002 A C++ template library extending syntax towards mathematical notation. 00003 00004 Copyright (C) 2012 Yannis Avrithis <iavr@image.ntua.gr> 00005 Copyright (C) 2012 Kimon Kontosis <kimonas@image.ntua.gr> 00006 00007 ivl is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU Lesser General Public License 00009 version 3 as published by the Free Software Foundation. 00010 00011 Alternatively, you can redistribute it and/or modify it under the terms 00012 of the GNU General Public License version 2 as published by the Free 00013 Software Foundation. 00014 00015 ivl is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00018 See the GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 and a copy of the GNU Lesser General Public License along 00022 with ivl. If not, see <http://www.gnu.org/licenses/>. */ 00023 00024 00025 template<> 00026 class scalar<bool> : public types::scalar_identifier 00027 { 00028 typedef bool prv_elem_type; 00029 prv_elem_type v; 00030 public: 00031 typedef prv_elem_type elem_type; 00032 scalar() { } 00033 scalar(const scalar& s) : v(static_cast<const prv_elem_type&>(s)) { } 00034 template <class J> 00035 scalar(const scalar<J>& s) : v(static_cast<const J&>(s)) { } 00036 scalar(const prv_elem_type& s) : v(s) { } 00037 operator prv_elem_type&() { return v; } 00038 operator const prv_elem_type&() const { return v; } 00039 prv_elem_type& base() { return v; } 00040 const prv_elem_type& base() const { return v; } 00041 }; 00042 00043 template<> 00044 class scalar<int8_t> : public types::scalar_identifier 00045 { 00046 typedef int8_t prv_elem_type; 00047 prv_elem_type v; 00048 public: 00049 typedef prv_elem_type elem_type; 00050 scalar() { } 00051 scalar(const scalar& s) : v(static_cast<const prv_elem_type&>(s)) { } 00052 template <class J> 00053 scalar(const scalar<J>& s) : v(static_cast<const J&>(s)) { } 00054 scalar(const prv_elem_type& s) : v(s) { } 00055 operator prv_elem_type&() { return v; } 00056 operator const prv_elem_type&() const { return v; } 00057 prv_elem_type& base() { return v; } 00058 const prv_elem_type& base() const { return v; } 00059 }; 00060 template<> 00061 class scalar<uint8_t> : public types::scalar_identifier 00062 { 00063 typedef uint8_t prv_elem_type; 00064 prv_elem_type v; 00065 public: 00066 typedef prv_elem_type elem_type; 00067 scalar() { } 00068 scalar(const scalar& s) : v(static_cast<const prv_elem_type&>(s)) { } 00069 template <class J> 00070 scalar(const scalar<J>& s) : v(static_cast<const J&>(s)) { } 00071 scalar(const prv_elem_type& s) : v(s) { } 00072 operator prv_elem_type&() { return v; } 00073 operator const prv_elem_type&() const { return v; } 00074 prv_elem_type& base() { return v; } 00075 const prv_elem_type& base() const { return v; } 00076 }; 00077 template<> 00078 class scalar<int16_t> : public types::scalar_identifier 00079 { 00080 typedef int16_t prv_elem_type; 00081 prv_elem_type v; 00082 public: 00083 typedef prv_elem_type elem_type; 00084 scalar() { } 00085 scalar(const scalar& s) : v(static_cast<const prv_elem_type&>(s)) { } 00086 template <class J> 00087 scalar(const scalar<J>& s) : v(static_cast<const J&>(s)) { } 00088 scalar(const prv_elem_type& s) : v(s) { } 00089 operator prv_elem_type&() { return v; } 00090 operator const prv_elem_type&() const { return v; } 00091 prv_elem_type& base() { return v; } 00092 const prv_elem_type& base() const { return v; } 00093 }; 00094 template<> 00095 class scalar<uint16_t> : public types::scalar_identifier 00096 { 00097 typedef uint16_t prv_elem_type; 00098 prv_elem_type v; 00099 public: 00100 typedef prv_elem_type elem_type; 00101 scalar() { } 00102 scalar(const scalar& s) : v(static_cast<const prv_elem_type&>(s)) { } 00103 template <class J> 00104 scalar(const scalar<J>& s) : v(static_cast<const J&>(s)) { } 00105 scalar(const prv_elem_type& s) : v(s) { } 00106 operator prv_elem_type&() { return v; } 00107 operator const prv_elem_type&() const { return v; } 00108 prv_elem_type& base() { return v; } 00109 const prv_elem_type& base() const { return v; } 00110 }; 00111 template<> 00112 class scalar<int32_t> : public types::scalar_identifier 00113 { 00114 typedef int32_t prv_elem_type; 00115 prv_elem_type v; 00116 public: 00117 typedef prv_elem_type elem_type; 00118 scalar() { } 00119 scalar(const scalar& s) : v(static_cast<const prv_elem_type&>(s)) { } 00120 template <class J> 00121 scalar(const scalar<J>& s) : v(static_cast<const J&>(s)) { } 00122 scalar(const prv_elem_type& s) : v(s) { } 00123 operator prv_elem_type&() { return v; } 00124 operator const prv_elem_type&() const { return v; } 00125 prv_elem_type& base() { return v; } 00126 const prv_elem_type& base() const { return v; } 00127 }; 00128 template<> 00129 class scalar<uint32_t> : public types::scalar_identifier 00130 { 00131 typedef uint32_t prv_elem_type; 00132 prv_elem_type v; 00133 public: 00134 typedef prv_elem_type elem_type; 00135 scalar() { } 00136 scalar(const scalar& s) : v(static_cast<const prv_elem_type&>(s)) { } 00137 template <class J> 00138 scalar(const scalar<J>& s) : v(static_cast<const J&>(s)) { } 00139 scalar(const prv_elem_type& s) : v(s) { } 00140 operator prv_elem_type&() { return v; } 00141 operator const prv_elem_type&() const { return v; } 00142 prv_elem_type& base() { return v; } 00143 const prv_elem_type& base() const { return v; } 00144 }; 00145 template<> 00146 class scalar<int64_t> : public types::scalar_identifier 00147 { 00148 typedef int64_t prv_elem_type; 00149 prv_elem_type v; 00150 public: 00151 typedef prv_elem_type elem_type; 00152 scalar() { } 00153 scalar(const scalar& s) : v(static_cast<const prv_elem_type&>(s)) { } 00154 template <class J> 00155 scalar(const scalar<J>& s) : v(static_cast<const J&>(s)) { } 00156 scalar(const prv_elem_type& s) : v(s) { } 00157 operator prv_elem_type&() { return v; } 00158 operator const prv_elem_type&() const { return v; } 00159 prv_elem_type& base() { return v; } 00160 const prv_elem_type& base() const { return v; } 00161 }; 00162 template<> 00163 class scalar<uint64_t> : public types::scalar_identifier 00164 { 00165 typedef uint64_t prv_elem_type; 00166 prv_elem_type v; 00167 public: 00168 typedef prv_elem_type elem_type; 00169 scalar() { } 00170 scalar(const scalar& s) : v(static_cast<const prv_elem_type&>(s)) { } 00171 template <class J> 00172 scalar(const scalar<J>& s) : v(static_cast<const J&>(s)) { } 00173 scalar(const prv_elem_type& s) : v(s) { } 00174 operator prv_elem_type&() { return v; } 00175 operator const prv_elem_type&() const { return v; } 00176 prv_elem_type& base() { return v; } 00177 const prv_elem_type& base() const { return v; } 00178 }; 00179 00180 #ifndef _MSC_VER 00181 // g++ has a special type for `char' which is neither 00182 // int8_t nor int16_t but a type of its own, whatever implementation 00183 // is used. So it has to be specially treated. 00184 // This does not hold for unsigned char though. 00185 template<> 00186 class scalar<char> : public types::scalar_identifier 00187 { 00188 typedef char prv_elem_type; 00189 prv_elem_type v; 00190 public: 00191 typedef prv_elem_type elem_type; 00192 scalar() { } 00193 scalar(const scalar& s) : v(static_cast<const prv_elem_type&>(s)) { } 00194 template <class J> 00195 scalar(const scalar<J>& s) : v(static_cast<const J&>(s)) { } 00196 scalar(const prv_elem_type& s) : v(s) { } 00197 operator prv_elem_type&() { return v; } 00198 operator const prv_elem_type&() const { return v; } 00199 prv_elem_type& base() { return v; } 00200 const prv_elem_type& base() const { return v; } 00201 }; 00202 #endif