File: wxFileNameWrapper.h

package info (click to toggle)
audacity 3.7.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 125,252 kB
  • sloc: cpp: 358,238; ansic: 75,458; lisp: 7,761; sh: 3,410; python: 1,503; xml: 1,385; perl: 854; makefile: 122
file content (92 lines) | stat: -rw-r--r-- 2,502 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**********************************************************************

Audacity: A Digital Audio Editor

wxFileNameWrapper.h

Paul Licameli

**********************************************************************/

#ifndef __AUDACITY_WXFILENAMEWRAPPER__
#define __AUDACITY_WXFILENAMEWRAPPER__

class wxArrayString;

#include <wx/filename.h> // to inherit

// The wxFileName does not have a move constructor.
// So add one to it, so that it passes around by value more quickly.
class wxFileNameWrapper : public wxFileName
{
public:
     using wxFileName::wxFileName;

     explicit
      wxFileNameWrapper(const wxFileName &that)
      : wxFileName(that)
   {}

   wxFileNameWrapper() = default;
   wxFileNameWrapper(const wxFileNameWrapper &that) = default;
   wxFileNameWrapper &operator= (const wxFileNameWrapper &that) = default;

   void swap(wxFileNameWrapper &that)
   {
      if (this != &that) {
#if 0
         // Awful hack number 1 makes gcc 5 choke
         enum : size_t { Size = sizeof(*this) };
         // Do it bitwise.
         // std::aligned_storage_t<Size> buffer;
         char buffer[Size];
         memcpy(&buffer, this, Size);
         memcpy(this, &that, Size);
         memcpy(&that, &buffer, Size);
#else
         // Awful hack number 2 relies on knowing the class layout
         // This is the less evil one but watch out for redefinition of the base class
         struct Contents
         {
            void swap(Contents &that) {
               m_volume.swap(that.m_volume);
               m_dirs.swap(that.m_dirs);
               m_name.swap(that.m_name);
               m_ext.swap(that.m_ext);
               std::swap(m_relative, that.m_relative);
               std::swap(m_hasExt, that.m_hasExt);
               std::swap(m_dontFollowLinks, that.m_dontFollowLinks);
            };

            wxString        m_volume;
            wxArrayString   m_dirs;
            wxString        m_name, m_ext;
            bool            m_relative;
            bool            m_hasExt;
            bool            m_dontFollowLinks;
         };

         reinterpret_cast<Contents*>(this)->swap
            (*reinterpret_cast<Contents*>(&that));
#endif
      }
   }

   // Define move copy and assignment in terms of swap
   wxFileNameWrapper(wxFileNameWrapper &&that)
   {
      swap(that);
   }

   wxFileNameWrapper &operator= (wxFileNameWrapper &&that)
   {
      if (this != &that) {
         Clear();
         swap(that);
      }
      return *this;
   }
};

#endif