// // Copyright (c) 2010-2017 Benjamin Kaufmann // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. // // // NOTE: ProgramOptions is inspired by Boost.Program_options // see: www.boost.org/libs/program_options // #ifndef PROGRAM_OPTIONS_VALUE_STORE_IMPL_H_INCLUDED #define PROGRAM_OPTIONS_VALUE_STORE_IMPL_H_INCLUDED namespace detail { template struct VTable { static void clone(const void* o, void** out) { *out = new T(*static_cast(o)); } static void destroy(const void* o, void** out) { delete static_cast(o); *out = 0; } static void typeinfo(const void*, void** out) { *out = const_cast( static_cast(&typeid(T)) ); } static vtable_type vtable_s; }; template struct OptVTable { static void clone(const void* o, void** out) { new (&*out) T(*static_cast(o)); } static void destroy(const void* o, void** out) { static_cast(o)->~T(); *out = 0; } static vtable_type vtable_s; }; template vtable_type VTable::vtable_s = { 0 , &VTable::clone , &VTable::destroy , &VTable::typeinfo }; template vtable_type OptVTable::vtable_s = { (vcall_type)0x1 , &OptVTable::clone , &OptVTable::destroy , &VTable::typeinfo }; template struct bool2type {}; template inline vptr_type vtable_select(bool2type<0>, const T* = 0) { return &VTable::vtable_s; } template inline vptr_type vtable_select(bool2type<1>, const T* = 0) { return &OptVTable::vtable_s; } template inline vptr_type vtable(const T* x) { return vtable_select(bool2type(), x); } template inline vptr_type base_vtable(const T* x) { return vtable_select(bool2type<0>(), x); } } // namespace detail #endif