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