Aegis  4.25.D505
/home/archives/aegis/branch.4/branch.25/delta28933.505/libaegis/introspector/enumeration.h
Go to the documentation of this file.
00001 //
00002 // aegis - project change supervisor
00003 // Copyright (C) 2008 Peter Miller
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or (at
00008 // your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License along
00016 // with this program. If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 
00019 #ifndef LIBAEGIS_INTROSPECTOR_ENUMERATION_H
00020 #define LIBAEGIS_INTROSPECTOR_ENUMERATION_H
00021 
00022 #include <common/nstring.h>
00023 #include <common/symtab/template.h>
00024 
00025 #include <libaegis/introspector.h>
00026 
00031 class introspector_enumeration:
00032     public introspector
00033 {
00034 public:
00038     virtual ~introspector_enumeration();
00039 
00046     class adapter
00047     {
00048     public:
00049         typedef aegis_shared_ptr<adapter> pointer;
00050 
00051         virtual ~adapter() {}
00052 
00053     protected:
00054         adapter() {}
00055 
00056     public:
00057         virtual void set(int x) = 0;
00058         virtual bool is_set() = 0;
00059 
00060     private:
00061         adapter(const adapter &rhs);
00062         adapter &operator=(const adapter &rhs);
00063     };
00064 
00069     template <typename T>
00070     class adapter_by_reference:
00071         public adapter
00072     {
00073     public:
00074         virtual
00075         ~adapter_by_reference()
00076         {
00077         }
00078 
00079     private:
00080         adapter_by_reference(T &arg) :
00081             where(arg)
00082         {
00083         }
00084 
00085     public:
00086         static pointer
00087         create(T &arg)
00088         {
00089             return pointer(new adapter_by_reference(arg));
00090         }
00091 
00092     protected:
00093         void
00094         set(int x)
00095         {
00096             where = T(x);
00097         }
00098 
00099         bool
00100         is_set()
00101         {
00102             return false;
00103         }
00104 
00105     private:
00106         T &where;
00107 
00108         adapter_by_reference();
00109         adapter_by_reference(const adapter_by_reference &rhs);
00110         adapter_by_reference &operator=(const adapter_by_reference &rhs);
00111     };
00112 
00118     template <class C, typename E>
00119     class adapter_by_method:
00120         public adapter
00121     {
00122     public:
00123         virtual
00124         ~adapter_by_method()
00125         {
00126         }
00127 
00128     private:
00129         adapter_by_method(C *a_obj, void (C::*a_set)(E),
00130                 bool (C::*a_isset)() const) :
00131             obj(a_obj),
00132             set_method(a_set),
00133             is_set_method(a_isset)
00134         {
00135         }
00136 
00137     public:
00138         static pointer
00139         create(C *a_obj, void (C::*a_set)(E), bool (C::*a_is_set)() const)
00140         {
00141             return pointer(new adapter_by_method(a_obj, a_set, a_is_set));
00142         }
00143 
00144     protected:
00145         void
00146         set(int x)
00147         {
00148             (obj->*set_method)(E(x));
00149         }
00150 
00151         bool
00152         is_set()
00153         {
00154             return (obj->*is_set_method)();
00155         }
00156 
00157     private:
00158         C *obj;
00159         void (C::*set_method)(E value);
00160         bool (C::*is_set_method)() const;
00161 
00162         adapter_by_method();
00163         adapter_by_method(const adapter_by_method &rhs);
00164         adapter_by_method &operator=(const adapter_by_method &rhs);
00165     };
00166 
00177     static void report_init(const char **names, size_t len);
00178 
00179 protected:
00189     introspector_enumeration(const nstring &name, const adapter::pointer &how);
00190 
00191     // See base class for documentation.
00192     void enumeration(const nstring &name);
00193 
00194     // See base class for documentation.
00195     nstring get_name() const;
00196 
00197 private:
00202     nstring name;
00203 
00208     const adapter::pointer &how;
00209 
00214     symtab<int> members;
00215 
00216 protected:
00220     introspector_enumeration();
00221 
00231     void register_tags(const char **names, size_t size);
00232 
00233 private:
00237     introspector_enumeration(const introspector_enumeration &);
00238 
00242     introspector_enumeration &operator=(const introspector_enumeration &);
00243 };
00244 
00245 #endif // LIBAEGIS_INTROSPECTOR_ENUMERATION_H