Skip to content

Commit

Permalink
Updated compound example to use string
Browse files Browse the repository at this point in the history
Update #318
  • Loading branch information
eugenwintersberger committed Jan 13, 2019
1 parent 9803272 commit 949e0f6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
8 changes: 5 additions & 3 deletions examples/hdfgroup/H5T/measurement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@

#include "measurement.hpp"

Measurement::Measurement (int serial_no, const char *location,
Measurement::Measurement (int serial_no, const std::string &location,
double temperature, double pressure) :
serial_no_ (serial_no), location_ (const_cast<char*>(location)), temperature_ (temperature), pressure_ (
pressure)
serial_no_ (serial_no),
location_ (location),
temperature_ (temperature),
pressure_ ( pressure)
{
}

Expand Down
4 changes: 2 additions & 2 deletions examples/hdfgroup/H5T/measurement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class Measurement
{
private:
int serial_no_;
char* location_;
std::string location_;
double temperature_;
double pressure_;
public:
Measurement() = default;
Measurement(int serial_no,const char *location,double temperature,double pressure);
Measurement(int serial_no,const std::string &location,double temperature,double pressure);

int serial_no() const noexcept;
std::string location() const;
Expand Down
47 changes: 26 additions & 21 deletions examples/hdfgroup/H5T/measurement_hdf5.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,35 @@ namespace datatype {


template<>
class TypeTrait<Measurement>
{
class TypeTrait<Measurement>
{
private:
struct buffer_struct
{
int serial_no_;
char* location_;
double temperature_;
double pressure_;
};
public:
using Type = Measurement;
using TypeClass = Compound;
struct buffer_struct
{
int serial_no_;
std::string location_;
double temperature_;
double pressure_;
};
public:
using Type = Measurement;
using TypeClass = Compound;

static TypeClass create(const Type& = Type())
{
Compound type = Compound::create(sizeof(buffer_struct));
type.insert("serial_no",HOFFSET(buffer_struct,serial_no_),datatype::create<int>());
type.insert("location",HOFFSET(buffer_struct,location_),datatype::create<std::string>());
type.insert("temperature",HOFFSET(buffer_struct,temperature_),datatype::create<double>());
type.insert("pressure",HOFFSET(buffer_struct,pressure_),datatype::create<double>());
static TypeClass
create (const Type& = Type ())
{
Compound type = Compound::create (sizeof(buffer_struct));
type.insert ("serial_no", HOFFSET(buffer_struct, serial_no_),
datatype::create<int> ());
type.insert ("location", HOFFSET(buffer_struct, location_),
datatype::create<std::string> ());
type.insert ("temperature", HOFFSET(buffer_struct, temperature_),
datatype::create<double> ());
type.insert ("pressure", HOFFSET(buffer_struct, pressure_),
datatype::create<double> ());

return type;
}
return type;
}
};

} // end of namespace datatype
Expand Down

0 comments on commit 949e0f6

Please sign in to comment.