// Copyright (c) 2005-2009 Hartmut Kaiser // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #if !defined(SAGA_C_ENGINE_UTIL_NOV_01_2007_0946AM) #define SAGA_C_ENGINE_UTIL_NOV_01_2007_0946AM #if defined(_MSC_VER) && (_MSC_VER >= 1200) #pragma once #endif #if !defined(__cplusplus) #error "This files needs to be compiled in C++ mode" #endif #include /////////////////////////////////////////////////////////////////////////////// // Definition of all types needed in the SAGA C language binding struct saga_object_impl {}; struct saga_context_impl {}; struct saga_session_impl {}; /////////////////////////////////////////////////////////////////////////////// struct saga_context_list_impl { std::vector data; }; /////////////////////////////////////////////////////////////////////////////// namespace saga { namespace c_bindings { /////////////////////////////////////////////////////////////////////////// template struct handle_traits; // no default specialization available template struct object_traits; // no default specialization available /////////////////////////////////////////////////////////////////////////// #define SAGA_HANDLE_TRAITS(t) \ template <> \ struct handle_traits \ { \ typedef saga::t type; \ }; \ \ template <> \ struct handle_traits \ { \ typedef saga::t const type; \ }; \ /**/ /////////////////////////////////////////////////////////////////////////// #define SAGA_OBJECT_TRAITS(t) \ template <> \ struct object_traits \ { \ typedef saga_ ## t type; \ }; \ \ template <> \ struct object_traits \ { \ typedef saga_ ## t ## _const type; \ }; \ /**/ /////////////////////////////////////////////////////////////////////////// #define SAGA_TRAITS(t) \ SAGA_HANDLE_TRAITS(t) \ SAGA_OBJECT_TRAITS(t) \ /**/ /////////////////////////////////////////////////////////////////////////// // definition of traits templates for all saga types SAGA_TRAITS(object) SAGA_TRAITS(session) SAGA_TRAITS(context) #undef SAGA_TRAITS #undef SAGA_OBJECT_TRAITS #undef SAGA_HANDLE_TRAITS /////////////////////////////////////////////////////////////////////////// template inline typename object_traits::type to_handle(T* p) { return reinterpret_cast::type>(p); } /////////////////////////////////////////////////////////////////////////// template inline typename handle_traits::type* from_handle(Handle h) { return reinterpret_cast::type*>(h); } /////////////////////////////////////////////////////////////////////////// template inline typename handle_traits::type* from_object_handle(saga_object h) { return reinterpret_cast::type*>(h); } /////////////////////////////////////////////////////////////////////////////// }} #endif