Audacity 3.2.0
wxFileNameWrapper.h
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5wxFileNameWrapper.h
6
7Paul Licameli
8
9**********************************************************************/
10
11#ifndef __AUDACITY_WXFILENAMEWRAPPER__
12#define __AUDACITY_WXFILENAMEWRAPPER__
13
14class wxArrayString;
15
16#include <wx/filename.h> // to inherit
17
18// The wxFileName does not have a move constructor.
19// So add one to it, so that it passes around by value more quickly.
20class wxFileNameWrapper : public wxFileName
21{
22public:
23 using wxFileName::wxFileName;
24
25 explicit
26 wxFileNameWrapper(const wxFileName &that)
27 : wxFileName(that)
28 {}
29
30 wxFileNameWrapper() = default;
31 wxFileNameWrapper(const wxFileNameWrapper &that) = default;
33
35 {
36 if (this != &that) {
37#if 0
38 // Awful hack number 1 makes gcc 5 choke
39 enum : size_t { Size = sizeof(*this) };
40 // Do it bitwise.
41 // std::aligned_storage_t<Size> buffer;
42 char buffer[Size];
43 memcpy(&buffer, this, Size);
44 memcpy(this, &that, Size);
45 memcpy(&that, &buffer, Size);
46#else
47 // Awful hack number 2 relies on knowing the class layout
48 // This is the less evil one but watch out for redefinition of the base class
49 struct Contents
50 {
51 void swap(Contents &that) {
52 m_volume.swap(that.m_volume);
53 m_dirs.swap(that.m_dirs);
54 m_name.swap(that.m_name);
55 m_ext.swap(that.m_ext);
56 std::swap(m_relative, that.m_relative);
57 std::swap(m_hasExt, that.m_hasExt);
58 std::swap(m_dontFollowLinks, that.m_dontFollowLinks);
59 };
60
61 wxString m_volume;
62 wxArrayString m_dirs;
63 wxString m_name, m_ext;
64 bool m_relative;
65 bool m_hasExt;
66 bool m_dontFollowLinks;
67 };
68
69 reinterpret_cast<Contents*>(this)->swap
70 (*reinterpret_cast<Contents*>(&that));
71#endif
72 }
73 }
74
75 // Define move copy and assignment in terms of swap
77 {
78 swap(that);
79 }
80
82 {
83 if (this != &that) {
84 Clear();
85 swap(that);
86 }
87 return *this;
88 }
89};
90
91#endif
92
void swap(wxFileNameWrapper &that)
wxFileNameWrapper(const wxFileNameWrapper &that)=default
wxFileNameWrapper & operator=(const wxFileNameWrapper &that)=default
wxFileNameWrapper()=default
wxFileNameWrapper(wxFileNameWrapper &&that)
wxFileNameWrapper(const wxFileName &that)
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:634
SizeType< float > Size
Alias for SizeType<float>
Definition: Size.h:174