EnumBuilder.h

Go to the documentation of this file.
00001 // @(#)root/reflex:$Id: EnumBuilder.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_EnumBuilder
00013 #define Reflex_EnumBuilder
00014 
00015 // Include files
00016 #include "Reflex/Builder/TypeBuilder.h"
00017 #include "Reflex/Member.h"
00018 
00019 namespace Reflex {
00020 // forward declarations
00021 class Enum;
00022 
00023 /**
00024  * @class EnumBuilder EnumBuilder.h Reflex/Builder/EnumBuilder.h
00025  * @author Stefan Roiser
00026  * @date 14/3/2005
00027  * @ingroup RefBld
00028  */
00029 class RFLX_API EnumBuilder {
00030 public:
00031    /** constructor */
00032    EnumBuilder(const char* name,
00033                const std::type_info & ti,
00034                unsigned int modifiers = 0);
00035 
00036 
00037    /** destructor */
00038    virtual ~EnumBuilder();
00039 
00040 
00041    /**
00042     * AddProperty will add a PropertyNth to the PropertyNth stack
00043     * which will be emptied with the next enum / item build
00044     * @param  key the PropertyNth key
00045     * @param  value the value of the PropertyNth
00046     * @return a reference to the building class
00047     */
00048    EnumBuilder& AddItem(const char* nam,
00049                         long value);
00050 
00051 
00052    /**
00053     * AddProperty will add a PropertyNth
00054     * @param  key the PropertyNth key
00055     * @param  value the value of the PropertyNth
00056     */
00057    EnumBuilder& AddProperty(const char* key,
00058                             Any value);
00059 
00060 
00061    /**
00062     * AddProperty will add a PropertyNth
00063     * @param  key the PropertyNth key
00064     * @param  value the value of the PropertyNth
00065     */
00066    EnumBuilder& AddProperty(const char* key,
00067                             const char* value);
00068 
00069 
00070    /*
00071     * ToType will return the currently produced Type (class)
00072     * @return the type currently being built
00073     */
00074    Type ToType();
00075 
00076 private:
00077    /** current enum being built */
00078    Enum* fEnum;
00079 
00080    /** last added enum item */
00081    Member fLastMember;
00082 
00083 };    // class EnumBuilder
00084 
00085 
00086 /**
00087  * @class EnumBuilder EnumBuilder.h Reflex/Builder/EnumBuilder.h
00088  * @author Stefan Roiser
00089  * @ingroup RefBld
00090  * @date 30/3/2004
00091  */
00092 template <typename T>
00093 class EnumBuilderT  {
00094 public:
00095    /** constructor */
00096    EnumBuilderT(unsigned int modifiers = 0);
00097 
00098 
00099    /** constructor */
00100    EnumBuilderT(const char* nam,
00101                 unsigned int modifiers = 0);
00102 
00103 
00104    /** destructor */
00105    virtual ~EnumBuilderT() {}
00106 
00107 
00108    /**
00109     * AddItem add a new item in the enum
00110     * @param  Name item Name
00111     * @param  value the value of the item
00112     * @return a reference to the building class
00113     */
00114    EnumBuilderT& AddItem(const char* nam,
00115                          long value);
00116 
00117 
00118    /**
00119     * AddProperty will add a PropertyNth to the PropertyNth stack
00120     * which will be emptied with the next enum / item build
00121     * @param  key the PropertyNth key
00122     * @param  value the value of the PropertyNth
00123     * @return a reference to the building class
00124     */
00125    template <typename P>
00126    EnumBuilderT& AddProperty(const char* key,
00127                              P value);
00128 
00129 
00130    /*
00131     * ToType will return the currently produced Type (class)
00132     * @return the type currently being built
00133     */
00134    Type ToType();
00135 
00136 private:
00137    /** the enums and values */
00138    EnumBuilder fEnumBuilderImpl;
00139 
00140 };    // class EnumBuilder
00141 
00142 } // namespace Reflex
00143 
00144 //-------------------------------------------------------------------------------
00145 template <typename T>
00146 inline Reflex::EnumBuilderT<T>::EnumBuilderT(unsigned int modifiers)
00147 //-------------------------------------------------------------------------------
00148    : fEnumBuilderImpl(Tools::Demangle(typeid(T)).c_str(),
00149                       typeid(T),
00150                       modifiers) {
00151 }
00152 
00153 
00154 //-------------------------------------------------------------------------------
00155 template <typename T>
00156 inline Reflex::EnumBuilderT<T>::EnumBuilderT(const char* nam,
00157                                              unsigned int modifiers)
00158 //-------------------------------------------------------------------------------
00159    : fEnumBuilderImpl(nam,
00160                       typeid(UnknownType),
00161                       modifiers) {
00162 }
00163 
00164 
00165 //-------------------------------------------------------------------------------
00166 template <typename T>
00167 inline Reflex::EnumBuilderT<T>&
00168 Reflex::EnumBuilderT<T
00169 >::AddItem(const char* nam,
00170            long value) {
00171 //-------------------------------------------------------------------------------
00172    fEnumBuilderImpl.AddItem(nam, value);
00173    return *this;
00174 }
00175 
00176 
00177 //-------------------------------------------------------------------------------
00178 template <typename T> template <typename P>
00179 inline Reflex::EnumBuilderT<T>&
00180 Reflex::EnumBuilderT<T
00181 >::AddProperty(const char* key,
00182                P value) {
00183 //-------------------------------------------------------------------------------
00184    fEnumBuilderImpl.AddProperty(key, value);
00185    return *this;
00186 }
00187 
00188 
00189 //-------------------------------------------------------------------------------
00190 template <typename T> inline Reflex::Type
00191 Reflex::EnumBuilderT<T
00192 >::ToType() {
00193 //-------------------------------------------------------------------------------
00194    return fEnumBuilderImpl.ToType();
00195 }
00196 
00197 
00198 #endif // Reflex_EnumBuilder

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