]> git.saurik.com Git - wxWidgets.git/blame - include/wx/meta/movable.h
GetRegion is not needed anymore
[wxWidgets.git] / include / wx / meta / movable.h
CommitLineData
6712283c
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/meta/movable.h
3// Purpose: Test if a type is movable using memmove() etc.
4// Author: Vaclav Slavik
5// Created: 2008-01-21
6// RCS-ID: $Id$
7// Copyright: (c) 2008 Vaclav Slavik
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_META_MOVABLE_H_
12#define _WX_META_MOVABLE_H_
13
14#include "wx/defs.h"
15#include "wx/string.h" // for wxIsMovable<wxString> specialization
16
40e01f4b
VZ
17// This macro declares something called "value" inside a class declaration.
18//
19// It has to be used because VC6 doesn't handle initialization of the static
20// variables in the class declaration itself while BCC5.82 doesn't understand
21// enums (it compiles the template fine but can't use it later)
22#if defined(__VISUALC__) && !wxCHECK_VISUALC_VERSION(7)
23 #define wxDEFINE_TEMPLATE_BOOL_VALUE(val) enum { value = val }
24#else
25 #define wxDEFINE_TEMPLATE_BOOL_VALUE(val) static const bool value = val
26#endif
27
6712283c
VS
28// Helper to decide if an object of type T is "movable", i.e. if it can be
29// copied to another memory location using memmove() or realloc() C functions.
30// C++ only gurantees that POD types (including primitive types) are
31// movable.
32template<typename T>
33struct wxIsMovable
34{
40e01f4b 35 wxDEFINE_TEMPLATE_BOOL_VALUE(false);
6712283c
VS
36};
37
38// Macro to add wxIsMovable<T> specialization for given type that marks it
39// as movable:
40#define WX_DECLARE_TYPE_MOVABLE(type) \
41 template<> struct wxIsMovable<type> \
42 { \
40e01f4b 43 wxDEFINE_TEMPLATE_BOOL_VALUE(true); \
6712283c
VS
44 };
45
46WX_DECLARE_TYPE_MOVABLE(bool)
47WX_DECLARE_TYPE_MOVABLE(unsigned char)
48WX_DECLARE_TYPE_MOVABLE(signed char)
49WX_DECLARE_TYPE_MOVABLE(unsigned int)
50WX_DECLARE_TYPE_MOVABLE(signed int)
51WX_DECLARE_TYPE_MOVABLE(unsigned short int)
52WX_DECLARE_TYPE_MOVABLE(signed short int)
53WX_DECLARE_TYPE_MOVABLE(signed long int)
54WX_DECLARE_TYPE_MOVABLE(unsigned long int)
55WX_DECLARE_TYPE_MOVABLE(float)
56WX_DECLARE_TYPE_MOVABLE(double)
57WX_DECLARE_TYPE_MOVABLE(long double)
58#if wxWCHAR_T_IS_REAL_TYPE
59WX_DECLARE_TYPE_MOVABLE(wchar_t)
60#endif
61#ifdef wxLongLong_t
62WX_DECLARE_TYPE_MOVABLE(wxLongLong_t)
63WX_DECLARE_TYPE_MOVABLE(wxULongLong_t)
64#endif
65
28f0592c
VS
66// Visual C++ 6.0 can't compile partial template specializations and as this is
67// only an optimization, we can live with pointers not being recognized as
68// movable types under VC6
7ca73541 69#if !defined(__VISUALC__) || wxCHECK_VISUALC_VERSION(7)
28f0592c 70
6712283c
VS
71// pointers are movable:
72template<typename T>
73struct wxIsMovable<T*>
74{
40e01f4b 75 static const bool value = true;
6712283c 76};
40e01f4b 77
6712283c
VS
78template<typename T>
79struct wxIsMovable<const T*>
80{
40e01f4b 81 static const bool value = true;
6712283c
VS
82};
83
d05b30e4 84#endif // !VC++ < 7
28f0592c 85
6712283c 86// Our implementation of wxString is written in such way that it's safe to move
68482dc5
VZ
87// it around (unless position cache is used which unfortunately breaks this).
88// OTOH, we don't know anything about std::string.
6712283c
VS
89// (NB: we don't put this into string.h and choose to include wx/string.h from
90// here instead so that rarely-used wxIsMovable<T> code isn't included by
91// everything)
68482dc5 92#if !wxUSE_STL && !wxUSE_STRING_POS_CACHE
6712283c
VS
93WX_DECLARE_TYPE_MOVABLE(wxString)
94#endif
95
6712283c 96#endif // _WX_META_MOVABLE_H_