RMF
HDF5/infrastructure_macros.h
Go to the documentation of this file.
1 /**
2  * \file RMF/HDF5/infrastructure_macros.h
3  * \brief Various general useful macros for IMP.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef RMF_HDF5_INFRASTRUCTURE_MACROS_H
10 #define RMF_HDF5_INFRASTRUCTURE_MACROS_H
11 
12 #include <sstream>
13 #include <iostream>
14 #include <string>
15 #include <vector>
17 
18 #if !defined(SWIG) && !defined(RMF_DOXYGEN)
19 namespace RMF {
20 namespace HDF5 {
21 using RMF::Showable;
22 using RMF::operator<<;
23 }
24 }
25 #endif
26 
27 /** Call a function and throw an RMF::IOException if the return values is bad */
28 #define RMF_HDF5_CALL(v) \
29  if ((v) < 0) { \
30  RMF_THROW(Message("HDF5/HDF5 call failed") << Expression(#v), \
31  RMF::IOException); \
32  }
33 
34 /** Create new HDF5 SharedData.handle.*/
35 #define RMF_HDF5_NEW_HANDLE(name, cmd, cleanup) \
36  std::shared_ptr<RMF::HDF5::SharedHandle> name = \
37  std::make_shared<RMF::HDF5::SharedHandle>(cmd, cleanup, #cmd)
38 
39 #define RMF_HDF5_HANDLE(name, cmd, cleanup) \
40  RMF::HDF5::Handle name(cmd, cleanup, #cmd)
41 
42 #ifndef RMF_DOXYGEN
43 /** Expand to applying the macro to each type supported by
44  the RMF library. The macro should take six arguments
45  - the lower case name of the type
46  - the upper case name
47  - the C++ type for accepting the value
48  - the C++ type for returning the value
49  - the C++ type for accepting more than one value
50  - the C++ type for returning more than one value
51  */
52 #define RMF_HDF5_FOREACH_TYPE(macroname) \
53  RMF_FOREACH_SIMPLE_TYPE(macroname); \
54  macroname(string, String, String, String, const Strings&, Strings); \
55  macroname(strings, Strings, Strings, Strings, const StringsList&, \
56  StringsList); \
57  macroname(floats, Floats, const Floats&, Floats, const FloatsList&, \
58  FloatsList); \
59  macroname(ints, Ints, const Ints&, Ints, const IntsList&, IntsList); \
60  macroname(indexes, Indexes, const Indexes&, Indexes, const IndexesList&, \
61  IndexesList);
62 #else
63 #define RMF_HDF5_FOREACH_TYPE(macroname) \
64  macroname(type, Type, Type, Types, const Types&, Types);
65 #endif
66 
67 #endif /* RMF_HDF5_INFRASTRUCTURE_MACROS_H */
Various general useful macros for IMP.