-
Notifications
You must be signed in to change notification settings - Fork 161
/
create_attribute_string_integer.cpp
54 lines (42 loc) · 1.58 KB
/
create_attribute_string_integer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* Copyright (c), 2017, Adrien Devresse
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
*/
#include <iostream>
#include <string>
#include <vector>
#include <highfive/highfive.hpp>
using namespace HighFive;
// create a dataset from a vector of string
// read it back and print it
int main(void) {
// Create a new file using the default property lists.
File file("create_attribute.h5", File::Truncate);
// Create a dummy dataset of one single integer
DataSet dataset = file.createDataSet("dset", DataSpace(1), create_datatype<int>());
// Now let's add a attribute on this dataset
// This attribute will be named "note"
// and have the following content
std::string note = "Very important Dataset!";
// Write in one line of code:
dataset.createAttribute<std::string>("note", note);
// We also add a "version" attribute
// that will be an array 1x2 of integer
std::vector<int> version{1, 0};
Attribute v = dataset.createAttribute("version", version);
// We can also create attributes on the file:
file.createAttribute("file_version", 1);
// and on groups in the file:
auto group = file.createGroup("group");
group.createAttribute("secret", 123);
// let's now list the keys of all attributes
std::vector<std::string> all_attributes_keys = dataset.listAttributeNames();
for (const auto& attr: all_attributes_keys) {
std::cout << "attribute: " << attr << std::endl;
}
return 0;
}