CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ReflexTools.h
Go to the documentation of this file.
1 #ifndef FWCore_Utilities_ReflexTools_h
2 #define FWCore_Utilities_ReflexTools_h
3 
4 /*----------------------------------------------------------------------
5 
6 ReflexTools provides a small number of Reflex-based tools, used in
7 the CMS event model.
8 
9 ----------------------------------------------------------------------*/
10 
11 #include "Reflex/Object.h"
12 #include "Reflex/Type.h"
13 
14 #include <ostream>
15 #include <set>
16 #include <string>
17 #include <typeinfo>
18 #include <vector>
19 
20 namespace edm {
21 
22  typedef std::set<std::string> StringSet;
23 
24  bool
25  find_nested_type_named(std::string const& nested_type,
26  Reflex::Type const& type_to_search,
27  Reflex::Type& found_type);
28 
29  inline
30  bool
31  value_type_of(Reflex::Type const& t, Reflex::Type& found_type) {
32  return find_nested_type_named("value_type", t, found_type);
33  }
34 
35 
36  inline
37  bool
38  wrapper_type_of(Reflex::Type const& possible_wrapper,
39  Reflex::Type& found_wrapped_type) {
40  return find_nested_type_named("wrapped_type",
41  possible_wrapper,
42  found_wrapped_type);
43  }
44 
45  bool
46  is_RefVector(Reflex::Type const& possible_ref_vector,
48 
49  bool
50  is_PtrVector(Reflex::Type const& possible_ref_vector,
52  bool
53  is_RefToBaseVector(Reflex::Type const& possible_ref_vector,
55 
56  void checkDictionaries(std::string const& name, bool noComponents = false);
61 
63  std::vector<Reflex::Type>& baseTypes);
64 
72 
73  // It would be nice to use void const* for the type of 'raw', but
74  // the Reflex interface for creating an Object will not allow that.
75 
76  template <class T>
77  T const*
78  reflex_cast(void* raw, Reflex::Type const& dynamicType) {
79  static Reflex::Type const
80  toType(Reflex::Type::ByTypeInfo(typeid(T)));
81 
82  Reflex::Object obj(dynamicType, raw);
83  return static_cast<T const*>(obj.CastObject(toType).Address());
84 
85  // This alternative implementation of reflex_cast would allow us
86  // to remove the compile-time depenency on Reflex/Type.h and
87  // Reflex/Object.h, at the cost of some speed.
88  //
89  // return static_cast<T const*>(reflex_pointer_adjust(raw,
90  // dynamicType,
91  // typeid(T)));
92  }
93 
94  // The following function should not now be used. It is here in case
95  // we need to get rid of the compile-time dependency on
96  // Reflex/Type.h and Reflex/Object.h introduced by the current
97  // implementation of reflex_cast (above). If we have to be rid of
98  // that dependency, the alternative implementation of reflex_cast
99  // uses this function, at the cost of some speed: repeated lookups
100  // of the same Reflex::Type object for the same type will have
101  // to be made.
102 
111 
112  void const*
113  reflex_pointer_adjust(void* raw,
114  Reflex::Type const& dynamicType,
115  std::type_info const& toType);
116 }
117 
118 #endif
type
Definition: HCALResponse.h:22
bool is_RefToBaseVector(Reflex::Type const &possible_ref_vector, Reflex::Type &value_type)
Definition: ReflexTools.cc:86
bool is_PtrVector(Reflex::Type const &possible_ref_vector, Reflex::Type &value_type)
Definition: ReflexTools.cc:69
bool value_type_of(Reflex::Type const &t, Reflex::Type &found_type)
Definition: ReflexTools.h:31
void const * reflex_pointer_adjust(void *raw, Reflex::Type const &dynamicType, std::type_info const &toType)
void public_base_classes(Reflex::Type const &type, std::vector< Reflex::Type > &baseTypes)
StringSet & missingTypes()
Definition: ReflexTools.cc:189
bool wrapper_type_of(Reflex::Type const &possible_wrapper, Reflex::Type &found_wrapped_type)
Definition: ReflexTools.h:38
std::set< std::string > StringSet
Definition: ReflexTools.h:22
void checkDictionaries(std::string const &name, bool noComponents=false)
Definition: ReflexTools.cc:199
StringSet & foundTypes()
Definition: ReflexTools.cc:193
Container::value_type value_type
void throwMissingDictionariesException()
Definition: ReflexTools.cc:209
bool find_nested_type_named(std::string const &nested_type, Reflex::Type const &type_to_search, Reflex::Type &found_type)
T const * reflex_cast(void *raw, Reflex::Type const &dynamicType)
Definition: ReflexTools.h:78
string const
Definition: compareJSON.py:14
void loadMissingDictionaries()
Definition: ReflexTools.cc:231
bool is_RefVector(Reflex::Type const &possible_ref_vector, Reflex::Type &value_type)
Definition: ReflexTools.cc:56
long double T