|
Aegis
4.25.D505
|
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_STRUCTURE_H 00020 #define LIBAEGIS_INTROSPECTOR_STRUCTURE_H 00021 00022 #include <common/symtab/template.h> 00023 #include <libaegis/introspector.h> 00024 00028 class introspector_structure: 00029 public introspector 00030 { 00031 public: 00032 typedef aegis_shared_ptr<introspector_structure> pointer; 00033 00037 virtual ~introspector_structure(); 00038 00039 private: 00047 introspector_structure(const nstring &name); 00048 00049 public: 00057 static pointer create(const nstring &name); 00058 00059 class adapter 00060 { 00061 public: 00062 typedef aegis_shared_ptr<adapter> pointer; 00063 virtual ~adapter() {} 00064 virtual bool is_set() = 0; 00065 virtual bool redefinition_ok() = 0; 00066 virtual introspector::pointer introspector_factory() = 0; 00067 protected: 00068 adapter() {} 00069 private: 00070 adapter(const adapter &rhs); 00071 adapter &operator=(const adapter &rhs); 00072 }; 00073 00074 template <class T> 00075 class adapter_by_method: 00076 public adapter 00077 { 00078 public: 00079 ~adapter_by_method() {} 00080 00081 private: 00082 adapter_by_method(T *a_obj, introspector::pointer (T::*a_fac)(), 00083 bool (T::*a_isset)() const) : 00084 obj(a_obj), 00085 fac(a_fac), 00086 isset(a_isset) 00087 { 00088 } 00089 00090 public: 00091 static pointer 00092 create(T *a_obj, introspector::pointer (T::*a_fac)(), 00093 bool (T::*a_isset)() const) 00094 { 00095 return pointer(new adapter_by_method(a_obj, a_fac, a_isset)); 00096 } 00097 00098 protected: 00099 // See base class for documentation. 00100 introspector::pointer 00101 introspector_factory() 00102 { 00103 return (obj->*fac)(); 00104 } 00105 00106 // See base class for documentation. 00107 bool 00108 is_set() 00109 { 00110 return (obj->*isset)(); 00111 } 00112 00113 // See base class for documentation. 00114 bool 00115 redefinition_ok() 00116 { 00117 return false; 00118 } 00119 00120 private: 00121 T *obj; 00122 introspector::pointer (T::*fac)(); 00123 bool (T::*isset)() const; 00124 }; 00125 00135 void register_member(const nstring &name, const adapter::pointer &factory); 00136 00137 protected: 00138 // See base class for documentation. 00139 nstring get_name() const; 00140 00141 // See base class for documentation. 00142 introspector::pointer field(const nstring &name); 00143 00144 private: 00149 nstring name; 00150 00155 symtab<adapter::pointer> members; 00156 00160 introspector_structure(); 00161 00165 introspector_structure(const introspector_structure &); 00166 00170 introspector_structure &operator=(const introspector_structure &); 00171 }; 00172 00173 #endif // LIBAEGIS_INTROSPECTOR_STRUCTURE_H
1.7.6.1