Skip to content

Commit

Permalink
Issue 548 (#566)
Browse files Browse the repository at this point in the history
* moved STL datatype traits to contrib/stl

Update #548

* Removed unused header files

Update #548

* attribute tests are back

Update #548

* node tests are back

update #548

* file and utility tests are back

Update #548

* datatype test is back

Update #548

* dataspace test ist back

Update #548

* moved dataspaces for STL containers to contrib

Update #548

* removed ebool code from the mainline

Update #548

* Added test build for the nexus contrib

Update #548

* Fixing ebool tests

Update #548

* add include statments

* downgrade conan version

* revert conanfile_ess.txt

* fix typo

* add CONAN_FILE for macos

* move include statement to dataset.cpp

* add back stl/string.hpp to dataset.hpp

* add newline at the end of files

* comment bzip2 from macos conanfile

* since @amues remove

* comment windows test

Co-authored-by: Jan Kotanski <[email protected]>
  • Loading branch information
eugenwintersberger and jkotan authored Jan 19, 2022
1 parent 5a4f3e7 commit d014984
Show file tree
Hide file tree
Showing 55 changed files with 588 additions and 327 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ elseif(NOT ${CONAN} MATCHES "DISABLE")
message(FATAL_ERROR "Unrecognised option for CONAN (${CONAN}), use AUTO, MANUAL or DISABLE")
endif()

#=============================================================================
# contrib extensions
#=============================================================================
set(H5CPP_ENABLE_NEXUS "true" CACHE BOOL "enable support or Nexus types")
set(H5CPP_ENABLE_STL "true" CACHE BOOL "enable STL support for H5CPP")

#=============================================================================
# General configuration
#=============================================================================
Expand Down
1 change: 1 addition & 0 deletions src/h5cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ install(FILES ${HEADERS}

set(h5cpp_headers ${HEADERS})
set(h5cpp_sources )
add_subdirectory(contrib)
add_subdirectory(core)
add_subdirectory(attribute)
add_subdirectory(dataspace)
Expand Down
1 change: 1 addition & 0 deletions src/h5cpp/attribute/attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <h5cpp/attribute/attribute.hpp>
#include <h5cpp/core/utilities.hpp>
#include <h5cpp/node/link.hpp>
#include <h5cpp/contrib/stl/string.hpp>

namespace hdf5 {
namespace attribute {
Expand Down
1 change: 1 addition & 0 deletions src/h5cpp/attribute/attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <h5cpp/error/error.hpp>
#include <initializer_list>
#include <h5cpp/core/utilities.hpp>
#include <h5cpp/contrib/stl/vector.hpp>

namespace hdf5 {
namespace attribute {
Expand Down
13 changes: 13 additions & 0 deletions src/h5cpp/contrib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set(CONTRIB_SOURCES)
set(CONTRIB_HEADERS)

if(H5CPP_ENABLE_STL)
add_subdirectory(stl)
endif()

if(H5CPP_ENABLE_NEXUS)
add_subdirectory(nexus)
endif()

set(h5cpp_sources ${h5cpp_sources} ${CONTRIB_SOURCES} PARENT_SCOPE)
set(h5cpp_headers ${h5cpp_headers} ${CONTRIB_HEADERS} PARENT_SCOPE)
8 changes: 8 additions & 0 deletions src/h5cpp/contrib/nexus/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ebool.cpp)
set(HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/ebool.hpp)

install(FILES ${HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/h5cpp/contrib/nexus)

set(CONTRIB_SOURCES ${CONTRIB_SOURCES} ${SOURCES} PARENT_SCOPE)
set(CONTRIB_HEADERS ${CONTROB_HEADERS} ${HEADERS} PARENT_SCOPE)
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include <sstream>
#include <h5cpp/datatype/enum.hpp>
#include <h5cpp/datatype/ebool.hpp>
#include <h5cpp/contrib/nexus/ebool.hpp>
#include <h5cpp/error/error.hpp>

namespace hdf5
Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions src/h5cpp/contrib/stl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/array.hpp
${CMAKE_CURRENT_SOURCE_DIR}/complex.hpp
${CMAKE_CURRENT_SOURCE_DIR}/stl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/string.hpp
${CMAKE_CURRENT_SOURCE_DIR}/vector.hpp)

install(FILES ${HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/h5cpp/contrib/stl)

set(h5cpp_headers ${h5cpp_headers} ${HEADERS} PARENT_SCOPE)
52 changes: 52 additions & 0 deletions src/h5cpp/contrib/stl/array.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma once

#include <h5cpp/datatype/type_trait.hpp>
#include <h5cpp/dataspace/type_trait.hpp>
#include <h5cpp/dataspace/simple.hpp>
#include <array>

namespace hdf5 {
namespace datatype {

template<typename T, size_t N>
class TypeTrait<std::array<T, N>> {
public:
using Type = std::array<T, N>;
using TypeClass = typename TypeTrait<T>::TypeClass;
static TypeClass create(const Type & = Type()) {
return TypeTrait<typename std::remove_const<T>::type>::create();
}
const static TypeClass & get(const Type & = Type()) {
const static TypeClass & cref_ = TypeTrait<typename std::remove_const<T>::type>::create();
return cref_;
}
};
} // end of namespace datatype

namespace dataspace {

template<typename T, size_t N>
class TypeTrait<std::array<T, N>> {
public:
using DataspaceType = Simple;

static DataspaceType create(const std::array<T, N> &) {
return Simple(hdf5::Dimensions{N}, hdf5::Dimensions{N});
}

const static DataspaceType & get(const std::array<T, N> &, DataspacePool &) {
const static DataspaceType & cref_ = Simple(hdf5::Dimensions{N}, hdf5::Dimensions{N});
return cref_;
}

static void *ptr(std::array<T, N> &value) {
return reinterpret_cast<void *>(value.data());
}

static const void *cptr(const std::array<T, N> &value) {
return reinterpret_cast<const void *>(value.data());
}
};

} // end of namespace dataspace
} // end of namespace hdf5
60 changes: 60 additions & 0 deletions src/h5cpp/contrib/stl/complex.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// (c) Copyright 2021 DESY, ESS
// 2021 Eugen Wintersberger <[email protected]>
//
// This file is part of h5cpp.
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
// License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the
// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor
// Boston, MA 02110-1301 USA
// ===========================================================================
//
// Authors: Eugen Wintersberger <[email protected]>
// Created on: Dec 23, 2021
//
#pragma once

#include <h5cpp/datatype/type_trait.hpp>
#include <complex>

namespace hdf5 {
namespace datatype {

template<typename T>
class TypeTrait<std::complex<T>>
{
private:
using element_type = TypeTrait<T>;

public:
using Type = std::complex<T>;
using TypeClass = Compound;

static TypeClass create(const Type & = Type())
{
datatype::Compound type = datatype::Compound::create(
sizeof(std::complex<T>));

type.insert("real", 0, element_type::create(T()));
type.insert("imag", alignof(T), element_type::create(T()));

return type;
}
const static TypeClass & get(const Type & = Type()) {
const static TypeClass & cref_ = create();
return cref_;
}
};
}
}
32 changes: 32 additions & 0 deletions src/h5cpp/contrib/stl/stl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// (c) Copyright 2017 DESY,ESS
//
// This file is part of h5cpp.
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
// License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the
// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor
// Boston, MA 02110-1301 USA
// ===========================================================================
//
// Authors: Eugen Wintersberger <[email protected]>
// Sebastian Koenig <[email protected]>
// Jan Kotanski <[email protected]>
// Created on: Aug 28, 2017
//
#pragma once

#include <h5cpp/contrib/stl/array.hpp>
#include <h5cpp/contrib/stl/string.hpp>
#include <h5cpp/contrib/stl/vector.hpp>
#include <h5cpp/contrib/stl/complex.hpp>
52 changes: 52 additions & 0 deletions src/h5cpp/contrib/stl/string.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma once

#include <h5cpp/datatype/type_trait.hpp>
#include <h5cpp/datatype/string.hpp>
#include <string>

namespace hdf5 {
namespace datatype {

template<>
class TypeTrait<std::string> {
public:
using Type = std::string;
using TypeClass = String;
static TypeClass create(const Type & = Type()) {
return datatype::String::variable();
}
const static TypeClass & get(const Type & = Type()) {
const static TypeClass & cref_ = create();
return cref_;
}
};


template<typename CharT>
class TypeTrait<std::basic_string<CharT>> {
private:

public:
using Type = std::basic_string<CharT>;
using TypeClass = String;

static TypeClass create(const Type & = Type()) {
static_assert(std::is_same<CharT, char>::value, "Only support 8Bit characters");

String type = String::variable();
type.encoding(CharacterEncoding::UTF8);
return type;

}
const static TypeClass & get(const Type & = Type()) {
const static TypeClass & cref_ = create();
return cref_;
}

};
} // end of namespace datatype

namespace dataspace {

} // end of namespace dataspace
} // end of namespace hdf5
50 changes: 50 additions & 0 deletions src/h5cpp/contrib/stl/vector.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#pragma once

#include <vector>
#include <h5cpp/datatype/type_trait.hpp>

namespace hdf5 {
namespace datatype {

template<typename T>
class TypeTrait<std::vector<T>> {
public:
using Type = std::vector<T>;
using TypeClass = typename TypeTrait<T>::TypeClass;
static TypeClass create(const Type & = Type()) {
return TypeTrait<typename std::remove_const<T>::type>::create();
}
const static TypeClass & get(const Type & = Type()) {
const static TypeClass & cref_ = create();
return cref_;
}
};

} // end of namespace datatype

namespace dataspace {

template<typename T>
class TypeTrait<std::vector<T>> {
public:
using DataspaceType = Simple;

static Simple create(const std::vector<T> &value) {
return Simple(hdf5::Dimensions{value.size()}, hdf5::Dimensions{value.size()});
}

static const Dataspace & get(const std::vector<T> & value, DataspacePool & pool) {
return pool.getSimple(value.size());
}

static void *ptr(std::vector<T> &data) {
return reinterpret_cast<void *>(data.data());
}

static const void *cptr(const std::vector<T> &data) {
return reinterpret_cast<const void *>(data.data());
}
};

} // end of namespace dataspace
} // end of namespace hdf5
4 changes: 0 additions & 4 deletions src/h5cpp/core/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@

#include <h5cpp/core/hdf5_capi.hpp>
#include <vector>
#include <sstream>
#include <cstring>
#include <algorithm>
#include <iterator>

namespace hdf5 {

Expand Down
2 changes: 1 addition & 1 deletion src/h5cpp/core/variable_length_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
#pragma once

#include <vector>
#include <string>
#include <algorithm>
#include <cstring>

namespace hdf5 {

Expand Down
1 change: 1 addition & 0 deletions src/h5cpp/dataspace/hyperslab.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <h5cpp/core/windows.hpp>
#include <memory>
#include <list>
#include <sstream>

namespace hdf5 {
namespace dataspace {
Expand Down
Loading

0 comments on commit d014984

Please sign in to comment.