1 | /*
|
---|
2 | * MPQCData_printName.hpp
|
---|
3 | *
|
---|
4 | * Created on: 28.07.2012
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef MPQCDATA_PRINTNAME_HPP_
|
---|
9 | #define MPQCDATA_PRINTNAME_HPP_
|
---|
10 |
|
---|
11 | // include config.h
|
---|
12 | #ifdef HAVE_CONFIG_H
|
---|
13 | #include <config.h>
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | //#include <iosfwd>
|
---|
17 | #include <string>
|
---|
18 |
|
---|
19 | #include <boost/preprocessor/iteration/local.hpp>
|
---|
20 | #include <boost/preprocessor/seq/elem.hpp>
|
---|
21 | #include <boost/preprocessor/seq/seq.hpp>
|
---|
22 | #include <boost/preprocessor/seq/size.hpp>
|
---|
23 | #include <boost/preprocessor/stringize.hpp>
|
---|
24 |
|
---|
25 | /** this is the boost::preprocessor::sequence of the keys in the boost::fusion::map
|
---|
26 | *
|
---|
27 | * Basically, every key appears here in brackets. If so, then the preprocessor magic
|
---|
28 | * below will create a template specialization of the printName() function in the
|
---|
29 | * namespace MPQCDataNames.
|
---|
30 | */
|
---|
31 | #define tokensequence \
|
---|
32 | (energy_total) \
|
---|
33 | (energy_nuclear_repulsion) \
|
---|
34 | (energy_electron_coulomb) \
|
---|
35 | (energy_electron_exchange) \
|
---|
36 | (energy_correlation) \
|
---|
37 | (energy_overlap) \
|
---|
38 | (energy_kinetic) \
|
---|
39 | (energy_hcore) \
|
---|
40 | (energy_eigenvalues) \
|
---|
41 | (forces) \
|
---|
42 | (times_walltime) \
|
---|
43 | (times_cputime) \
|
---|
44 | (times_flops)
|
---|
45 |
|
---|
46 | /// we take note of the number of keys in tokensequence as (local) loop bounds below
|
---|
47 | #ifndef tokensequence
|
---|
48 | #define MAXTOKENS 0
|
---|
49 | #else
|
---|
50 | #define MAXTOKENS BOOST_PP_SEQ_SIZE(tokensequence)
|
---|
51 | #endif
|
---|
52 |
|
---|
53 | //!> this is the macro function which prints the specialized template function
|
---|
54 | #define printName_specializer(z, n, NAMESPACE, TOKENSEQ, NAMESEQ ) \
|
---|
55 | template<> std::string printName< NAMESPACE :: BOOST_PP_SEQ_ELEM( n, TOKENSEQ ) >() { \
|
---|
56 | return std::string( BOOST_PP_STRINGIZE( BOOST_PP_SEQ_ELEM( n, NAMESEQ ) ) ); \
|
---|
57 | }
|
---|
58 |
|
---|
59 | /** Specific namespace for all the specialized template functions that print
|
---|
60 | * a useful name for each of the boost::fusion::map key.
|
---|
61 | */
|
---|
62 | namespace MPQCDataNames {
|
---|
63 |
|
---|
64 | /** This function needs to be specialized for every member variable in MPQCData
|
---|
65 | * such that it prints the name of the member variable.
|
---|
66 | *
|
---|
67 | * By default, we just return an empty string.
|
---|
68 | */
|
---|
69 | template <typename T> std::string printName() {
|
---|
70 | return std::string();
|
---|
71 | };
|
---|
72 |
|
---|
73 | // iterate (line-wise) over the sequence and spill out a specialized printName
|
---|
74 | #if defined tokensequence && defined MAXTOKENS && defined printName_specializer
|
---|
75 | #define BOOST_PP_LOCAL_MACRO(n) printName_specializer(~, n, MPQCDataFused, tokensequence, tokensequence)
|
---|
76 | #define BOOST_PP_LOCAL_LIMITS (0, MAXTOKENS-1)
|
---|
77 | #include BOOST_PP_LOCAL_ITERATE()
|
---|
78 | #endif
|
---|
79 |
|
---|
80 | }; /* namespace MPQCDataNames */
|
---|
81 |
|
---|
82 | #undef tokensequence
|
---|
83 | #undef printName_specializer
|
---|
84 |
|
---|
85 | #undef MAXTOKENS
|
---|
86 |
|
---|
87 | #endif /* MPQCDATA_PRINTNAME_HPP_ */
|
---|