select_by_id_dataset_cpp11.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c), 2017, Adrien Devresse
3  *
4  * Distributed under the Boost Software License, Version 1.0.
5  * (See accompanying file LICENSE_1_0.txt or copy at
6  * http://www.boost.org/LICENSE_1_0.txt)
7  *
8  */
9 #include <functional>
10 #include <iostream>
11 #include <string>
12 #include <vector>
13 
14 #include <highfive/H5File.hpp>
15 #include <highfive/H5DataSet.hpp>
16 #include <highfive/H5DataSpace.hpp>
17 
18 const std::string FILE_NAME("select_partial_string.h5");
19 const std::string DATASET_NAME("message");
20 
21 // Create a dataset name "dset" of double 4x6
22 //
23 int main(void) {
24  using namespace HighFive;
25  try {
26  // Create a new file using the default property lists.
28 
29  {
30  // We have a set of string
31  std::vector<std::string> values = {
32  "Cat", "Dog", "Hello", "Tree", "World", "Plane",
33  ", ", "你好", "Tea", "Moon", "صباح جميل", "Spaceship",
34  };
35 
36  // let's create a dataset
37  DataSet dataset = file.createDataSet<std::string>(
38  DATASET_NAME, DataSpace::From(values));
39 
40  // and write them
41  dataset.write(values);
42  }
43 
44  {
45  DataSet dataset = file.getDataSet(DATASET_NAME);
46 
47  // now let's read back by cherry pick our interesting string
48  std::vector<std::string> result;
49  // we select only element N° 2 and 5
50  dataset.select(ElementSet({2, 4, 6, 7, 6, 10})).read(result);
51 
52  // and display it
53  for (auto i : result) {
54  std::cout << i << " ";
55  }
56  std::cout << "\n";
57  }
58 
59  } catch (Exception& err) {
60  // catch and print any HDF5 error
61  std::cerr << err.what() << std::endl;
62  }
63 
64  return 0; // successfully terminated
65 }
const std::string DATASET_NAME("message")
void read(T &array) const
static DataSpace From(const ScalarValue &scalar_value)
int main(void)
const std::string FILE_NAME("select_partial_string.h5")
void write(const T &buffer)
static const int ReadWrite
Open flag: Read Write access.
Definition: H5File.hpp:32
static const int Truncate
Open flag: Truncate a file if already existing.
Definition: H5File.hpp:34
File class.
Definition: H5File.hpp:25
DataSet getDataSet(const std::string &dataset_name, const DataSetAccessProps &accessProps=DataSetAccessProps()) const
get an existing dataset in the current file
const char * what() const override
get the current exception error message
Definition: H5Exception.hpp:34
FILE * file
Selection select(const std::vector< size_t > &offset, const std::vector< size_t > &count, const std::vector< size_t > &stride=std::vector< size_t >()) const
Basic HighFive Exception class.
Definition: H5Exception.hpp:23
DataSet createDataSet(const std::string &dataset_name, const DataSpace &space, const DataType &type, const DataSetCreateProps &createProps=DataSetCreateProps(), const DataSetAccessProps &accessProps=DataSetAccessProps())
createDataSet Create a new dataset in the current file of datatype type and of size space ...
static const int Create
Open flag: Create non existing file.
Definition: H5File.hpp:40


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:09