CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/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 <ostream>
00012 #include <set>
00013 #include <string>
00014 #include <vector>
00015 
00016 #include "Reflex/Type.h"
00017 #include "Reflex/Object.h"
00018 
00019 namespace edm
00020 {
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   {
00033     return find_nested_type_named("value_type", t, found_type);
00034   }
00035 
00036 
00037   inline
00038   bool 
00039   wrapper_type_of(Reflex::Type const& possible_wrapper,
00040                   Reflex::Type& found_wrapped_type)
00041   {
00042     return find_nested_type_named("wrapped_type",
00043                                   possible_wrapper,
00044                                   found_wrapped_type);
00045   }
00046 
00047   // is_sequence_wrapper is used to determine whether the Type
00048   // 'possible_sequence_wrapper' represents
00049   //   edm::Wrapper<Seq<X> >,
00050   // where Seq<X> is anything that is a sequence of X.
00051   // Note there is special support of edm::RefVector<Seq<X> >, which
00052   // will be recognized as a sequence of X.
00053   bool 
00054   is_sequence_wrapper(Reflex::Type const& possible_sequence_wrapper,
00055                       Reflex::Type& found_sequence_value_type);
00056 
00057   bool 
00058   if_edm_ref_get_value_type(Reflex::Type const& possible_ref,
00059                             Reflex::Type& value_type);
00060 
00061   bool 
00062   if_edm_ptr_get_value_type(Reflex::Type const& possible_ref,
00063                             Reflex::Type& value_type);
00064 
00065   bool 
00066   if_edm_refToBase_get_value_type(Reflex::Type const& possible_ref,
00067                                   Reflex::Type& value_type);
00068 
00069   bool
00070   is_RefVector(Reflex::Type const& possible_ref_vector,
00071                Reflex::Type& value_type);
00072 
00073   bool
00074   is_PtrVector(Reflex::Type const& possible_ref_vector,
00075                Reflex::Type& value_type);
00076   bool
00077   is_RefToBaseVector(Reflex::Type const& possible_ref_vector,
00078                      Reflex::Type& value_type);
00079 
00080   void checkDictionaries(std::string const& name, bool noComponents = false);
00081   StringSet& missingTypes();
00082 
00083   void public_base_classes(const Reflex::Type& type,
00084                            std::vector<Reflex::Type>& baseTypes);
00085 
00093 
00094   // It would be nice to use void const* for the type of 'raw', but
00095   // the Reflex interface for creating an Object will not allow that.
00096 
00097   template <class T>
00098   T const*
00099   reflex_cast(void* raw, Reflex::Type const& dynamicType)
00100   {
00101     static const Reflex::Type 
00102       toType(Reflex::Type::ByTypeInfo(typeid(T)));
00103 
00104     Reflex::Object obj(dynamicType, raw);
00105     return static_cast<T const*>(obj.CastObject(toType).Address());
00106 
00107     // This alternative implementation of reflex_cast would allow us
00108     // to remove the compile-time depenency on Reflex/Type.h and
00109     // Reflex/Object.h, at the cost of some speed.
00110     //
00111     //     return static_cast<T const*>(reflex_pointer_adjust(raw, 
00112     //                                                 dynamicType,
00113     //                                                 typeid(T)));
00114   }
00115 
00116   // The following function should not now be used. It is here in case
00117   // we need to get rid of the compile-time dependency on
00118   // Reflex/Type.h and Reflex/Object.h introduced by the current
00119   // implementation of reflex_cast (above). If we have to be rid of
00120   // that dependency, the alternative implementation of reflex_cast
00121   // uses this function, at the cost of some speed: repeated lookups
00122   // of the same Reflex::Type object for the same type will have
00123   // to be made.
00124 
00133   
00134   void const*
00135   reflex_pointer_adjust(void* raw,
00136                         Reflex::Type const& dynamicType,
00137                         std::type_info const& toType);
00138   
00139 }
00140 
00141 #endif