CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/FWCore/Utilities/interface/ReflexTools.h

Go to the documentation of this file.
00001 #ifndef FWCore_Utilities_ReflexTools_h
00002 #define FWCore_Utilities_ReflexTools_h
00003 
00004 /*----------------------------------------------------------------------
00005 
00006 ReflexTools provides a small number of Reflex-based tools, used in
00007 the CMS event model.
00008 
00009 ----------------------------------------------------------------------*/
00010 
00011 #include "Reflex/Object.h"
00012 #include "Reflex/Type.h"
00013 
00014 #include <ostream>
00015 #include <set>
00016 #include <string>
00017 #include <typeinfo>
00018 #include <vector>
00019 
00020 namespace edm {
00021 
00022   typedef std::set<std::string> StringSet;
00023 
00024   bool
00025   find_nested_type_named(std::string const& nested_type,
00026                          Reflex::Type const& type_to_search,
00027                          Reflex::Type& found_type);
00028 
00029   inline
00030   bool
00031   value_type_of(Reflex::Type const& t, Reflex::Type& found_type) {
00032     return find_nested_type_named("value_type", t, found_type);
00033   }
00034 
00035 
00036   inline
00037   bool
00038   wrapper_type_of(Reflex::Type const& possible_wrapper,
00039                   Reflex::Type& found_wrapped_type) {
00040     return find_nested_type_named("wrapped_type",
00041                                   possible_wrapper,
00042                                   found_wrapped_type);
00043   }
00044 
00045   bool
00046   is_RefVector(Reflex::Type const& possible_ref_vector,
00047                Reflex::Type& value_type);
00048 
00049   bool
00050   is_PtrVector(Reflex::Type const& possible_ref_vector,
00051                Reflex::Type& value_type);
00052   bool
00053   is_RefToBaseVector(Reflex::Type const& possible_ref_vector,
00054                      Reflex::Type& value_type);
00055 
00056   void checkDictionaries(std::string const& name, bool noComponents = false);
00057   void throwMissingDictionariesException();
00058   void loadMissingDictionaries();
00059   StringSet& missingTypes();
00060   StringSet& foundTypes();
00061 
00062   void public_base_classes(Reflex::Type const& type,
00063                            std::vector<Reflex::Type>& baseTypes);
00064 
00072 
00073   // It would be nice to use void const* for the type of 'raw', but
00074   // the Reflex interface for creating an Object will not allow that.
00075 
00076   template <class T>
00077   T const*
00078   reflex_cast(void* raw, Reflex::Type const& dynamicType) {
00079     static Reflex::Type const
00080       toType(Reflex::Type::ByTypeInfo(typeid(T)));
00081 
00082     Reflex::Object obj(dynamicType, raw);
00083     return static_cast<T const*>(obj.CastObject(toType).Address());
00084 
00085     // This alternative implementation of reflex_cast would allow us
00086     // to remove the compile-time depenency on Reflex/Type.h and
00087     // Reflex/Object.h, at the cost of some speed.
00088     //
00089     //     return static_cast<T const*>(reflex_pointer_adjust(raw,
00090     //                                                 dynamicType,
00091     //                                                 typeid(T)));
00092   }
00093 
00094   // The following function should not now be used. It is here in case
00095   // we need to get rid of the compile-time dependency on
00096   // Reflex/Type.h and Reflex/Object.h introduced by the current
00097   // implementation of reflex_cast (above). If we have to be rid of
00098   // that dependency, the alternative implementation of reflex_cast
00099   // uses this function, at the cost of some speed: repeated lookups
00100   // of the same Reflex::Type object for the same type will have
00101   // to be made.
00102 
00111 
00112   void const*
00113   reflex_pointer_adjust(void* raw,
00114                         Reflex::Type const& dynamicType,
00115                         std::type_info const& toType);
00116 }
00117 
00118 #endif