movable.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. // Copyright: (c) 2008 Vaclav Slavik
  7. // Licence: wxWindows licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_META_MOVABLE_H_
  10. #define _WX_META_MOVABLE_H_
  11. #include "wx/meta/pod.h"
  12. #include "wx/string.h" // for wxIsMovable<wxString> specialization
  13. // Helper to decide if an object of type T is "movable", i.e. if it can be
  14. // copied to another memory location using memmove() or realloc() C functions.
  15. // C++ only gurantees that POD types (including primitive types) are
  16. // movable.
  17. template<typename T>
  18. struct wxIsMovable
  19. {
  20. wxDEFINE_TEMPLATE_BOOL_VALUE(wxIsPod<T>::value);
  21. };
  22. // Macro to add wxIsMovable<T> specialization for given type that marks it
  23. // as movable:
  24. #define WX_DECLARE_TYPE_MOVABLE(type) \
  25. template<> struct wxIsMovable<type> \
  26. { \
  27. wxDEFINE_TEMPLATE_BOOL_VALUE(true); \
  28. };
  29. // Our implementation of wxString is written in such way that it's safe to move
  30. // it around (unless position cache is used which unfortunately breaks this).
  31. // OTOH, we don't know anything about std::string.
  32. // (NB: we don't put this into string.h and choose to include wx/string.h from
  33. // here instead so that rarely-used wxIsMovable<T> code isn't included by
  34. // everything)
  35. #if !wxUSE_STD_STRING && !wxUSE_STRING_POS_CACHE
  36. WX_DECLARE_TYPE_MOVABLE(wxString)
  37. #endif
  38. #endif // _WX_META_MOVABLE_H_