Field3D
Traits.h
Go to the documentation of this file.
00001 //----------------------------------------------------------------------------//
00002 
00003 /*
00004  * Copyright (c) 2009 Sony Pictures Imageworks Inc
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  *
00012  * Redistributions of source code must retain the above copyright
00013  * notice, this list of conditions and the following disclaimer.
00014  * Redistributions in binary form must reproduce the above copyright
00015  * notice, this list of conditions and the following disclaimer in the
00016  * documentation and/or other materials provided with the
00017  * distribution.  Neither the name of Sony Pictures Imageworks nor the
00018  * names of its contributors may be used to endorse or promote
00019  * products derived from this software without specific prior written
00020  * permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
00026  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00028  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00029  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00031  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
00033  * OF THE POSSIBILITY OF SUCH DAMAGE.
00034  */
00035 
00036 //----------------------------------------------------------------------------//
00037 
00043 //----------------------------------------------------------------------------//
00044 
00045 #ifndef _INCLUDED_Field3D_Traits_H_
00046 #define _INCLUDED_Field3D_Traits_H_
00047 
00048 #include <string>
00049 
00050 #include <assert.h>
00051 
00052 #include <hdf5.h>
00053 
00054 #include "Log.h"
00055 #include "Types.h"
00056 
00057 //----------------------------------------------------------------------------//
00058 
00059 #include "ns.h"
00060 
00061 FIELD3D_NAMESPACE_OPEN
00062 
00063 //----------------------------------------------------------------------------//
00064 // Enums
00065 //----------------------------------------------------------------------------//
00066 
00067 enum DataTypeEnum {
00068   DataTypeHalf=0,
00069   DataTypeFloat,
00070   DataTypeDouble,
00071   DataTypeVecHalf,
00072   DataTypeVecFloat,
00073   DataTypeVecDouble,
00074   DataTypeUnknown
00075 };
00076 
00077 //----------------------------------------------------------------------------//
00078 // Data Structures
00079 //----------------------------------------------------------------------------//
00080 
00081 template <typename T>
00082 struct DataTypeTraits {
00083   static std::string name() {
00084     assert(false && "Unsupported type in DataTypeTraits::name()");
00085     Msg::print(Msg::SevWarning, "Unsupported type in DataTypeTraits::name()");
00086     return std::string("ERROR in DataTypeTraits::name()");
00087   }
00088   static DataTypeEnum typeEnum() {
00089     assert(false && "Unsupported type in DataTypeTraits::typeEnum()");
00090     Msg::print(Msg::SevWarning,
00091                "Unsupported type in DataTypeTraits::typeEnum()");
00092     return DataTypeUnknown;
00093   }
00094   static hid_t h5type() {
00095     assert(false && "Unsupported type in DataTypeTraits::h5type()");
00096     Msg::print(Msg::SevWarning,
00097                "Unsupported type in DataTypeTraits::h5type()");
00098     return 0;
00099   }
00100   static int h5bits() {
00101     assert(false && "Unsupported type in DataTypeTraits::h5bits()");
00102     Msg::print(Msg::SevWarning,
00103                "Unsupported type in DataTypeTraits::h5bits()");
00104     return 0;
00105   }
00106 };
00107 
00108 //----------------------------------------------------------------------------//
00109 // Template specializations
00110 //----------------------------------------------------------------------------//
00111 
00112 template<>
00113 inline std::string DataTypeTraits<half>::name()
00114 {
00115   return std::string("half");
00116 }
00117 
00118 //----------------------------------------------------------------------------//
00119 
00120 template<>
00121 inline std::string DataTypeTraits<float>::name()
00122 {
00123   return std::string("float");
00124 }
00125 
00126 //----------------------------------------------------------------------------//
00127 
00128 template<>
00129 inline std::string DataTypeTraits<double>::name()
00130 {
00131   return std::string("double");
00132 }
00133 
00134 //----------------------------------------------------------------------------//
00135 
00136 template<>
00137 inline std::string DataTypeTraits<V3h>::name()
00138 {
00139   return std::string("V3h");
00140 }
00141 
00142 //----------------------------------------------------------------------------//
00143 
00144 template<>
00145 inline std::string DataTypeTraits<V3f>::name()
00146 {
00147   return std::string("V3f");
00148 }
00149 
00150 //----------------------------------------------------------------------------//
00151 
00152 template<>
00153 inline std::string DataTypeTraits<V3d>::name()
00154 {
00155   return std::string("V3d");
00156 }
00157 
00158 //----------------------------------------------------------------------------//
00159 
00160 template<>
00161 inline DataTypeEnum DataTypeTraits<half>::typeEnum()
00162 {
00163   return DataTypeHalf;
00164 }
00165 
00166 //----------------------------------------------------------------------------//
00167 
00168 template<>
00169 inline DataTypeEnum DataTypeTraits<float>::typeEnum()
00170 {
00171   return DataTypeFloat;
00172 }
00173 
00174 //----------------------------------------------------------------------------//
00175 
00176 template<>
00177 inline DataTypeEnum DataTypeTraits<double>::typeEnum()
00178 {
00179   return DataTypeDouble;
00180 }
00181 
00182 //----------------------------------------------------------------------------//
00183 
00184 template<>
00185 inline DataTypeEnum DataTypeTraits<V3h>::typeEnum()
00186 {
00187   return DataTypeVecHalf;
00188 }
00189 
00190 //----------------------------------------------------------------------------//
00191 
00192 template<>
00193 inline DataTypeEnum DataTypeTraits<V3f>::typeEnum()
00194 {
00195   return DataTypeVecFloat;
00196 }
00197 
00198 //----------------------------------------------------------------------------//
00199 
00200 template<>
00201 inline DataTypeEnum DataTypeTraits<V3d>::typeEnum()
00202 {
00203   return DataTypeVecDouble;
00204 }
00205 
00206 template <>
00207 inline hid_t DataTypeTraits<half>::h5type()
00208 {
00209   return H5T_NATIVE_SHORT;
00210 }
00211 
00212 //----------------------------------------------------------------------------//
00213 
00214 template <>
00215 inline hid_t DataTypeTraits<float>::h5type()
00216 {
00217   return H5T_NATIVE_FLOAT;
00218 }
00219 
00220 //----------------------------------------------------------------------------//
00221 
00222 template <>
00223 inline hid_t DataTypeTraits<double>::h5type()
00224 {
00225   return H5T_NATIVE_DOUBLE;
00226 }
00227 
00228 //----------------------------------------------------------------------------//
00229 
00230 template <>
00231 inline hid_t DataTypeTraits<char>::h5type()
00232 {
00233   return H5T_NATIVE_CHAR;
00234 }
00235 
00236 //----------------------------------------------------------------------------//
00237 
00238 template <>
00239 inline hid_t DataTypeTraits<V3h>::h5type()
00240 {
00241   return H5T_NATIVE_SHORT;
00242 }
00243 
00244 //----------------------------------------------------------------------------//
00245 
00246 template <>
00247 inline hid_t DataTypeTraits<V3f>::h5type()
00248 {
00249   return H5T_NATIVE_FLOAT;
00250 }
00251 
00252 //----------------------------------------------------------------------------//
00253 
00254 template <>
00255 inline hid_t DataTypeTraits<V3d>::h5type()
00256 {
00257   return H5T_NATIVE_DOUBLE;
00258 }
00259 
00260 //----------------------------------------------------------------------------//
00261 
00262 template <>
00263 inline int DataTypeTraits<half>::h5bits() 
00264 { 
00265   return 16; 
00266 }
00267 
00268 //----------------------------------------------------------------------------//
00269 
00270 template <>
00271 inline int DataTypeTraits<float>::h5bits() 
00272 { 
00273   return 32; 
00274 }
00275 
00276 //----------------------------------------------------------------------------//
00277 
00278 template <>
00279 inline int DataTypeTraits<double>::h5bits() 
00280 { 
00281   return 64; 
00282 }
00283 
00284 //----------------------------------------------------------------------------//
00285 
00286 template <>
00287 inline int DataTypeTraits<V3h>::h5bits() 
00288 { 
00289   return 16; 
00290 }
00291 
00292 //----------------------------------------------------------------------------//
00293 
00294 template <>
00295 inline int DataTypeTraits<V3f>::h5bits() 
00296 { 
00297   return 32; 
00298 }
00299 
00300 //----------------------------------------------------------------------------//
00301 
00302 template <>
00303 inline int DataTypeTraits<V3d>::h5bits() 
00304 { 
00305   return 64; 
00306 }
00307 
00308 //----------------------------------------------------------------------------//
00309 
00310 FIELD3D_NAMESPACE_HEADER_CLOSE
00311 
00312 //----------------------------------------------------------------------------//
00313 
00314 #endif // Include guard