UnionBuilder.h

Go to the documentation of this file.
00001 // @(#)root/reflex:$Id: UnionBuilder.h 29288 2009-07-01 13:03:35Z axel $
00002 // Author: Stefan Roiser 2004
00003 
00004 // Copyright CERN, CH-1211 Geneva 23, 2004-2006, All rights reserved.
00005 //
00006 // Permission to use, copy, modify, and distribute this software for any
00007 // purpose is hereby granted without fee, provided that this copyright and
00008 // permissions notice appear in all copies and derivatives.
00009 //
00010 // This software is provided "as is" without express or implied warranty.
00011 
00012 #ifndef Reflex_UnionBuilder
00013 #define Reflex_UnionBuilder
00014 
00015 // Include files
00016 #include "Reflex/Builder/TypeBuilder.h"
00017 #include "Reflex/Member.h"
00018 
00019 namespace Reflex {
00020 // forward declarations
00021 class Union;
00022 class Type;
00023 
00024 /**
00025  * @class UnionBuilderImpl UnionBuilder.h Reflex/Builder/UnionBuilder.h
00026  * @author Stefan Roiser
00027  * @date 14/3/2005
00028  * @ingroup RefBld
00029  */
00030 class RFLX_API UnionBuilderImpl {
00031 public:
00032    /** constructor */
00033    UnionBuilderImpl(const char* nam, size_t size, const std::type_info & ti, unsigned int modifiers = 0, TYPE typ = UNION);
00034 
00035    /** destructor */
00036    virtual ~UnionBuilderImpl();
00037 
00038    /**
00039     * AddItem will add one union item
00040     * @param Name the Name of the union item
00041     * @param At the At of the union item
00042     */
00043    void AddItem(const char* nam,
00044                 const Type& typ);
00045 
00046    /** AddDataMember will add the information about one data
00047     * MemberAt of the union
00048     *
00049     * @param  Name of the data MemberAt
00050     * @param  At of the data MemberAt
00051     * @param  Offset of the data MemberAt
00052     * @param  modifiers the modifiers of the data MemberAt
00053     */
00054    void AddDataMember(const char* nam,
00055                       const Type& typ,
00056                       size_t offs,
00057                       unsigned int modifiers = 0);
00058 
00059    /** AddFunctionMember will add the information about one
00060     * function MemberAt of the union
00061     *
00062     * @param  Name of the function MemberAt
00063     * @param  At of the function MemberAt
00064     * @param  stubFP Stub function pointer for the function
00065     * @param  stubCxt Stub user context for the stub function
00066     * @param  params parameter names and default values (semi-colon separated)
00067     * @param  modifiers the modifiers of the function MemberAt
00068     */
00069    void AddFunctionMember(const char* nam,
00070                           const Type& typ,
00071                           StubFunction stubFP,
00072                           void* stubCtx = 0,
00073                           const char* params = 0,
00074                           unsigned int modifiers = 0);
00075 
00076    /**
00077     * AddProperty will add a PropertyNth to the PropertyNth stack
00078     * which will be emtpied with the next build of a union
00079     * or union item
00080     * @param  key the PropertyNth key
00081     * @param  value the value of the PropertyNth
00082     * @return a reference to the building class
00083     */
00084 
00085    void AddProperty(const char* key,
00086                     Any value);
00087    void AddProperty(const char* key,
00088                     const char* value);
00089 
00090    /** SetSizeOf will set the SizeOf property for this union.
00091     * It currently ignores all actual content.
00092     * @size Size of the union
00093     */
00094    void SetSizeOf(size_t size);
00095 
00096    /*
00097     * ToType will return the currently produced Type (class)
00098     * @return the type currently being built
00099     */
00100    Type ToType();
00101 
00102 protected:
00103    friend class UnionBuilder;
00104 
00105    /**
00106     * EnableCallback Enable or disable the callback call in the destructor
00107     * @param  enable true to enable callback call, false to disable callback call
00108     */
00109    void EnableCallback(const bool enable = true);
00110 
00111 private:
00112    /** the union currently being built */
00113    Union* fUnion;
00114 
00115    /** the last union item built */
00116    Member fLastMember;
00117 
00118    /** flag, fire callback in destructor */
00119    bool fCallbackEnabled;
00120 
00121 }; // class UnionBuilderImpl
00122 
00123 
00124 /**
00125  * @class UnionBuilder UnionBuilder.h Reflex/Builder/UnionBuilder.h
00126  * @author Stefan Roiser
00127  * @date 30/3/2004
00128  * @ingroup RefBld
00129  */
00130 class RFLX_API UnionBuilder {
00131 public:
00132    /** constructor */
00133    UnionBuilder(const char* nam, const std::type_info & ti, size_t size, unsigned int modifiers = 0, TYPE typ = UNION);
00134 
00135    /** destructor */
00136    virtual ~UnionBuilder();
00137 
00138    /**
00139     * AddItem will add one union item
00140     * @param Name the Name of the union item
00141     * @param At the At of the union item
00142     * @return a reference to the UnionBuilder
00143     */
00144    template <typename T> UnionBuilder& AddItem(const char* nam);
00145 
00146    /**
00147     * AddItem will add one union item
00148     * @param Name the Name of the union item
00149     * @param At the At of the union item
00150     * @return a reference to the UnionBuilder
00151     */
00152    UnionBuilder& AddItem(const char* nam,
00153                          const char* typ);
00154 
00155    /** AddDataMember will add the information about one data
00156     * MemberAt of the union
00157     *
00158     * @param  Name of the data MemberAt
00159     * @param  Offset of data MemberAt
00160     * @param  modifiers the modifiers of the data MemberAt
00161     * @return a reference to the UnionBuilder
00162     */
00163    template <class T> UnionBuilder& AddDataMember(const char* nam,
00164                                                   size_t offs,
00165                                                   unsigned int modifiers = 0);
00166    UnionBuilder& AddDataMember(const Type& typ,
00167                                const char* nam,
00168                                size_t offs,
00169                                unsigned int modifiers = 0);
00170 
00171    /** AddFunctionMember will add the information about one
00172     * function MemberAt of the union
00173     *
00174     * @param  Name of the function MemberAt
00175     * @param  function templated function MemberAt to extract At information
00176     * @param  stubFP Stub function pointer for the function
00177     * @param  stubCxt Stub user context for the stub function
00178     * @param  params parameter names and default values (semi-colon separated)
00179     * @param  modifiers the modifiers of the data MemberAt
00180     * @return a reference to the UnionBuilder
00181     */
00182    template <class F> UnionBuilder& AddFunctionMember(const char* nam,
00183                                                       StubFunction stubFP,
00184                                                       void* stubCtx = 0,
00185                                                       const char* params = 0,
00186                                                       unsigned int modifiers = 0);
00187    UnionBuilder& AddFunctionMember(const Type& typ,
00188                                    const char* nam,
00189                                    StubFunction stubFP,
00190                                    void* stubCtx = 0,
00191                                    const char* params = 0,
00192                                    unsigned int modifiers = 0);
00193 
00194    /**
00195     * AddProperty will add a PropertyNth to the PropertyNth stack
00196     * which will be emtpied with the next build of a union
00197     * or union item
00198     * @param  key the PropertyNth key
00199     * @param  value the value of the PropertyNth
00200     * @return a reference to the building class
00201     */
00202    template <typename P> UnionBuilder& AddProperty(const char* key,
00203                                                    P value);
00204 
00205    /** SetSizeOf will set the SizeOf property for this union.
00206     * It currently ignores all actual content.
00207     * @size Size of the union
00208     */
00209    UnionBuilder& SetSizeOf(size_t size);
00210 
00211    /*
00212     * ToType will return the currently produced Type (class)
00213     * @return the type currently being built
00214     */
00215    Type ToType();
00216 
00217 protected:
00218 #ifdef G__COMMON_H
00219    friend int::G__search_tagname(const char*, int);
00220 #endif
00221 
00222    /**
00223     * EnableCallback Enable or disable the callback call in the destructor
00224     * @param  enable true to enable callback call, false to disable callback call
00225     */
00226    UnionBuilder& EnableCallback(const bool enable = true);
00227 
00228 private:
00229    /** the union information */
00230    UnionBuilderImpl fUnionBuilderImpl;
00231 
00232 }; //class UnionBuilder
00233 
00234 } // namespace Reflex
00235 
00236 //-------------------------------------------------------------------------------
00237 template <typename T> Reflex::UnionBuilder&
00238 Reflex::UnionBuilder::AddItem(const char* nam) {
00239    // -- !!! Obsolete, do not use.
00240    fUnionBuilderImpl.AddItem(nam, TypeDistiller<T>::Get());
00241    return *this;
00242 }
00243 
00244 
00245 //______________________________________________________________________________
00246 template <typename T> Reflex::UnionBuilder&
00247 Reflex::UnionBuilder::AddDataMember(const char* nam,
00248                                     size_t offs,
00249                                     unsigned int modifiers /*= 0*/) {
00250    fUnionBuilderImpl.AddDataMember(nam, TypeDistiller<T>::Get(), offs, modifiers);
00251    return *this;
00252 }
00253 
00254 
00255 //______________________________________________________________________________
00256 template <typename F> Reflex::UnionBuilder&
00257 Reflex::UnionBuilder::AddFunctionMember(const char* nam,
00258                                         StubFunction stubFP,
00259                                         void* stubCtx /*= 0*/,
00260                                         const char* params /*= 0*/,
00261                                         unsigned int modifiers /*= 0*/) {
00262    fUnionBuilderImpl.AddFunctionMember(nam, FunctionDistiller<F>::Get(), stubFP, stubCtx, params, modifiers);
00263    return *this;
00264 }
00265 
00266 
00267 //______________________________________________________________________________
00268 template <typename P> Reflex::UnionBuilder&
00269 Reflex::UnionBuilder::AddProperty(const char* key,
00270                                   P value) {
00271    fUnionBuilderImpl.AddProperty(key, value);
00272    return *this;
00273 }
00274 
00275 
00276 #endif // Reflex_UnionBuilder

Generated on Tue Jul 5 14:25:49 2011 for ROOT_528-00b_version by  doxygen 1.5.1