ioproxy.h

Go to the documentation of this file.
00001 
00004 
00005 //
00006 // Copyright (c) 2000-2004 California Institute of Technology
00007 // Copyright (c) 2004-2007 University of Southern California
00008 // Rob Peters <rjpeters at usc dot edu>
00009 //
00010 // created: Wed Mar 22 21:41:38 2000
00011 // commit: $Id: ioproxy.h 10065 2007-04-12 05:54:56Z rjpeters $
00012 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/io/ioproxy.h $
00013 //
00014 // --------------------------------------------------------------------
00015 //
00016 // This file is part of GroovX.
00017 //   [http://ilab.usc.edu/rjpeters/groovx/]
00018 //
00019 // GroovX is free software; you can redistribute it and/or modify it
00020 // under the terms of the GNU General Public License as published by
00021 // the Free Software Foundation; either version 2 of the License, or
00022 // (at your option) any later version.
00023 //
00024 // GroovX is distributed in the hope that it will be useful, but
00025 // WITHOUT ANY WARRANTY; without even the implied warranty of
00026 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00027 // General Public License for more details.
00028 //
00029 // You should have received a copy of the GNU General Public License
00030 // along with GroovX; if not, write to the Free Software Foundation,
00031 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00032 //
00034 
00035 #ifndef GROOVX_IO_IOPROXY_H_UTC20050626084021_DEFINED
00036 #define GROOVX_IO_IOPROXY_H_UTC20050626084021_DEFINED
00037 
00038 #include "io/io.h"
00039 
00040 #include "nub/ref.h"
00041 
00042 #include "rutz/fstring.h"
00043 #include "rutz/demangle.h"
00044 
00045 #include <typeinfo>
00046 
00047 namespace io
00048 {
00049 
00050 //  #######################################################
00051 //  =======================================================
00052 
00054 
00061 template <class C>
00062 class proxy : public serializable
00063 {
00064 protected:
00065   proxy(C* ref) : serializable(), m_referand(ref) {}
00066   virtual ~proxy() throw() {}
00067 
00068 public:
00069   static nub::ref<serializable> make(C* ref)
00070     { return nub::ref<serializable>( new proxy(ref), nub::PRIVATE ); }
00071 
00072   virtual void read_from(io::reader& reader)
00073     { m_referand->C::read_from(reader); }
00074 
00075   virtual void write_to(io::writer& writer) const
00076     { m_referand->C::write_to(writer); }
00077 
00078   virtual io::version_id class_version_id() const
00079     { return m_referand->C::class_version_id(); }
00080 
00081   virtual rutz::fstring obj_typename() const
00082     { return rutz::demangled_name(typeid(C)); }
00083 
00084 private:
00085   proxy(const proxy&);
00086   proxy& operator=(const proxy&);
00087 
00088   nub::ref<C> m_referand;
00089 };
00090 
00091 template <class C>
00092 inline nub::ref<serializable> make_proxy(C* ref)
00093   { return proxy<C>::make(ref); }
00094 
00095 
00096 //  #######################################################
00097 //  =======================================================
00098 
00100 
00101 template <class C>
00102 class const_proxy : public serializable
00103 {
00104 protected:
00105   const_proxy(const C* ref) : serializable(), m_referand(const_cast<C*>(ref)) {}
00106   virtual ~const_proxy() throw() {}
00107 
00108 public:
00109   static nub::ref<const serializable> make(const C* ref)
00110     { return nub::ref<serializable>( new const_proxy(ref), nub::PRIVATE ); }
00111 
00112   virtual void read_from(io::reader& reader)
00113     { m_referand->C::read_from(reader); }
00114 
00115   virtual void write_to(io::writer& writer) const
00116     { m_referand->C::write_to(writer); }
00117 
00118   virtual io::version_id class_version_id() const
00119     { return m_referand->C::class_version_id(); }
00120 
00121   virtual rutz::fstring obj_typename() const
00122     { return rutz::demangled_name(typeid(C)); }
00123 
00124 private:
00125   const_proxy(const const_proxy&);
00126   const_proxy& operator=(const const_proxy&);
00127 
00128   nub::ref<C> m_referand;
00129 };
00130 
00131 template <class C>
00132 inline nub::ref<const serializable> make_const_proxy(const C* ref)
00133   { return const_proxy<C>::make(ref); }
00134 
00135 
00136 } // end namespace io
00137 
00138 static const char __attribute__((used)) vcid_groovx_io_ioproxy_h_utc20050626084021[] = "$Id: ioproxy.h 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00139 #endif // !GROOVX_IO_IOPROXY_H_UTC20050626084021_DEFINED

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:49:39 2008 by Doxygen version 1.5.5.