From 1bd685e9c5ebbe8487b566d311d62cd66fffc4a7 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Wed, 21 Aug 2019 11:19:03 +0300 Subject: [PATCH] Add more support for strings --- src/hdf5_array.hpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/hdf5_array.hpp b/src/hdf5_array.hpp index 711c0bc..11762bb 100644 --- a/src/hdf5_array.hpp +++ b/src/hdf5_array.hpp @@ -263,6 +263,35 @@ namespace CosmoTool { } }; + struct CosmoString { + char const * s; + operator char const *() { return s; } + char const *operator=(char const *s0) { + s = s0; + return s0; + } + }; + + class hdf5_CosmoStringType { + public: + H5::StrType type; + + hdf5_CosmoStringType() : type(H5::PredType::C_S1, H5T_VARIABLE) { + } + + static const hdf5_CosmoStringType *ctype() + { + static hdf5_CosmoStringType singleton; + return &singleton; + } + }; + + template<> struct get_hdf5_data_type { + static H5::DataType type() { + return hdf5_CosmoStringType::ctype()->type; + } + }; + template void hdf5_write_array(H5_CommonFileGroup& fg, const std::string& data_set_name, const ArrayType& data ) {