| 1 | #ifndef NEXUSFILE_HPP |
|---|
| 2 | #define NEXUSFILE_HPP 1 |
|---|
| 3 | |
|---|
| 4 | #include <map> |
|---|
| 5 | #include <string> |
|---|
| 6 | #include <utility> |
|---|
| 7 | #include <vector> |
|---|
| 8 | #include "napi.h" |
|---|
| 9 | |
|---|
| 10 | #ifdef _WIN32 |
|---|
| 11 | |
|---|
| 12 | #ifndef _MSC_VER |
|---|
| 13 | # define NXDLL_EXPORT |
|---|
| 14 | #else |
|---|
| 15 | # if IN_NEXUS_CPP_LIBRARY |
|---|
| 16 | # define NXDLL_EXPORT __declspec(dllexport) |
|---|
| 17 | # else |
|---|
| 18 | # define NXDLL_EXPORT __declspec(dllimport) |
|---|
| 19 | # endif |
|---|
| 20 | #endif /* _MSC_VER */ |
|---|
| 21 | |
|---|
| 22 | #else /* _WIN32 */ |
|---|
| 23 | # define NXDLL_EXPORT |
|---|
| 24 | #endif /* _WIN32 */ |
|---|
| 25 | |
|---|
| 26 | /** |
|---|
| 27 | * \file NeXusFile.hpp Definition of the NeXus C++ API. |
|---|
| 28 | * \defgroup cpp_types C++ Types |
|---|
| 29 | * \defgroup cpp_core C++ Core |
|---|
| 30 | * \ingroup cpp_main |
|---|
| 31 | */ |
|---|
| 32 | |
|---|
| 33 | namespace NeXus { |
|---|
| 34 | /** |
|---|
| 35 | * The primitive types published by this API. |
|---|
| 36 | * \li FLOAT32 float. |
|---|
| 37 | * \li FLOAT64 double |
|---|
| 38 | * \li INT8 int8_t |
|---|
| 39 | * \li UINT8 uint8_t |
|---|
| 40 | * \li INT16 int16_t |
|---|
| 41 | * \li UINT16 uint16_t |
|---|
| 42 | * \li INT32 int32_t |
|---|
| 43 | * \li UINT32 uint32_t |
|---|
| 44 | * \li INT64 int8_t if available on the machine |
|---|
| 45 | * \li UINT64 uint8_t if available on the machine |
|---|
| 46 | * \ingroup cpp_types |
|---|
| 47 | */ |
|---|
| 48 | enum NXnumtype { |
|---|
| 49 | FLOAT32 = NX_FLOAT32, |
|---|
| 50 | FLOAT64 = NX_FLOAT64, |
|---|
| 51 | INT8 = NX_INT8, |
|---|
| 52 | UINT8 = NX_UINT8, |
|---|
| 53 | // BOOLEAN = NX_BOOLEAN, // NX_BOOLEAN is currently broken |
|---|
| 54 | INT16 = NX_INT16, |
|---|
| 55 | UINT16 = NX_UINT16, |
|---|
| 56 | INT32 = NX_INT32, |
|---|
| 57 | UINT32 = NX_UINT32, |
|---|
| 58 | INT64 = NX_INT64, |
|---|
| 59 | UINT64 = NX_UINT64, |
|---|
| 60 | CHAR = NX_CHAR, |
|---|
| 61 | BINARY = NX_BINARY |
|---|
| 62 | }; |
|---|
| 63 | |
|---|
| 64 | /** |
|---|
| 65 | * The available compression types. These are all ignored in xml files. |
|---|
| 66 | * \li NONE no compression |
|---|
| 67 | * \li LZW Lossless Lempel Ziv Welch compression (recommended) |
|---|
| 68 | * \li RLE Run length encoding (only HDF-4) |
|---|
| 69 | * \li HUF Huffmann encoding (only HDF-4) |
|---|
| 70 | * \ingroup cpp_types |
|---|
| 71 | */ |
|---|
| 72 | enum NXcompression { |
|---|
| 73 | CHUNK = NX_CHUNK, |
|---|
| 74 | NONE = NX_COMP_NONE, |
|---|
| 75 | LZW = NX_COMP_LZW, |
|---|
| 76 | RLE = NX_COMP_RLE, |
|---|
| 77 | HUF = NX_COMP_HUF |
|---|
| 78 | }; |
|---|
| 79 | |
|---|
| 80 | /** |
|---|
| 81 | * Type definition for a type-keyed multimap |
|---|
| 82 | */ |
|---|
| 83 | typedef std::multimap<std::string, std::string> TypeMap; |
|---|
| 84 | |
|---|
| 85 | /** |
|---|
| 86 | * This structure holds the type and dimensions of a primative field/array. |
|---|
| 87 | */ |
|---|
| 88 | struct Info{ |
|---|
| 89 | /** The primative type for the field. */ |
|---|
| 90 | NXnumtype type; |
|---|
| 91 | /** The dimensions of the file. */ |
|---|
| 92 | std::vector<int64_t> dims; |
|---|
| 93 | }; |
|---|
| 94 | |
|---|
| 95 | /** Information about an attribute. */ |
|---|
| 96 | struct AttrInfo{ |
|---|
| 97 | /** The primative type for the attribute. */ |
|---|
| 98 | NXnumtype type; |
|---|
| 99 | /** The length of the attribute. */ |
|---|
| 100 | unsigned length; |
|---|
| 101 | /** The name of the attribute. */ |
|---|
| 102 | std::string name; |
|---|
| 103 | }; |
|---|
| 104 | |
|---|
| 105 | /** |
|---|
| 106 | * The Object that allows access to the information in the file. |
|---|
| 107 | * \ingroup cpp_core |
|---|
| 108 | */ |
|---|
| 109 | class NXDLL_EXPORT File |
|---|
| 110 | { |
|---|
| 111 | private: |
|---|
| 112 | /** The handle for the C-API. */ |
|---|
| 113 | NXhandle m_file_id; |
|---|
| 114 | /** should be close handle on exit */ |
|---|
| 115 | bool m_close_handle; |
|---|
| 116 | |
|---|
| 117 | public: |
|---|
| 118 | /** |
|---|
| 119 | * \return A pair of the next entry available in a listing. |
|---|
| 120 | */ |
|---|
| 121 | std::pair<std::string, std::string> getNextEntry(); |
|---|
| 122 | /** |
|---|
| 123 | * \return Information about the next attribute. |
|---|
| 124 | */ |
|---|
| 125 | AttrInfo getNextAttr(); |
|---|
| 126 | |
|---|
| 127 | private: |
|---|
| 128 | /** |
|---|
| 129 | * This is a deprecated function. |
|---|
| 130 | * \param com The compression type. |
|---|
| 131 | */ |
|---|
| 132 | void compress(NXcompression comp); |
|---|
| 133 | |
|---|
| 134 | /** |
|---|
| 135 | * Initialize the pending group search to start again. |
|---|
| 136 | */ |
|---|
| 137 | void initGroupDir(); |
|---|
| 138 | |
|---|
| 139 | /** |
|---|
| 140 | * Initialize the pending attribute search to start again. |
|---|
| 141 | */ |
|---|
| 142 | void initAttrDir(); |
|---|
| 143 | |
|---|
| 144 | /** |
|---|
| 145 | * Function to walk the file tree and fill in the TypeMap. |
|---|
| 146 | * |
|---|
| 147 | * \param path the current path in the file |
|---|
| 148 | * \param class_name the current NX class name |
|---|
| 149 | * \param tmap the typemap being constructed |
|---|
| 150 | */ |
|---|
| 151 | void walkFileForTypeMap(const std::string path, const std::string class_name, TypeMap &tmap); |
|---|
| 152 | |
|---|
| 153 | /** |
|---|
| 154 | * Function to append new path to current one. |
|---|
| 155 | * \param currpath the current path to append to |
|---|
| 156 | * \param subpath the path to append to the current path |
|---|
| 157 | * \return the newly joined path |
|---|
| 158 | */ |
|---|
| 159 | const std::string makeCurrentPath(const std::string currpath, const std::string subpath); |
|---|
| 160 | |
|---|
| 161 | /** |
|---|
| 162 | * Function to consolidate the file opening code for the various constructors |
|---|
| 163 | * \param filename The name of the file to open. |
|---|
| 164 | * \param access How to access the file. |
|---|
| 165 | */ |
|---|
| 166 | void initOpenFile(const std::string& filename, const NXaccess access = NXACC_READ); |
|---|
| 167 | |
|---|
| 168 | public: |
|---|
| 169 | /** |
|---|
| 170 | * Create a new File. |
|---|
| 171 | * |
|---|
| 172 | * \param filename The name of the file to open. |
|---|
| 173 | * \param access How to access the file. |
|---|
| 174 | */ |
|---|
| 175 | File(const std::string& filename, const NXaccess access = NXACC_READ); |
|---|
| 176 | |
|---|
| 177 | /** |
|---|
| 178 | * Create a new File. |
|---|
| 179 | * |
|---|
| 180 | * \param filename The name of the file to open. |
|---|
| 181 | * \param access How to access the file. |
|---|
| 182 | */ |
|---|
| 183 | File(const char *filename, const NXaccess access = NXACC_READ); |
|---|
| 184 | |
|---|
| 185 | /** |
|---|
| 186 | * Use an existing handle returned from NXopen() |
|---|
| 187 | * |
|---|
| 188 | * \param handle Handle to connect to |
|---|
| 189 | * \param close_handle Should the handle be closed on destruction |
|---|
| 190 | */ |
|---|
| 191 | File(NXhandle handle, bool close_handle = false); |
|---|
| 192 | |
|---|
| 193 | /** Destructor. This does close the file. */ |
|---|
| 194 | ~File(); |
|---|
| 195 | |
|---|
| 196 | /** Close the file before the constructor is called. */ |
|---|
| 197 | void close(); |
|---|
| 198 | |
|---|
| 199 | /** Flush the file. */ |
|---|
| 200 | void flush(); |
|---|
| 201 | |
|---|
| 202 | template<typename NumT> |
|---|
| 203 | void malloc(NumT*& data, const Info& info); |
|---|
| 204 | |
|---|
| 205 | template<typename NumT> |
|---|
| 206 | void free(NumT*& data); |
|---|
| 207 | |
|---|
| 208 | /** |
|---|
| 209 | * Create a new group. |
|---|
| 210 | * |
|---|
| 211 | * \param name The name of the group to create (i.e. "entry"). |
|---|
| 212 | * \param class_name The type of group to create (i.e. "NXentry"). |
|---|
| 213 | * \param open_group Whether or not to automatically open the group after |
|---|
| 214 | * creating it. |
|---|
| 215 | */ |
|---|
| 216 | void makeGroup(const std::string& name, const std::string& class_name, |
|---|
| 217 | bool open_group = false); |
|---|
| 218 | |
|---|
| 219 | /** |
|---|
| 220 | * Open an existing group. |
|---|
| 221 | * |
|---|
| 222 | * \param name The name of the group to create (i.e. "entry"). |
|---|
| 223 | * \param class_name The type of group to create (i.e. "NXentry"). |
|---|
| 224 | */ |
|---|
| 225 | void openGroup(const std::string& name, const std::string& class_name); |
|---|
| 226 | |
|---|
| 227 | /** |
|---|
| 228 | * Open the NeXus object with the path specified. |
|---|
| 229 | * |
|---|
| 230 | * \param path A unix like path string to a group or field. The path |
|---|
| 231 | * string is a list of group names and SDS names separated with a slash, |
|---|
| 232 | * '/' (i.e. "/entry/sample/name"). |
|---|
| 233 | */ |
|---|
| 234 | void openPath(const std::string& path); |
|---|
| 235 | |
|---|
| 236 | /** |
|---|
| 237 | * Open the group in which the NeXus object with the specified path exists. |
|---|
| 238 | * |
|---|
| 239 | * \param path A unix like path string to a group or field. The path |
|---|
| 240 | * string is a list of group names and SDS names separated with a slash, |
|---|
| 241 | * '/' (i.e. "/entry/sample/name"). |
|---|
| 242 | */ |
|---|
| 243 | void openGroupPath(const std::string& path); |
|---|
| 244 | /** |
|---|
| 245 | * Get the path into the current file |
|---|
| 246 | * \return A unix like path string pointing to the current |
|---|
| 247 | * position in the file |
|---|
| 248 | */ |
|---|
| 249 | std::string getPath(); |
|---|
| 250 | |
|---|
| 251 | /** |
|---|
| 252 | * Close the currently open group. |
|---|
| 253 | */ |
|---|
| 254 | void closeGroup(); |
|---|
| 255 | |
|---|
| 256 | /** |
|---|
| 257 | * \copydoc NeXus::File::makeData(const std::string&, NXnumtype, |
|---|
| 258 | * const std::vector<int64_t>&, bool); |
|---|
| 259 | */ |
|---|
| 260 | void makeData(const std::string& name, NXnumtype type, |
|---|
| 261 | const std::vector<int>& dims, bool open_data = false); |
|---|
| 262 | |
|---|
| 263 | /** |
|---|
| 264 | * Create a data field with the specified information. |
|---|
| 265 | * |
|---|
| 266 | * \param name The name of the field to create (i.e. "distance"). |
|---|
| 267 | * \param type The primative type of the field (i.e. "NeXus::FLOAT32"). |
|---|
| 268 | * \param dims The dimensions of the field. |
|---|
| 269 | * \param open_data Whether or not to open the data after creating it. |
|---|
| 270 | */ |
|---|
| 271 | void makeData(const std::string& name, NXnumtype type, |
|---|
| 272 | const std::vector<int64_t>& dims, bool open_data = false); |
|---|
| 273 | |
|---|
| 274 | /** |
|---|
| 275 | * Create a 1D data field with the specified information. |
|---|
| 276 | * |
|---|
| 277 | * \param name The name of the field to create (i.e. "distance"). |
|---|
| 278 | * \param type The primative type of the field (i.e. "NeXus::FLOAT32"). |
|---|
| 279 | * \param length The number of elements in the field. |
|---|
| 280 | * \param open_data Whether or not to open the data after creating it. |
|---|
| 281 | */ |
|---|
| 282 | template <typename NumT> |
|---|
| 283 | void makeData(const std::string& name, const NXnumtype type, |
|---|
| 284 | const NumT length, bool open_data = false); |
|---|
| 285 | |
|---|
| 286 | /** |
|---|
| 287 | * Create a 1D data field, insert the data, and close the data. |
|---|
| 288 | * |
|---|
| 289 | * \param name The name of the field to create. |
|---|
| 290 | * \param value The string to put into the file. |
|---|
| 291 | */ |
|---|
| 292 | void writeData(const std::string& name, const std::string& value); |
|---|
| 293 | |
|---|
| 294 | /** |
|---|
| 295 | * Create a 1D data field, insert the data, and close the data. |
|---|
| 296 | * |
|---|
| 297 | * \param name The name of the field to create. |
|---|
| 298 | * \param value The string to put into the file. |
|---|
| 299 | */ |
|---|
| 300 | void writeData(const std::string& name, const char* value); |
|---|
| 301 | |
|---|
| 302 | /** |
|---|
| 303 | * Create a 1D data field, insert the data, and close the data. |
|---|
| 304 | * |
|---|
| 305 | * \tparam NumT numeric data type of \a value |
|---|
| 306 | * \param name The name of the field to create. |
|---|
| 307 | * \param value The vector to put into the file. |
|---|
| 308 | */ |
|---|
| 309 | template <typename NumT> |
|---|
| 310 | void writeData(const std::string& name, const std::vector<NumT>& value); |
|---|
| 311 | |
|---|
| 312 | /** |
|---|
| 313 | * Create a 1D data field, insert the data, and close the data. |
|---|
| 314 | * |
|---|
| 315 | * \tparam NumT numeric data type of \a value |
|---|
| 316 | * \param name The name of the field to create. |
|---|
| 317 | * \param value The value to put into the file. |
|---|
| 318 | */ |
|---|
| 319 | template <typename NumT> |
|---|
| 320 | void writeData(const std::string& name, const NumT& value); |
|---|
| 321 | |
|---|
| 322 | /** |
|---|
| 323 | * Create a n-dimension data field, insert the data, and close the data. |
|---|
| 324 | * |
|---|
| 325 | * \param name The name of the field to create. |
|---|
| 326 | * \param value The data to put into the file. |
|---|
| 327 | * \param dims The dimensions of the data. |
|---|
| 328 | * \tparam NumT numeric data type of \a value |
|---|
| 329 | */ |
|---|
| 330 | template <typename NumT> |
|---|
| 331 | void writeData(const std::string& name, const std::vector<NumT>& value, |
|---|
| 332 | const std::vector<int>& dims); |
|---|
| 333 | |
|---|
| 334 | /** |
|---|
| 335 | * Create a n-dimension data field, insert the data, and close the data. |
|---|
| 336 | * |
|---|
| 337 | * \param name The name of the field to create. |
|---|
| 338 | * \param value The data to put into the file. |
|---|
| 339 | * \param dims The dimensions of the data. |
|---|
| 340 | * \tparam NumT numeric data type of \a value |
|---|
| 341 | */ |
|---|
| 342 | template <typename NumT> |
|---|
| 343 | void writeData(const std::string& name, const std::vector<NumT>& value, |
|---|
| 344 | const std::vector<int64_t>& dims); |
|---|
| 345 | |
|---|
| 346 | /** Create a 1D data field with an unlimited dimension, insert the data, and close the data. |
|---|
| 347 | * |
|---|
| 348 | * \tparam NumT numeric data type of \a value |
|---|
| 349 | * \param name :: The name of the field to create. |
|---|
| 350 | * \param value :: The vector to put into the file. |
|---|
| 351 | */ |
|---|
| 352 | template <typename NumT> |
|---|
| 353 | void writeExtendibleData(const std::string& name, std::vector<NumT>& value); |
|---|
| 354 | |
|---|
| 355 | /** Create a 1D data field with an unlimited dimension, insert the data, and close the data. |
|---|
| 356 | * |
|---|
| 357 | * \tparam NumT numeric data type of \a value |
|---|
| 358 | * \param name :: The name of the field to create. |
|---|
| 359 | * \param value :: The vector to put into the file. |
|---|
| 360 | * \param chunkSize :: chunk size to use when writing |
|---|
| 361 | */ |
|---|
| 362 | template <typename NumT> |
|---|
| 363 | void writeExtendibleData(const std::string& name, std::vector<NumT>& value, const int64_t chunk); |
|---|
| 364 | |
|---|
| 365 | /** Create a 1D data field with an unlimited dimension, insert the data, and close the data. |
|---|
| 366 | * |
|---|
| 367 | * \tparam NumT numeric data type of \a value |
|---|
| 368 | * \param name :: The name of the field to create. |
|---|
| 369 | * \param value :: The vector to put into the file. |
|---|
| 370 | * \param dims :: The dimensions of the data. |
|---|
| 371 | * \param chunk :: chunk size to use when writing |
|---|
| 372 | */ |
|---|
| 373 | template <typename NumT> |
|---|
| 374 | void writeExtendibleData(const std::string& name, std::vector<NumT>& value, |
|---|
| 375 | std::vector<int64_t>& dims, std::vector<int64_t> & chunk); |
|---|
| 376 | |
|---|
| 377 | |
|---|
| 378 | /** Updates the data written into an already-created |
|---|
| 379 | * data vector. If the data was created as extendible, it will be resized. |
|---|
| 380 | * |
|---|
| 381 | * \tparam NumT numeric data type of \a value |
|---|
| 382 | * \param name :: The name of the field to create. |
|---|
| 383 | * \param value :: The vector to put into the file. |
|---|
| 384 | */ |
|---|
| 385 | template <typename NumT> |
|---|
| 386 | void writeUpdatedData(const std::string& name, std::vector<NumT>& value); |
|---|
| 387 | |
|---|
| 388 | /** Updates the data written into an already-created |
|---|
| 389 | * data vector. If the data was created as extendible, it will be resized. |
|---|
| 390 | * |
|---|
| 391 | * \tparam NumT numeric data type of \a value |
|---|
| 392 | * \param name :: The name of the field to create. |
|---|
| 393 | * \param value :: The vector to put into the file. |
|---|
| 394 | * \param dims :: The dimensions of the data. |
|---|
| 395 | */ |
|---|
| 396 | template <typename NumT> |
|---|
| 397 | void writeUpdatedData(const std::string& name, std::vector<NumT>& value, |
|---|
| 398 | std::vector<int64_t>& dims); |
|---|
| 399 | |
|---|
| 400 | /** |
|---|
| 401 | * \copydoc makeCompData(const std::string&, const NXnumtype, |
|---|
| 402 | * const std::vector<int64_t>&, const NXcompression, |
|---|
| 403 | * const std::vector<int64_t>&, bool) |
|---|
| 404 | */ |
|---|
| 405 | void makeCompData(const std::string& name, const NXnumtype type, |
|---|
| 406 | const std::vector<int>& dims, const NXcompression comp, |
|---|
| 407 | const std::vector<int>& bufsize, bool open_data = false); |
|---|
| 408 | |
|---|
| 409 | /** |
|---|
| 410 | * Create a field with compression. |
|---|
| 411 | * |
|---|
| 412 | * \param name The name of the data to create. |
|---|
| 413 | * \param type The primitive type for the data. |
|---|
| 414 | * \param dims The dimensions of the data. |
|---|
| 415 | * \param comp The compression algorithm to use. |
|---|
| 416 | * \param bufsize The size of the compression buffer to use. |
|---|
| 417 | * \param open_data Whether or not to open the data after creating it. |
|---|
| 418 | */ |
|---|
| 419 | void makeCompData(const std::string& name, const NXnumtype type, |
|---|
| 420 | const std::vector<int64_t>& dims, const NXcompression comp, |
|---|
| 421 | const std::vector<int64_t>& bufsize, bool open_data = false); |
|---|
| 422 | |
|---|
| 423 | /** |
|---|
| 424 | * \copydoc writeCompData(const std::string & name, |
|---|
| 425 | * const std::vector<NumT> & value, |
|---|
| 426 | * const std::vector<int64_t> & dims, const NXcompression comp, |
|---|
| 427 | * const std::vector<int64_t> & bufsize) |
|---|
| 428 | */ |
|---|
| 429 | template <typename NumT> |
|---|
| 430 | void writeCompData(const std::string & name, |
|---|
| 431 | const std::vector<NumT> & value, |
|---|
| 432 | const std::vector<int> & dims, const NXcompression comp, |
|---|
| 433 | const std::vector<int> & bufsize); |
|---|
| 434 | |
|---|
| 435 | /** |
|---|
| 436 | * Create a compressed data, insert the data, and close it. |
|---|
| 437 | * |
|---|
| 438 | * \param name The name of the data to create. |
|---|
| 439 | * \param value The vector to put into the file. |
|---|
| 440 | * \param dims The dimensions of the data. |
|---|
| 441 | * \param comp The compression algorithm to use. |
|---|
| 442 | * \param bufsize The size of the compression buffer to use. |
|---|
| 443 | * \tparam NumT numeric data type of \a value |
|---|
| 444 | */ |
|---|
| 445 | template <typename NumT> |
|---|
| 446 | void writeCompData(const std::string & name, |
|---|
| 447 | const std::vector<NumT> & value, |
|---|
| 448 | const std::vector<int64_t> & dims, const NXcompression comp, |
|---|
| 449 | const std::vector<int64_t> & bufsize); |
|---|
| 450 | |
|---|
| 451 | /** |
|---|
| 452 | * \param name The name of the data to open. |
|---|
| 453 | */ |
|---|
| 454 | void openData(const std::string& name); |
|---|
| 455 | |
|---|
| 456 | /** |
|---|
| 457 | * Close the currently open data. |
|---|
| 458 | */ |
|---|
| 459 | void closeData(); |
|---|
| 460 | |
|---|
| 461 | /** |
|---|
| 462 | * \param data The data to put in the file. |
|---|
| 463 | */ |
|---|
| 464 | void putData(const void* data); |
|---|
| 465 | |
|---|
| 466 | /** |
|---|
| 467 | * \param data The data to put in the file. |
|---|
| 468 | * \tparam NumT numeric data type of \a data |
|---|
| 469 | */ |
|---|
| 470 | template <typename NumT> |
|---|
| 471 | void putData(const std::vector<NumT>& data); |
|---|
| 472 | |
|---|
| 473 | /** |
|---|
| 474 | * Put the supplied data as an attribute into the currently open data. |
|---|
| 475 | * |
|---|
| 476 | * \param info Description of the attribute to add. |
|---|
| 477 | * \param data The attribute value. |
|---|
| 478 | */ |
|---|
| 479 | void putAttr(const AttrInfo& info, const void* data); |
|---|
| 480 | |
|---|
| 481 | /** |
|---|
| 482 | * Put the supplied data as an attribute into the currently open data. |
|---|
| 483 | * |
|---|
| 484 | * \param name Name of the attribute to add. |
|---|
| 485 | * \param value The attribute value. |
|---|
| 486 | * \tparam NumT numeric data type of \a value |
|---|
| 487 | */ |
|---|
| 488 | template <typename NumT> |
|---|
| 489 | void putAttr(const std::string& name, const NumT value); |
|---|
| 490 | |
|---|
| 491 | /** |
|---|
| 492 | * Put a string as an attribute in the file. |
|---|
| 493 | * |
|---|
| 494 | * \param name Name of the attribute to add. |
|---|
| 495 | * \param value The attribute value. |
|---|
| 496 | */ |
|---|
| 497 | void putAttr(const char* name, const char* value); |
|---|
| 498 | |
|---|
| 499 | /** |
|---|
| 500 | * Put a string as an attribute in the file. |
|---|
| 501 | * |
|---|
| 502 | * \param name Name of the attribute to add. |
|---|
| 503 | * \param value The attribute value. |
|---|
| 504 | */ |
|---|
| 505 | void putAttr(const std::string& name, const std::string value); |
|---|
| 506 | |
|---|
| 507 | /** |
|---|
| 508 | * \copydoc NeXus::File::putSlab(void* data, std::vector<int64_t>& start, |
|---|
| 509 | * std::vector<int64_t>& size) |
|---|
| 510 | */ |
|---|
| 511 | void putSlab(void* data, std::vector<int>& start, |
|---|
| 512 | std::vector<int>& size); |
|---|
| 513 | |
|---|
| 514 | /** |
|---|
| 515 | * Insert an array as part of a data in the final file. |
|---|
| 516 | * |
|---|
| 517 | * \param data The array to put in the file. |
|---|
| 518 | * \param start The starting index to insert the data. |
|---|
| 519 | * \param size The size of the array to put in the file. |
|---|
| 520 | */ |
|---|
| 521 | void putSlab(void* data, std::vector<int64_t>& start, |
|---|
| 522 | std::vector<int64_t>& size); |
|---|
| 523 | |
|---|
| 524 | /** |
|---|
| 525 | * \copydoc NeXus::File::putSlab(std::vector<NumT>& data, std::vector<int64_t>&, |
|---|
| 526 | * std::vector<int64_t>&) |
|---|
| 527 | */ |
|---|
| 528 | template <typename NumT> |
|---|
| 529 | void putSlab(std::vector<NumT>& data, std::vector<int>& start, |
|---|
| 530 | std::vector<int>& size); |
|---|
| 531 | |
|---|
| 532 | /** |
|---|
| 533 | * Insert an array as part of a data in the final file. |
|---|
| 534 | * |
|---|
| 535 | * \param data The array to put in the file. |
|---|
| 536 | * \param start The starting index to insert the data. |
|---|
| 537 | * \param size The size of the array to put in the file. |
|---|
| 538 | * \tparam NumT numeric data type of \a data |
|---|
| 539 | */ |
|---|
| 540 | template <typename NumT> |
|---|
| 541 | void putSlab(std::vector<NumT>& data, std::vector<int64_t>& start, |
|---|
| 542 | std::vector<int64_t>& size); |
|---|
| 543 | |
|---|
| 544 | /** |
|---|
| 545 | * \copydoc NeXus::File::putSlab(std::vector<NumT>&, int64_t, int64_t) |
|---|
| 546 | */ |
|---|
| 547 | template <typename NumT> |
|---|
| 548 | void putSlab(std::vector<NumT>& data, int start, int size); |
|---|
| 549 | |
|---|
| 550 | /** |
|---|
| 551 | * Insert a number as part of a data in the final file. |
|---|
| 552 | * |
|---|
| 553 | * \param data The array to put in the file. |
|---|
| 554 | * \param start The starting index to insert the data. |
|---|
| 555 | * \param size The size of the array to put in the file. |
|---|
| 556 | * \tparam NumT numeric data type of \a data |
|---|
| 557 | */ |
|---|
| 558 | template <typename NumT> |
|---|
| 559 | void putSlab(std::vector<NumT>& data, int64_t start, int64_t size); |
|---|
| 560 | |
|---|
| 561 | /** |
|---|
| 562 | * \return The id of the data used for linking. |
|---|
| 563 | */ |
|---|
| 564 | NXlink getDataID(); |
|---|
| 565 | |
|---|
| 566 | /** |
|---|
| 567 | * Create a link in the current location to the supplied id. |
|---|
| 568 | * |
|---|
| 569 | * \param link The object (group or data) in the file to link to. |
|---|
| 570 | */ |
|---|
| 571 | void makeLink(NXlink& link); |
|---|
| 572 | |
|---|
| 573 | /** |
|---|
| 574 | * Create a link with a new name. |
|---|
| 575 | * |
|---|
| 576 | * \param name The name of this copy of the link. |
|---|
| 577 | * \param link The object (group or data) in the file to link to. |
|---|
| 578 | */ |
|---|
| 579 | void makeNamedLink(const std::string& name, NXlink& link); |
|---|
| 580 | |
|---|
| 581 | /** |
|---|
| 582 | * Open the original copy of this group or data as declared by the |
|---|
| 583 | * "target" attribute. |
|---|
| 584 | */ |
|---|
| 585 | void openSourceGroup(); |
|---|
| 586 | |
|---|
| 587 | /** |
|---|
| 588 | * Put the currently open data in the supplied pointer. |
|---|
| 589 | * |
|---|
| 590 | * \param data The pointer to copy the data to. |
|---|
| 591 | */ |
|---|
| 592 | void getData(void* data); |
|---|
| 593 | |
|---|
| 594 | /** |
|---|
| 595 | * Allocate memory and return the data as a vector. Since this |
|---|
| 596 | * does call "new vector<NumT>" the caller is responsible for |
|---|
| 597 | * calling "delete". |
|---|
| 598 | * \tparam NumT numeric data type of result |
|---|
| 599 | * |
|---|
| 600 | * \return The data as a vector. |
|---|
| 601 | */ |
|---|
| 602 | template <typename NumT> |
|---|
| 603 | std::vector<NumT> * getData(); |
|---|
| 604 | |
|---|
| 605 | /** |
|---|
| 606 | * Put data into the supplied vector. The vector does not need to |
|---|
| 607 | * be the correct size, just the correct type as it is resized to |
|---|
| 608 | * the appropriate value. |
|---|
| 609 | * |
|---|
| 610 | * \param data Where to put the data. |
|---|
| 611 | * \tparam NumT numeric data type of \a data |
|---|
| 612 | */ |
|---|
| 613 | template <typename NumT> |
|---|
| 614 | void getData(std::vector<NumT>& data); |
|---|
| 615 | |
|---|
| 616 | /** Get data and coerce into an int vector. |
|---|
| 617 | * |
|---|
| 618 | * @throw Exception if the data is actually a float or |
|---|
| 619 | * another type that cannot be coerced to an int. |
|---|
| 620 | * @param data :: vector to be filled. |
|---|
| 621 | */ |
|---|
| 622 | void getDataCoerce(std::vector<int> &data); |
|---|
| 623 | |
|---|
| 624 | /** Get data and coerce into a vector of doubles. |
|---|
| 625 | * |
|---|
| 626 | * @throw Exception if the data cannot be coerced to a double. |
|---|
| 627 | * @param data :: vector to be filled. |
|---|
| 628 | */ |
|---|
| 629 | void getDataCoerce(std::vector<double> &data); |
|---|
| 630 | |
|---|
| 631 | /** Return true if the data opened is of one of the |
|---|
| 632 | * int data types, 32 bits or less. |
|---|
| 633 | */ |
|---|
| 634 | bool isDataInt(); |
|---|
| 635 | |
|---|
| 636 | /** Put data into the supplied vector. The vector does not need to |
|---|
| 637 | * be the correct size, just the correct type as it is resized to |
|---|
| 638 | * the appropriate value. |
|---|
| 639 | * |
|---|
| 640 | * The named data object is opened, loaded, then closed. |
|---|
| 641 | * |
|---|
| 642 | * @param dataName :: name of the data to open. |
|---|
| 643 | * @param data :: Where to put the data. |
|---|
| 644 | * \tparam NumT numeric data type of \a data |
|---|
| 645 | */ |
|---|
| 646 | template <typename NumT> |
|---|
| 647 | void readData(const std::string & dataName, std::vector<NumT>& data); |
|---|
| 648 | |
|---|
| 649 | /** Put data into the supplied value. |
|---|
| 650 | * |
|---|
| 651 | * The named data object is opened, loaded, then closed. |
|---|
| 652 | * |
|---|
| 653 | * \param dataName :: name of the data to open. |
|---|
| 654 | * \param data :: Where to put the data. |
|---|
| 655 | * \tparam NumT numeric data type of \a data |
|---|
| 656 | */ |
|---|
| 657 | template <typename NumT> |
|---|
| 658 | void readData(const std::string & dataName, NumT & data); |
|---|
| 659 | |
|---|
| 660 | /** Put data into the supplied string. The vector does not need to |
|---|
| 661 | * be the correct size, just the correct type as it is resized to |
|---|
| 662 | * the appropriate value. |
|---|
| 663 | * |
|---|
| 664 | * The named data object is opened, loaded, then closed. |
|---|
| 665 | * |
|---|
| 666 | * @param dataName :: name of the data to open. |
|---|
| 667 | * @param data :: Where to put the data. |
|---|
| 668 | */ |
|---|
| 669 | void readData(const std::string & dataName, std::string & data); |
|---|
| 670 | |
|---|
| 671 | /** |
|---|
| 672 | * \return String data from the file. |
|---|
| 673 | */ |
|---|
| 674 | std::string getStrData(); |
|---|
| 675 | |
|---|
| 676 | /** |
|---|
| 677 | * \return The Info structure that describes the currently open data. |
|---|
| 678 | */ |
|---|
| 679 | Info getInfo(); |
|---|
| 680 | |
|---|
| 681 | /** |
|---|
| 682 | * Return the entries available in the current place in the file. |
|---|
| 683 | */ |
|---|
| 684 | std::map<std::string, std::string> getEntries(); |
|---|
| 685 | |
|---|
| 686 | /** Return the entries available in the current place in the file, |
|---|
| 687 | * but avoids the map copy of getEntries(). |
|---|
| 688 | * |
|---|
| 689 | * \param result The map that will be filled with the entries |
|---|
| 690 | */ |
|---|
| 691 | void getEntries(std::map<std::string, std::string> & result); |
|---|
| 692 | |
|---|
| 693 | /** |
|---|
| 694 | * \copydoc NeXus::File::getSlab(void*, const std::vector<int64_t>&, |
|---|
| 695 | * const std::vector<int64_t>&) |
|---|
| 696 | */ |
|---|
| 697 | void getSlab(void* data, const std::vector<int>& start, |
|---|
| 698 | const std::vector<int>& size); |
|---|
| 699 | |
|---|
| 700 | /** |
|---|
| 701 | * Get a section of data from the file. |
|---|
| 702 | * |
|---|
| 703 | * \param data The pointer to insert that data into. |
|---|
| 704 | * \param start The offset into the file's data block to start the read |
|---|
| 705 | * from. |
|---|
| 706 | * \param size The size of the block to read from the file. |
|---|
| 707 | */ |
|---|
| 708 | void getSlab(void* data, const std::vector<int64_t>& start, |
|---|
| 709 | const std::vector<int64_t>& size); |
|---|
| 710 | |
|---|
| 711 | /** |
|---|
| 712 | * \return Information about all attributes on the data that is |
|---|
| 713 | * currently open. |
|---|
| 714 | */ |
|---|
| 715 | std::vector<AttrInfo> getAttrInfos(); |
|---|
| 716 | |
|---|
| 717 | /** |
|---|
| 718 | * \return true if the current point in the file has the named attribute |
|---|
| 719 | * \param name the name of the attribute to look for. |
|---|
| 720 | */ |
|---|
| 721 | bool hasAttr(const std::string & name); |
|---|
| 722 | |
|---|
| 723 | /** |
|---|
| 724 | * Get the value of the attribute specified by the AttrInfo supplied. |
|---|
| 725 | * |
|---|
| 726 | * \param info Designation of which attribute to read. |
|---|
| 727 | * \param data The pointer to put the attribute value in. |
|---|
| 728 | * \param length The length of the attribute. If this is "-1" then the |
|---|
| 729 | * information in the supplied AttrInfo object will be used. |
|---|
| 730 | */ |
|---|
| 731 | void getAttr(const AttrInfo& info, void* data, int length = -1); |
|---|
| 732 | |
|---|
| 733 | /** |
|---|
| 734 | * Get the value of an attribute that is a scalar number. |
|---|
| 735 | * |
|---|
| 736 | * \param info Designation of which attribute to read. |
|---|
| 737 | * \tparam NumT numeric data type of result |
|---|
| 738 | * |
|---|
| 739 | * \return The attribute value. |
|---|
| 740 | */ |
|---|
| 741 | template <typename NumT> |
|---|
| 742 | NumT getAttr(const AttrInfo& info); |
|---|
| 743 | |
|---|
| 744 | |
|---|
| 745 | /** |
|---|
| 746 | * Get the value of an attribute that is a scalar number. |
|---|
| 747 | * |
|---|
| 748 | * \param[in] name Name of attribute to read |
|---|
| 749 | * \param[out] value The read attribute value. |
|---|
| 750 | * \tparam NumT numeric data type of \a value |
|---|
| 751 | */ |
|---|
| 752 | template <typename NumT> |
|---|
| 753 | void getAttr(const std::string& name, NumT& value); |
|---|
| 754 | |
|---|
| 755 | |
|---|
| 756 | /** |
|---|
| 757 | * Get the value of a string attribute. |
|---|
| 758 | * |
|---|
| 759 | * \param info Which attribute to read. |
|---|
| 760 | * |
|---|
| 761 | * \return The value of the attribute. |
|---|
| 762 | */ |
|---|
| 763 | std::string getStrAttr(const AttrInfo & info); |
|---|
| 764 | |
|---|
| 765 | /** |
|---|
| 766 | * \return The id of the group used for linking. |
|---|
| 767 | */ |
|---|
| 768 | NXlink getGroupID(); |
|---|
| 769 | |
|---|
| 770 | /** |
|---|
| 771 | * Determine whether or not two links refer to the same data or group. |
|---|
| 772 | * |
|---|
| 773 | * \param first The first link information to compare. |
|---|
| 774 | * \param second The second link information to compare. |
|---|
| 775 | * |
|---|
| 776 | * \return True if the two point at the same data or group. |
|---|
| 777 | */ |
|---|
| 778 | bool sameID(NXlink& first, NXlink& second); |
|---|
| 779 | |
|---|
| 780 | /** |
|---|
| 781 | * Diagnostic print of the link information. |
|---|
| 782 | * |
|---|
| 783 | * \param link The link to print to stdout. |
|---|
| 784 | */ |
|---|
| 785 | void printLink(NXlink & link); |
|---|
| 786 | |
|---|
| 787 | /** |
|---|
| 788 | * Set the number format used for a particular type when using the |
|---|
| 789 | * xml base. This is ignore in the other bases. |
|---|
| 790 | * |
|---|
| 791 | * \param type The primitive type to set the format for. |
|---|
| 792 | * \param format The format to use. |
|---|
| 793 | */ |
|---|
| 794 | void setNumberFormat(NXnumtype& type, const std::string& format); |
|---|
| 795 | |
|---|
| 796 | /** |
|---|
| 797 | * Find out the name of the file this object is holding onto. |
|---|
| 798 | * |
|---|
| 799 | * \param buff_length The size of the buffer to use for reading the name. |
|---|
| 800 | * |
|---|
| 801 | * \return The name of the file. |
|---|
| 802 | */ |
|---|
| 803 | std::string inquireFile(const int buff_length = NX_MAXPATHLEN); |
|---|
| 804 | |
|---|
| 805 | /** |
|---|
| 806 | * Determine Whether or not a supplied group is external. |
|---|
| 807 | * |
|---|
| 808 | * \param name The name of the group to check. |
|---|
| 809 | * \param type The type of the group to check. |
|---|
| 810 | * \param buff_length The size of the buffer to use for reading the url. |
|---|
| 811 | * |
|---|
| 812 | * \return The url to the external group. |
|---|
| 813 | */ |
|---|
| 814 | std::string isExternalGroup(const std::string& name, |
|---|
| 815 | const std::string& type, |
|---|
| 816 | const unsigned buff_length = NX_MAXNAMELEN); |
|---|
| 817 | |
|---|
| 818 | /** |
|---|
| 819 | * Create a link to a group in an external file. |
|---|
| 820 | * |
|---|
| 821 | * \param name The name for the group in this file. |
|---|
| 822 | * \param type The type for the group in this file. |
|---|
| 823 | * \param url The url to the group in the external file. |
|---|
| 824 | */ |
|---|
| 825 | void linkExternal(const std::string& name, const std::string& type, |
|---|
| 826 | const std::string& url); |
|---|
| 827 | /** |
|---|
| 828 | * This function checksi if we are in an open dataset |
|---|
| 829 | * \returns true if we are currently in an open dataset else false |
|---|
| 830 | */ |
|---|
| 831 | bool isDataSetOpen(); |
|---|
| 832 | |
|---|
| 833 | /** |
|---|
| 834 | * Create a multimap with the data types as keys and the associated paths as values. |
|---|
| 835 | * |
|---|
| 836 | * \return The multimap of the opened file. |
|---|
| 837 | */ |
|---|
| 838 | TypeMap *getTypeMap(); |
|---|
| 839 | }; |
|---|
| 840 | |
|---|
| 841 | /** |
|---|
| 842 | * This function returns the NXnumtype given a concrete number. |
|---|
| 843 | * \tparam NumT numeric data type of \a number to check |
|---|
| 844 | */ |
|---|
| 845 | template <typename NumT> |
|---|
| 846 | NXDLL_EXPORT NXnumtype getType(NumT number = NumT()); |
|---|
| 847 | |
|---|
| 848 | |
|---|
| 849 | }; |
|---|
| 850 | |
|---|
| 851 | #include "NeXusStream.hpp" |
|---|
| 852 | |
|---|
| 853 | #endif |
|---|