CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/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   StringSet& missingTypes();
00058 
00059   void public_base_classes(Reflex::Type const& type,
00060                            std::vector<Reflex::Type>& baseTypes);
00061 
00069 
00070   // It would be nice to use void const* for the type of 'raw', but
00071   // the Reflex interface for creating an Object will not allow that.
00072 
00073   template <class T>
00074   T const*
00075   reflex_cast(void* raw, Reflex::Type const& dynamicType) {
00076     static Reflex::Type const
00077       toType(Reflex::Type::ByTypeInfo(typeid(T)));
00078 
00079     Reflex::Object obj(dynamicType, raw);
00080     return static_cast<T const*>(obj.CastObject(toType).Address());
00081 
00082     // This alternative implementation of reflex_cast would allow us
00083     // to remove the compile-time depenency on Reflex/Type.h and
00084     // Reflex/Object.h, at the cost of some speed.
00085     //
00086     //     return static_cast<T const*>(reflex_pointer_adjust(raw,
00087     //                                                 dynamicType,
00088     //                                                 typeid(T)));
00089   }
00090 
00091   // The following function should not now be used. It is here in case
00092   // we need to get rid of the compile-time dependency on
00093   // Reflex/Type.h and Reflex/Object.h introduced by the current
00094   // implementation of reflex_cast (above). If we have to be rid of
00095   // that dependency, the alternative implementation of reflex_cast
00096   // uses this function, at the cost of some speed: repeated lookups
00097   // of the same Reflex::Type object for the same type will have
00098   // to be made.
00099 
00108 
00109   void const*
00110   reflex_pointer_adjust(void* raw,
00111                         Reflex::Type const& dynamicType,
00112                         std::type_info const& toType);
00113 }
00114 
00115 #endif