2008-01-22 06:29:21 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/meta/movable.h
|
|
|
|
// Purpose: Test if a type is movable using memmove() etc.
|
|
|
|
// Author: Vaclav Slavik
|
|
|
|
// Created: 2008-01-21
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 2008 Vaclav Slavik
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_META_MOVABLE_H_
|
|
|
|
#define _WX_META_MOVABLE_H_
|
|
|
|
|
2010-06-14 11:12:37 -04:00
|
|
|
#include "wx/meta/pod.h"
|
2008-01-22 06:29:21 -05:00
|
|
|
#include "wx/string.h" // for wxIsMovable<wxString> specialization
|
|
|
|
|
|
|
|
// Helper to decide if an object of type T is "movable", i.e. if it can be
|
|
|
|
// copied to another memory location using memmove() or realloc() C functions.
|
|
|
|
// C++ only gurantees that POD types (including primitive types) are
|
|
|
|
// movable.
|
|
|
|
template<typename T>
|
|
|
|
struct wxIsMovable
|
|
|
|
{
|
2010-06-14 11:12:37 -04:00
|
|
|
wxDEFINE_TEMPLATE_BOOL_VALUE(wxIsPod<T>::value);
|
2008-01-22 06:29:21 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// Macro to add wxIsMovable<T> specialization for given type that marks it
|
|
|
|
// as movable:
|
|
|
|
#define WX_DECLARE_TYPE_MOVABLE(type) \
|
|
|
|
template<> struct wxIsMovable<type> \
|
|
|
|
{ \
|
2008-02-15 09:16:32 -05:00
|
|
|
wxDEFINE_TEMPLATE_BOOL_VALUE(true); \
|
2008-01-22 06:29:21 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// Our implementation of wxString is written in such way that it's safe to move
|
2008-08-28 15:19:11 -04:00
|
|
|
// it around (unless position cache is used which unfortunately breaks this).
|
|
|
|
// OTOH, we don't know anything about std::string.
|
2008-01-22 06:29:21 -05:00
|
|
|
// (NB: we don't put this into string.h and choose to include wx/string.h from
|
|
|
|
// here instead so that rarely-used wxIsMovable<T> code isn't included by
|
|
|
|
// everything)
|
2011-03-30 10:16:04 -04:00
|
|
|
#if !wxUSE_STD_STRING && !wxUSE_STRING_POS_CACHE
|
2008-01-22 06:29:21 -05:00
|
|
|
WX_DECLARE_TYPE_MOVABLE(wxString)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // _WX_META_MOVABLE_H_
|