source: src/CodePatterns/Factory_impl.hpp@ 084729c

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 084729c was 084729c, checked in by Frederik Heber <heber@…>, 8 years ago

Squashed 'ThirdParty/CodePatterns/' content from commit c1e1041

git-subtree-dir: ThirdParty/CodePatterns
git-subtree-split: c1e10418c454f98be2f43d93167642b0008428fc

  • Property mode set to 100644
File size: 5.2 KB
RevLine 
[084729c]1/*
2 * Factory_impl.hpp
3 *
4 * Created on: Jan 3, 2011
5 * Author: heber
6 */
7
8// include config.h
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
13#include <boost/preprocessor/debug/assert.hpp>
14#include <boost/preprocessor/facilities/empty.hpp>
15#include <boost/preprocessor/iteration/local.hpp>
16#include <boost/preprocessor/punctuation/comma.hpp>
17#include <boost/preprocessor/punctuation/comma_if.hpp>
18#include <boost/preprocessor/punctuation/paren.hpp>
19#include <boost/preprocessor/seq/elem.hpp>
20#include <boost/preprocessor/seq/size.hpp>
21#include <boost/preprocessor/stringize.hpp>
22
23// check for required type_seq
24#ifdef type_seq
25#define type_seq_size BOOST_PP_SEQ_SIZE(type_seq)
26#else
27BOOST_PP_ASSERT_MSG( 0 , \
28 "std::cout << \"missing type_seq for creating Factory<T>\" << std::endl")
29#define type_seq ()
30#endif
31
32// check for required Abstract_Interface_Class
33#ifndef Abstract_Interface_Class
34 BOOST_PP_ASSERT_MSG( 0 , \
35 "std::cout << \"missing Abstract_Interface_Class for creating Factory<T>\" << std::endl")
36#define Abstract_Interface_Class NONE
37#endif
38
39// check for required Abstract_Encapsulation_Class
40#ifndef Abstract_Encapsulation_Class
41 BOOST_PP_ASSERT_MSG( 0 , \
42 "std::cout << \"missing Abstract_Encapsulation_Class for creating Factory<T>\" << std::endl")
43#define Abstract_Encapsulation_Class NONE
44#endif
45
46// check for type_name_space, is only optional
47#ifndef type_name_space
48#define type_name_space BOOST_PP_EMPTY()
49#endif
50
51#ifndef type_name_space_suffix
52#define type_name_space_suffix BOOST_PP_EMPTY()
53#endif
54
55
56/** Functions that allows to print a given seq of elements in the way of
57 * std::map from strings to enums.
58 *
59 * e.g. let "seq" be defined as
60 * #define seq (one)(two)(three)(four)
61 *
62 * then we use
63 * #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_map(seqsize, n, seq, EnumMap, test::)
64 * #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(seq)-1 )
65 * #include BOOST_PP_LOCAL_ITERATE()
66 *
67 * which expands by the preprocessor to:
68 * EnumMap[one] = test::one;
69 * EnumMap[two] = test::two;
70 * EnumMap[three] = test::three;
71 * EnumMap[four] = test::four;
72 *
73 */
74#define seqitems_as_enum_key_map(z,n,_seq_with_elements, _map, _keytype, _key_name_space, _type_name_space, _type_suffix) \
75 _map [ _key_name_space \
76 BOOST_PP_SEQ_ELEM(n, _seq_with_elements) \
77 ] = _keytype< _type_name_space BOOST_PP_SEQ_ELEM(n, _seq_with_elements) _type_suffix > ();
78
79/** Functions that allows to print a given seq of elements in the way of
80 * std::map from strings to enums.
81 *
82 * e.g. let "seq" be defined as
83 * #define seq (one)(two)(three)(four)
84 *
85 * then we use
86 * #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_value_map(seqsize, n, seq, EnumMap, typid BOOST_PP_LPAREN() super:: , BOOST_PP_RPAREN().name() , test::)
87 * #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(seq)-1 )
88 * #include BOOST_PP_LOCAL_ITERATE()
89 *
90 * which expands by the preprocessor to:
91 * EnumMap[ typeid ( super:: one ) .name() ] = test::one;
92 * EnumMap[ typeid ( super:: two ) .name() ] = test::two;
93 * EnumMap[ typeid ( super:: three ) .name() ] = test::three;
94 * EnumMap[ typeid ( super:: four ) .name() ] = test::four;
95 *
96 * or we use
97 * #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_value_map(seqsize, n, seq, EnumMap, BOOST_PP_STRINGIZE BOOST_PP_LPAREN() , BOOST_PP_RPAREN() , test::)
98 * #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(seq)-1 )
99 * #include BOOST_PP_LOCAL_ITERATE()
100 *
101 * which expands by the preprocessor to:
102 * EnumMap[ "one" ] = test:: one;
103 * EnumMap[ "two" ] = test:: two;
104 * EnumMap[ "three" ] = test:: three;
105 * EnumMap[ "four" ] = test:: four;
106 */
107#define seqitems_as_enum_value_map(z,n,_seq_with_elements, _map, _type_specifier, _type_suffix, _enum_name_space) \
108 _map [ _type_specifier \
109 BOOST_PP_SEQ_ELEM(n, _seq_with_elements) \
110 _type_suffix \
111 ] = _enum_name_space BOOST_PP_SEQ_ELEM(n, _seq_with_elements);
112
113
114template <>
115void Factory<Abstract_Interface_Class>::FillEnumTable()
116{
117 // insert all known (enum, string) keys
118#define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_value_map(~, n, type_seq, enums, BOOST_PP_STRINGIZE BOOST_PP_LPAREN() , BOOST_PP_RPAREN() , FactoryTypeList<Abstract_Interface_Class>::)
119#define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(type_seq)-1 )
120#include BOOST_PP_LOCAL_ITERATE()
121
122 // insert all known (type, enum) keys
123#define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_value_map(~, n, type_seq, types, typeid BOOST_PP_LPAREN() type_name_space , type_name_space_suffix BOOST_PP_RPAREN() .name(), FactoryTypeList<Abstract_Interface_Class>::)
124#define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(type_seq)-1 )
125#include BOOST_PP_LOCAL_ITERATE()
126
127 // create invert mapping (string, enum)
128 for (Factory<Abstract_Interface_Class>::EnumMap::const_iterator iter = enums.begin();
129 iter != enums.end();
130 ++iter) {
131 names.insert(make_pair(iter->second, iter->first));
132 }
133}
134
135template <>
136void Factory<Abstract_Interface_Class>::FillPrototypeTable()
137{
138 // fill PrototypeTable
139#define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_map(~, n, type_seq, PrototypeTable, new Creator< Abstract_Interface_Class BOOST_PP_COMMA() Abstract_Encapsulation_Class, FactoryTypeList<Abstract_Interface_Class>::, type_name_space, type_name_space_suffix > )
140#define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(type_seq)-1 )
141#include BOOST_PP_LOCAL_ITERATE()
142}
143
Note: See TracBrowser for help on using the repository browser.