h5cpp 0.7.1
A modern C++ wrapper for the HDF5 C library
factory.hpp
Go to the documentation of this file.
1//
2// (c) Copyright 2017 DESY,ESS
3//
4// This file is part of h5cpp.
5//
6// This library is free software; you can redistribute it and/or modify it
7// under the terms of the GNU Lesser General Public License as published
8// by the Free Software Foundation; either version 2.1 of the License, or
9// (at your option) any later version.
10//
11// This library is distributed in the hope that it will be useful, but
12// WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY
13// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14// License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public License
17// along with this library; if not, write to the
18// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor
19// Boston, MA 02110-1301 USA
20// ===========================================================================
21//
22// Authors:
23// Eugen Wintersberger <eugen.wintersberger@desy.de>
24// Martin Shetty <martin.shetty@esss.se>
25// Jan Kotanski <jan.kotanski@desy.de>
26// Created on: Aug 28, 2017
27//
28#pragma once
29
31
32namespace hdf5 {
33namespace datatype {
34
38template<typename T>
39typename TypeTrait<typename std::remove_const<T>::type>::TypeClass create(const T &v = T{}) {
40 return TypeTrait<typename std::remove_const<T>::type>::create(v);
41}
45template<typename T>
46const Datatype & get(const T &v = T{}) {
47 return TypeTrait<typename std::remove_const<T>::type>::get(v);
48}
49
54{
55 public:
56
66 template<typename T>
67 const Datatype & get(const T & v = T{});
68
69 private:
70 Datatype instance;
71};
72
73template<typename T>
74const Datatype & DatatypeHolder::get(const T & v)
75{
76 auto & type = hdf5::datatype::get(v);
77 if(static_cast<hid_t>(type))
78 return type;
79
80 if (!static_cast<hid_t>(instance))
81 instance = hdf5::datatype::create(v);
82 return instance;
83}
84
85} // namespace datatype
86} // namespace hdf5
data type object holder
Definition: factory.hpp:54
const Datatype & get(const T &v=T{})
factory holder method for getting reference of data types
Definition: factory.hpp:74
base class for all data types
Definition: datatype.hpp:42
trait to create HDF5 datatypes
Definition: type_trait.hpp:53
const Datatype & get(const T &v=T{})
factory function for getting reference of data types
Definition: factory.hpp:46
TypeTrait< typenamestd::remove_const< T >::type >::TypeClass create(const T &v=T{})
factory function for creating data types
Definition: factory.hpp:39
top-level namespace of the entire library
Definition: attribute.hpp:45
#define DLL_EXPORT
Definition: windows.hpp:29