value_store.h
Go to the documentation of this file.
00001 //
00002 //  Copyright (c) Benjamin Kaufmann 2010
00003 //
00004 //  This is free software; you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation; either version 2 of the License, or
00007 //  (at your option) any later version. 
00008 // 
00009 //  This file is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this file; if not, write to the Free Software
00016 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 //
00018 //
00019 // NOTE: ProgramOptions is inspired by Boost.Program_options
00020 //       see: www.boost.org/libs/program_options
00021 //
00022 #ifndef PROGRAM_OPTIONS_VALUE_STORE_IMPL_H_INCLUDED
00023 #define PROGRAM_OPTIONS_VALUE_STORE_IMPL_H_INCLUDED
00024 
00025 #include <typeinfo>
00026 
00027 namespace detail {
00028 template <class T>
00029 struct VTable {
00030         static void clone(const void* o, void** out) { 
00031                 *out = new T(*static_cast<const T*>(o));
00032         }
00033         static void destroy(const void* o, void** out) { 
00034                 delete static_cast<const T*>(o);
00035                 *out = 0;
00036         }
00037         static void typeinfo(const void*, void** out)  { 
00038                 *out = const_cast<void*>( static_cast<const void*>(&typeid(T)) ); 
00039         }
00040         static vtable_type vtable_s;
00041 };
00042 template <class T>
00043 struct OptVTable {
00044         static void clone(const void* o, void** out) { 
00045                 new (&*out) T(*static_cast<const T*>(o));
00046         }
00047         static void destroy(const void* o, void** out) { 
00048                 static_cast<const T*>(o)->~T();
00049                 *out = 0;
00050         }
00051         static vtable_type vtable_s;
00052 };
00053 template <class T>
00054 vtable_type VTable<T>::vtable_s = {
00055           0
00056         , &VTable<T>::clone
00057         , &VTable<T>::destroy
00058         , &VTable<T>::typeinfo
00059 };
00060 template <class T>
00061 vtable_type OptVTable<T>::vtable_s = {
00062         (vcall_type)0x1
00063         , &OptVTable<T>::clone
00064         , &OptVTable<T>::destroy
00065         , &VTable<T>::typeinfo
00066 };
00067 template <bool> struct bool2type {};
00068 template <class T>
00069 inline vptr_type vtable_select(bool2type<0>, const T* = 0) { 
00070         return &VTable<T>::vtable_s;
00071 }
00072 template <class T>
00073 inline vptr_type vtable_select(bool2type<1>, const T* = 0) { 
00074         return &OptVTable<T>::vtable_s;
00075 }
00076 template <class T>
00077 inline vptr_type vtable(const T* x) { 
00078         return vtable_select(bool2type<sizeof(T)<=sizeof(void*)>(), x);
00079 }
00080 
00081 template <class T>
00082 inline vptr_type base_vtable(const T* x) {
00083         return vtable_select(bool2type<0>(), x);
00084 }
00085 
00086 }
00087 
00088 #endif


clasp
Author(s): Benjamin Kaufmann
autogenerated on Thu Aug 27 2015 12:41:40