11/* *
2- * Copyright 2013-2015 Felix Schmitt, Axel Huebl, Carlchristian Eckert
2+ * Copyright 2013-2016 Felix Schmitt, Axel Huebl, Carlchristian Eckert,
3+ * Alexander Grund
34 *
45 * This file is part of libSplash.
56 *
@@ -67,11 +68,13 @@ namespace splash
6768 size_t myElements = H5Tget_size (this ->type );
6869
6970 /* for variable length string the size is first known after reading
70- * the actual data or attribute, so we forward HDF5's behaviour */
71- if ( H5Tis_variable_str ( this -> type ) )
71+ * the actual data or attribute, so we forward HDF5's behavior */
72+ if (isVariableLength () )
7273 return myElements; /* == sizeof(char*) see H5Tget_size description */
73- else
74+ else if ( isNullTerminated () )
7475 return sizeof (char ) * (myElements - 1 ); /* just as strlen() */
76+ else
77+ return sizeof (char ) * myElements;
7578 }
7679
7780 static CollectionType* genType (hid_t datatype_id)
@@ -80,14 +83,7 @@ namespace splash
8083
8184 if (h5_class == H5T_STRING)
8285 {
83- if ( H5Tis_variable_str (datatype_id) )
84- {
85- return new ColTypeString;
86- } else
87- {
88- size_t size = H5Tget_size (datatype_id);
89- return new ColTypeString (size);
90- }
86+ return new ColTypeString (datatype_id, true );
9187 } else
9288 {
9389 return NULL ;
@@ -96,12 +92,27 @@ namespace splash
9692
9793 std::string toString () const
9894 {
99- if ( H5Tis_variable_str ( this -> type ) )
95+ if (isVariableLength () )
10096 return " VLString" ;
10197 else
10298 return " String" ;
10399 }
104100
101+ bool isVariableLength () const
102+ {
103+ return H5Tis_variable_str (this ->type );
104+ }
105+
106+ bool isNullTerminated () const
107+ {
108+ return H5Tget_strpad (type) == H5T_STR_NULLTERM;
109+ }
110+
111+ private:
112+ explicit ColTypeString (H5DataType inType, bool /* dummy*/ ):
113+ CollectionType(H5Tcopy(inType))
114+ {
115+ }
105116 };
106117
107118}
0 commit comments