Aegis  4.25.D505
/home/archives/aegis/branch.4/branch.25/delta28933.505/libaegis/introspector/time.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_TIME_H
00020 #define LIBAEGIS_INTROSPECTOR_TIME_H
00021 
00022 #include <libaegis/introspector.h>
00023 #include <libaegis/output.h>
00024 
00029 class introspector_time:
00030     public introspector
00031 {
00032 public:
00036     virtual ~introspector_time();
00037 
00038     class adapter
00039     {
00040     public:
00041         typedef aegis_shared_ptr<adapter> pointer;
00042         virtual ~adapter(){}
00043     protected:
00044         adapter(){}
00045     public:
00046         virtual void set(time_t) = 0;
00047         virtual bool is_set() const = 0;
00048     private:
00049         adapter(const adapter &rhs);
00050         adapter &operator=(const adapter &rhs);
00051     };
00052 
00053     template <class T>
00054     class adapter_by_method:
00055         public adapter
00056     {
00057     public:
00058         virtual
00059         ~adapter_by_method()
00060         {
00061         }
00062 
00063     private:
00064         adapter_by_method(T *a_obj, void (T::*a_set)(time_t),
00065                 bool (T::*a_is_set)() const) :
00066             obj(a_obj),
00067             set_method(a_set),
00068             is_set_method(a_is_set)
00069         {
00070         }
00071 
00072     public:
00073         static pointer
00074         create(T *ao, void (T::*as)(time_t), bool (T::*ais)() const)
00075         {
00076             return pointer(new adapter_by_method(ao, as, ais));
00077         }
00078 
00079     protected:
00080         void
00081         set(time_t x)
00082         {
00083             (obj->*set_method)(x);
00084         }
00085 
00086         bool
00087         is_set()
00088             const
00089         {
00090             return (obj->*is_set_method)();
00091         }
00092 
00093     private:
00094         T *obj;
00095         void (T::*set_method)(time_t);
00096         bool (T::*is_set_method)() const;
00097 
00098         adapter_by_method();
00099         adapter_by_method(const adapter_by_method &);
00100         adapter_by_method &operator=(const adapter_by_method &);
00101     };
00102 
00103 private:
00111     introspector_time(const adapter::pointer &how);
00112 
00113 public:
00121     static pointer create(const adapter::pointer &how);
00122 
00136     static void write(const output::pointer &op, const nstring &name,
00137         time_t value, bool show_if_default = false);
00138 
00152     static void write_xml(const output::pointer &op, const nstring &name,
00153         time_t value, bool show_if_default = false);
00154 
00155 protected:
00156     // See base class for documentation.
00157     void integer(long n);
00158 
00159     // See base class for documentation.
00160     void real(double n);
00161 
00162     // See base class for documentation.
00163     nstring get_name() const;
00164 
00165 private:
00170     adapter::pointer how;
00171 
00175     introspector_time();
00176 
00180     introspector_time(const introspector_time &);
00181 
00185     introspector_time &operator=(const introspector_time &);
00186 };
00187 
00188 #endif // LIBAEGIS_INTROSPECTOR_TIME_H