Hdf_common.hpp

00001 /* Hdf_common.hpp */
00002 
00003 #ifndef HDF_COMMON_HPP
00004 #define HDF_COMMON_HPP
00005 
00006 #include <string>
00007 #include <sstream> /* for to_string */
00008 #include "mfhdf.h"
00009 #include <typeinfo>
00010 
00011 namespace Hdf_common {
00012   const char *hdf_access_mode(const int32 mode);
00013   std::string hdf_type_info(const int32 data_type);
00014   const int32 hdf_int32_type(const char* data_type);
00015   const char *hdf_cstr_type(const int32 data_type); // static buffer inside
00016   template<class Hdf_Type>
00017   const char *hdf_cstr_type(); // static buffer inside
00018   size_t hdf_sizeof(const int32 data_type);
00019   size_t hdf_sizeof(const char* data_type);
00020   const char *hdf_format_string(const int32 data_type); // static buffer inside
00021   template<typename num_type>
00022   std::string to_string(const num_type &i);
00023 }
00024 template<class Hdf_Type>
00025 const char *hdf_cstr_type() {
00026   static char cstr_type[10];
00027   if (typeid(Hdf_Type)==typeid(uchar8))
00028     strcpy(cstr_type, "uchar8");
00029   else if (typeid(Hdf_Type)==typeid(char8))
00030     strcpy(cstr_type, "char8");
00031   else if (typeid(Hdf_Type)==typeid(uint8))
00032     strcpy(cstr_type, "uint8");
00033   else if (typeid(Hdf_Type)==typeid(int8))
00034     strcpy(cstr_type, "int8");
00035   else if (typeid(Hdf_Type)==typeid(uint16))
00036     strcpy(cstr_type, "uint16");
00037   else if (typeid(Hdf_Type)==typeid(int16))
00038     strcpy(cstr_type, "int16");
00039   else if (typeid(Hdf_Type)==typeid(uint32))
00040     strcpy(cstr_type, "uint32");
00041   else if (typeid(Hdf_Type)==typeid(int32))
00042     strcpy(cstr_type, "int32");
00043   else if (typeid(Hdf_Type)==typeid(float32))
00044     strcpy(cstr_type, "float32");
00045   else if (typeid(Hdf_Type)==typeid(float64))
00046     strcpy(cstr_type, "float64");
00047   else 
00048     strcpy(cstr_type, "unknown");
00049   return cstr_type; 
00050 };
00051 template <typename num_type>
00052 std::string Hdf_common::to_string(const num_type &i) {
00053     std::ostringstream oss;
00054     oss << i;
00055     return oss.str();
00056 };
00060 typedef enum{
00061   HDF_UNKNOWN,
00062   HDF_FILE,
00063   SDS,
00064   VDATA,
00065   VDATA_FIELD,
00066 } attribute_parent;
00067 #endif