コード例 #1
0
ファイル: attribute.hpp プロジェクト: jb--/h5xx
inline boost::any read_attribute_if_exists(H5::H5Object const& object, std::string const& name)
{
    if (exists_attribute(object, name)) {
        return read_attribute<T>(object, name);
    }
    return boost::any();
}
コード例 #2
0
ファイル: attribute.hpp プロジェクト: jb--/h5xx
inline typename boost::enable_if<boost::mpl::and_<
    is_vector<T>
  , boost::is_same<typename T::value_type, std::string>
>, void>::type
write_attribute(H5::H5Object const& object, std::string const& name, T const& value)
{
    size_t size = value.size();

    // size of longest string
    size_t str_len = 0;
    for (size_t i = 0; i < size; ++i) {
        str_len = std::max(str_len, value[i].size());
    }

    // remove attribute if it exists and re-create with proper String datatype
    // and simple dataspace
    if (exists_attribute(object, name)) {
        object.removeAttr(name);
    }

    hsize_t dim[1] = { size };
    H5::DataSpace ds(1, dim);
    H5::StrType tid(H5::PredType::C_S1, str_len);
    H5::Attribute attr = object.createAttribute(name, tid, ds);

    // copy strings to contiguous buffer
    std::vector<char> buffer(size * str_len);
    for (size_t i = 0; i < size; ++i) {
        value[i].copy(buffer.data() + i * str_len, str_len);
    }

    attr.write(tid, &*buffer.begin());
}
コード例 #3
0
ファイル: utility.hpp プロジェクト: KaiSzuttor/h5xx
inline void delete_attribute(h5xxObject const& object, std::string const& name)
{
    if (exists_attribute(object, name)) {
        if (H5Adelete(object.hid(), name.c_str()) < 0) {
            throw error("deleting attribute \"" + name + "\" from HDF5 object \"" + get_name(object) + "\"");
        }
    }
}
コード例 #4
0
ファイル: widget.cpp プロジェクト: goalizc/takisy
void* widget::attribute(const std::string& name) const
{
    return exists_attribute(name) ? impl_->attributes_[name].data() : nullptr;
}