Skip to content

Commit eaaf8e6

Browse files
authored
Merge pull request #259 from Flamefire/colType
Keep info on H5 datatypes in collection types
2 parents fe395eb + daf41a8 commit eaaf8e6

4 files changed

Lines changed: 43 additions & 21 deletions

File tree

src/include/splash/CollectionType.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,12 @@ namespace splash
7070
*/
7171
virtual ~CollectionType()
7272
{
73-
};
73+
}
7474
protected:
75+
explicit CollectionType(H5DataType inType = -1): type(inType)
76+
{
77+
}
78+
7579
H5DataType type;
7680
};
7781

src/include/splash/basetypes/ColTypeDim.hpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ namespace splash
4040

4141
ColTypeDim()
4242
{
43-
this->type = H5Tcreate(H5T_COMPOUND, Dimensions::getSize());
43+
this->type = H5Tcreate(H5T_COMPOUND, getSize());
4444
H5Tinsert(this->type, "x", 0, H5T_NATIVE_HSIZE);
45-
H5Tinsert(this->type, "y", sizeof (hsize_t), H5T_NATIVE_HSIZE);
46-
H5Tinsert(this->type, "z", sizeof (hsize_t) * 2, H5T_NATIVE_HSIZE);
45+
H5Tinsert(this->type, "y", sizeof(hsize_t), H5T_NATIVE_HSIZE);
46+
H5Tinsert(this->type, "z", sizeof(hsize_t) * 2, H5T_NATIVE_HSIZE);
4747
}
4848

4949
~ColTypeDim()
@@ -53,7 +53,7 @@ namespace splash
5353

5454
size_t getSize() const
5555
{
56-
return Dimensions::getSize();
56+
return getSize_();
5757
}
5858

5959
std::string toString() const
@@ -69,7 +69,7 @@ namespace splash
6969
{
7070
if(H5Tget_nmembers(datatype_id) == 3)
7171
{
72-
if(H5Tget_size(datatype_id) == Dimensions::getSize())
72+
if(H5Tget_size(datatype_id) == getSize_())
7373
{
7474
char* m0 = H5Tget_member_name(datatype_id, 0);
7575
char* m1 = H5Tget_member_name(datatype_id, 1);
@@ -88,7 +88,14 @@ namespace splash
8888
else
8989
return NULL;
9090
}
91-
};
91+
92+
private:
93+
static size_t getSize_()
94+
{
95+
return sizeof(hsize_t) * 3;
96+
}
97+
98+
};
9299
}
93100

94101
#endif /* COLTYPEDIM_H */

src/include/splash/basetypes/ColTypeDimArray.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#define COLTYPEDIMARRAY_H
2626

2727
#include "splash/CollectionType.hpp"
28-
28+
#include "splash/Dimensions.hpp"
2929
#include <string>
3030

3131
namespace splash

src/include/splash/basetypes/ColTypeString.hpp

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
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

Comments
 (0)