Skip to content

Commit

Permalink
Remove deprecated FixedLenStringArray (#946)
Browse files Browse the repository at this point in the history
  • Loading branch information
alkino authored Feb 9, 2024
1 parent 066c188 commit ece5bae
Show file tree
Hide file tree
Showing 10 changed files with 0 additions and 450 deletions.
127 changes: 0 additions & 127 deletions include/highfive/H5DataType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,133 +340,6 @@ DataType create_datatype();
/// \brief Create a DataType instance representing type T and perform a sanity check on its size
template <typename T>
DataType create_and_check_datatype();


namespace deprecated {
///
/// \brief A structure representing a set of fixed-length strings
///
/// Although fixed-len arrays can be created 'raw' without the need for
/// this structure, to retrieve results efficiently it must be used.
///
/// \tparam N Size of the string in bytes, including the null character. Note,
/// that all string must be null-terminated.
///
template <std::size_t N>
class FixedLenStringArray {
public:
FixedLenStringArray() = default;

///
/// \brief Create a FixedStringArray from a raw contiguous buffer.
///
/// The argument `n_strings` specifies the number of strings.
///
FixedLenStringArray(const char array[][N], std::size_t n_strings);

///
/// \brief Create a FixedStringArray from a sequence of strings.
///
/// Such conversion involves a copy, original vector is not modified
///
explicit FixedLenStringArray(const std::vector<std::string>& vec);

FixedLenStringArray(const std::string* iter_begin, const std::string* iter_end);

FixedLenStringArray(const std::initializer_list<std::string>&);

///
/// \brief Append an std::string to the buffer structure
///
void push_back(const std::string&);

void push_back(const std::array<char, N>&);

///
/// \brief Retrieve a string from the structure as std::string
///
std::string getString(std::size_t index) const;

// Container interface
inline const char* operator[](std::size_t i) const noexcept {
return datavec[i].data();
}
inline const char* at(std::size_t i) const {
return datavec.at(i).data();
}
inline bool empty() const noexcept {
return datavec.empty();
}
inline std::size_t size() const noexcept {
return datavec.size();
}
inline void resize(std::size_t n) {
datavec.resize(n);
}
inline const char* front() const {
return datavec.front().data();
}
inline const char* back() const {
return datavec.back().data();
}
inline char* data() noexcept {
return datavec[0].data();
}
inline const char* data() const noexcept {
return datavec[0].data();
}

private:
using vector_t = typename std::vector<std::array<char, N>>;

public:
// Use the underlying iterator
using iterator = typename vector_t::iterator;
using const_iterator = typename vector_t::const_iterator;
using reverse_iterator = typename vector_t::reverse_iterator;
using const_reverse_iterator = typename vector_t::const_reverse_iterator;
using value_type = typename vector_t::value_type;

inline iterator begin() noexcept {
return datavec.begin();
}
inline iterator end() noexcept {
return datavec.end();
}
inline const_iterator begin() const noexcept {
return datavec.begin();
}
inline const_iterator cbegin() const noexcept {
return datavec.cbegin();
}
inline const_iterator end() const noexcept {
return datavec.end();
}
inline const_iterator cend() const noexcept {
return datavec.cend();
}
inline reverse_iterator rbegin() noexcept {
return datavec.rbegin();
}
inline reverse_iterator rend() noexcept {
return datavec.rend();
}
inline const_reverse_iterator rbegin() const noexcept {
return datavec.rbegin();
}
inline const_reverse_iterator rend() const noexcept {
return datavec.rend();
}

private:
vector_t datavec;
};
} // namespace deprecated

template <size_t N>
using FixedLenStringArray H5_DEPRECATED_USING("Use 'std::vector<std::string>'.") =
deprecated::FixedLenStringArray<N>;

} // namespace HighFive


Expand Down
52 changes: 0 additions & 52 deletions include/highfive/bits/H5DataType_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,6 @@ class AtomicType<char[StrLen]>: public DataType {
: DataType(create_string(StrLen)) {}
};

template <size_t StrLen>
class AtomicType<deprecated::FixedLenStringArray<StrLen>>: public DataType {
public:
inline AtomicType()
: DataType(create_string(StrLen)) {}
};

template <typename T>
class AtomicType<std::complex<T>>: public DataType {
public:
Expand All @@ -239,51 +232,6 @@ AtomicType<T>::AtomicType() {
}


namespace deprecated {
template <std::size_t N>
inline FixedLenStringArray<N>::FixedLenStringArray(const char array[][N], std::size_t length) {
datavec.resize(length);
std::memcpy(datavec[0].data(), array[0].data(), N * length);
}

template <std::size_t N>
inline FixedLenStringArray<N>::FixedLenStringArray(const std::string* iter_begin,
const std::string* iter_end) {
datavec.reserve(static_cast<std::size_t>(iter_end - iter_begin));
for (std::string const* it = iter_begin; it != iter_end; ++it) {
push_back(*it);
}
}

template <std::size_t N>
inline FixedLenStringArray<N>::FixedLenStringArray(const std::vector<std::string>& vec)
: FixedLenStringArray(vec.data(), vec.data() + vec.size()) {}

template <std::size_t N>
inline FixedLenStringArray<N>::FixedLenStringArray(
const std::initializer_list<std::string>& init_list)
: FixedLenStringArray(init_list.begin(), init_list.end()) {}

template <std::size_t N>
inline void FixedLenStringArray<N>::push_back(const std::string& src) {
datavec.emplace_back();
const size_t length = std::min(N - 1, src.length());
std::memcpy(datavec.back().data(), src.c_str(), length);
datavec.back()[length] = 0;
}

template <std::size_t N>
inline void FixedLenStringArray<N>::push_back(const std::array<char, N>& src) {
datavec.emplace_back();
std::copy(src.begin(), src.end(), datavec.back().data());
}

template <std::size_t N>
inline std::string FixedLenStringArray<N>::getString(std::size_t i) const {
return std::string(datavec[i].data());
}
} // namespace deprecated

// Internal
// Reference mapping
template <>
Expand Down
55 changes: 0 additions & 55 deletions include/highfive/bits/H5Inspector_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,61 +289,6 @@ struct inspector<Reference>: type_helper<Reference> {
}
};

template <size_t N>
struct inspector<deprecated::FixedLenStringArray<N>> {
using type = deprecated::FixedLenStringArray<N>;
using value_type = char*;
using base_type = deprecated::FixedLenStringArray<N>;
using hdf5_type = char;

static constexpr size_t ndim = 1;
static constexpr size_t recursive_ndim = ndim;
static constexpr bool is_trivially_copyable = false;

static std::vector<size_t> getDimensions(const type& val) {
return std::vector<size_t>{val.size()};
}

static size_t getSizeVal(const type& val) {
return N * compute_total_size(getDimensions(val));
}

static size_t getSize(const std::vector<size_t>& dims) {
return N * compute_total_size(dims);
}

static void prepare(type& /* val */, const std::vector<size_t>& dims) {
if (dims[0] > N) {
std::ostringstream os;
os << "Size of FixedlenStringArray (" << N << ") is too small for dims (" << dims[0]
<< ").";
throw DataSpaceException(os.str());
}
}

static hdf5_type* data(type& val) {
return val.data();
}

static const hdf5_type* data(const type& val) {
return val.data();
}

static void serialize(const type& val, hdf5_type* m) {
for (size_t i = 0; i < val.size(); ++i) {
std::memcpy(m + i * N, val[i], N);
}
}

static void unserialize(const hdf5_type* vec, const std::vector<size_t>& dims, type& val) {
for (size_t i = 0; i < dims[0]; ++i) {
std::array<char, N> s;
std::memcpy(s.data(), vec + (i * N), N);
val.push_back(s);
}
}
};

template <typename T>
struct inspector<std::vector<T>> {
using type = std::vector<T>;
Expand Down
8 changes: 0 additions & 8 deletions include/highfive/bits/H5Node_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,6 @@ class NodeTraits {
bool parents = true);


template <std::size_t N>
H5_DEPRECATED("Use 'std::vector<std::string>'.")
DataSet createDataSet(const std::string& dataset_name,
const deprecated::FixedLenStringArray<N>& data,
const DataSetCreateProps& createProps = DataSetCreateProps::Default(),
const DataSetAccessProps& accessProps = DataSetAccessProps::Default(),
bool parents = true);

///
/// \brief get an existing dataset in the current file
/// \param dataset_name
Expand Down
13 changes: 0 additions & 13 deletions include/highfive/bits/H5Node_traits_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,6 @@ inline DataSet NodeTraits<Derivate>::createDataSet(const std::string& dataset_na
return ds;
}

template <typename Derivate>
template <std::size_t N>
inline DataSet NodeTraits<Derivate>::createDataSet(const std::string& dataset_name,
const deprecated::FixedLenStringArray<N>& data,
const DataSetCreateProps& createProps,
const DataSetAccessProps& accessProps,
bool parents) {
DataSet ds = createDataSet<char[N]>(
dataset_name, DataSpace(data.size()), createProps, accessProps, parents);
ds.write(data);
return ds;
}

template <typename Derivate>
inline DataSet NodeTraits<Derivate>::getDataSet(const std::string& dataset_name,
const DataSetAccessProps& accessProps) const {
Expand Down
6 changes: 0 additions & 6 deletions include/highfive/bits/H5Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@

namespace HighFive {

namespace deprecated {
// If ever used, recognize dimensions of FixedLenStringArray
template <std::size_t N>
class FixedLenStringArray;
} // namespace deprecated

namespace details {
// converter function for hsize_t -> size_t when hsize_t != size_t
template <typename Size>
Expand Down
5 changes: 0 additions & 5 deletions include/highfive/bits/H5_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ class AtomicType;
template <typename Derivate>
class AnnotateTraits;

namespace deprecated {
template <std::size_t N>
class FixedLenStringArray;
}

template <typename Derivate>
class NodeTraits;

Expand Down
2 changes: 0 additions & 2 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,3 @@ if(HIGHFIVE_TEST_SINGLE_INCLUDES)
target_link_libraries("tests_include_${CLASS_NAME}" HighFive HighFiveWarnings)
endforeach()
endif()

add_subdirectory(deprecated)
10 changes: 0 additions & 10 deletions tests/unit/deprecated/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit ece5bae

Please sign in to comment.