[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

vigra/memory.hxx |

    00001 /************************************************************************/
    00002 /*                                                                      */
    00003 /*         Copyright 2002-2003 by Ullrich Koethe, Hans Meine            */
    00004 /*                                                                      */
    00005 /*    This file is part of the VIGRA computer vision library.           */
    00006 /*    The VIGRA Website is                                              */
    00007 /*        http://hci.iwr.uni-heidelberg.de/vigra/                       */
    00008 /*    Please direct questions, bug reports, and contributions to        */
    00009 /*        ullrich.koethe@iwr.uni-heidelberg.de    or                    */
    00010 /*        vigra@informatik.uni-hamburg.de                               */
    00011 /*                                                                      */
    00012 /*    Permission is hereby granted, free of charge, to any person       */
    00013 /*    obtaining a copy of this software and associated documentation    */
    00014 /*    files (the "Software"), to deal in the Software without           */
    00015 /*    restriction, including without limitation the rights to use,      */
    00016 /*    copy, modify, merge, publish, distribute, sublicense, and/or      */
    00017 /*    sell copies of the Software, and to permit persons to whom the    */
    00018 /*    Software is furnished to do so, subject to the following          */
    00019 /*    conditions:                                                       */
    00020 /*                                                                      */
    00021 /*    The above copyright notice and this permission notice shall be    */
    00022 /*    included in all copies or substantial portions of the             */
    00023 /*    Software.                                                         */
    00024 /*                                                                      */
    00025 /*    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND    */
    00026 /*    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES   */
    00027 /*    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND          */
    00028 /*    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT       */
    00029 /*    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,      */
    00030 /*    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING      */
    00031 /*    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR     */
    00032 /*    OTHER DEALINGS IN THE SOFTWARE.                                   */
    00033 /*                                                                      */
    00034 /************************************************************************/
    00035
    00036 #ifndef VIGRA_MEMORY_HXX
    00037 #define VIGRA_MEMORY_HXX
    00038
    00039 #include "metaprogramming.hxx"
    00040
    00041 namespace vigra {
    00042
    00043 enum SkipInitializationTag { SkipInitialization};
    00044
    00045 template<class T>
    00046 struct CanSkipInitialization
    00047 {
    00048     typedef typename TypeTraits<T>::isBuiltinType type;
    00049     static const bool value = type::asBool;
    00050 };
    00051
    00052 namespace detail {
    00053
    00054 // differs from std::uninitialized_copy by explicit type conversion
    00055 template <class Src, class Dest>
    00056 Dest uninitializedCopy(Src s, Src end, Dest d)
    00057 {
    00058     typedef typename std::iterator_traits<Dest>::value_type T;
    00059     for(; s != end; ++s, ++d)
    00060         new(d) T(static_cast<T const &>(*s));
    00061     return d;
    00062 }
    00063
    00064 template <class T>
    00065 inline void destroy_n(T * /* p */, std::ptrdiff_t /* n */, VigraTrueType /* isPOD */)
    00066 {
    00067 }
    00068
    00069 template <class T>
    00070 inline void destroy_n(T * p, std::ptrdiff_t n, VigraFalseType /* isPOD */)
    00071 {
    00072     T * end = p + n;
    00073     for(; p != end; ++p)
    00074         p->~T();
    00075 }
    00076
    00077 template <class T>
    00078 inline void destroy_n(T * p, std::ptrdiff_t n)
    00079 {
    00080     destroy_n(p, n, typename TypeTraits<T>::isPOD());
    00081 }
    00082
    00083 /********************************************************************/
    00084
    00085 // g++ 2.95 has std::destroy() in the STL
    00086 #if !defined(__GNUC__) ||  __GNUC__ >= 3
    00087
    00088 template <class T>
    00089 inline void destroy(T * p, VigraTrueType /* isPOD */)
    00090 {
    00091 }
    00092
    00093 template <class T>
    00094 inline void destroy(T * p, VigraFalseType /* isPOD */)
    00095 {
    00096     p->~T();
    00097 }
    00098
    00099 template <class T>
    00100 inline void destroy(T * p)
    00101 {
    00102     destroy(p, typename TypeTraits<T>::isPOD());
    00103 }
    00104
    00105 #else
    00106
    00107 } } // namespace vigra::detail
    00108
    00109 #include <memory>
    00110
    00111 namespace vigra { namespace detail {
    00112
    00113 using std::destroy;
    00114
    00115 #endif
    00116
    00117 } } // namespace vigra::detail
    00118
    00119 #endif // VIGRA_MEMORY_HXX

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python vigra 1.9.0 (Tue Nov 6 2012)