Audacity 3.2.0
Identifier.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 Identifier.h
6
7 Paul Licameli split from Types.h
8
9 **********************************************************************/
10
11#ifndef __AUDACITY_IDENTIFIER__
12#define __AUDACITY_IDENTIFIER__
13
14#include <vector>
15#include <wx/string.h>
16
18
21class STRINGS_API Identifier
22{
23public:
24
25 Identifier() = default;
26
28 Identifier(const wxString &str) : value{ str } {}
29
31 Identifier(const wxChar *str) : value{ str } {}
32
34 Identifier(const char *str) : value{ str } {}
35
36 // Copy construction and assignment
37 Identifier( const Identifier & ) = default;
38 Identifier &operator = ( const Identifier& ) = default;
39
40 // Move construction and assignment
41 Identifier( wxString && str )
42 { value.swap( str ); }
44 { swap( id ); }
45 Identifier &operator= ( Identifier&& id )
46 {
47 if ( this != &id )
48 value.clear(), swap( id );
49 return *this;
50 }
51
52 // Implements moves
53 void swap( Identifier &id ) { value.swap( id.value ); }
54
56
58 explicit
59 Identifier(std::initializer_list<Identifier> components, wxChar separator);
60
61 bool empty() const { return value.empty(); }
62 size_t size() const { return value.size(); }
63 size_t length() const { return value.length(); }
64
66 const wxString &GET() const { return value; }
67
68 std::vector< Identifier > split( wxChar separator ) const;
69
70private:
71 wxString value;
72};
73
75inline bool operator == ( const Identifier &x, const Identifier &y )
76{ return x.GET() == y.GET(); }
77
78inline bool operator != ( const Identifier &x, const Identifier &y )
79{ return !(x == y); }
80
81inline bool operator < ( const Identifier &x, const Identifier &y )
82{ return x.GET() < y.GET(); }
83
84inline bool operator > ( const Identifier &x, const Identifier &y )
85{ return y < x; }
86
87inline bool operator <= ( const Identifier &x, const Identifier &y )
88{ return !(y < x); }
89
90inline bool operator >= ( const Identifier &x, const Identifier &y )
91{ return !(x < y); }
92
93namespace std
94{
95 template<> struct hash< Identifier > {
96 size_t operator () ( const Identifier &id ) const // noexcept
97 { return hash<wxString>{}( id.GET() ); }
98 };
99}
100
102inline bool wxFromString(const wxString& str, Identifier *id)
103 { if (id) { *id = str; return true; } else return false; }
104
106inline wxString wxToString( const Identifier& str ) { return str.GET(); }
107
109
111template<typename Tag, bool CaseSensitive = true >
113{
114public:
115
116 using TagType = Tag;
117
119 TaggedIdentifier() = default;
120
129
131 template< typename Tag2, bool b >
134 template< typename Tag2, bool b >
137 template< typename Tag2, bool b >
138 TaggedIdentifier& operator= ( const TaggedIdentifier<Tag2, b>& ) PROHIBITED;
140 template< typename Tag2, bool b >
141 TaggedIdentifier& operator= ( TaggedIdentifier<Tag2, b>&& ) PROHIBITED;
142
146
148 template<typename String, typename = typename String::TagType>
149 String CONVERT() const
150 { return String{ this->GET() }; }
151};
152
156template< typename Tag1, typename Tag2, bool b1, bool b2 >
157inline bool operator == (
159{
160 static_assert( std::is_same_v< Tag1, Tag2 > && b1 == b2,
161 "TaggedIdentifiers with different tags or sensitivity are not comparable" );
162 // This test should be eliminated at compile time:
163 if ( b1 )
164 return x.GET(). Cmp ( y.GET() ) == 0;
165 else
166 return x.GET(). CmpNoCase ( y.GET() ) == 0;
167}
168
169template< typename Tag1, typename Tag2, bool b1, bool b2 >
170inline bool operator != (
172{ return !(x == y); }
173
174template< typename Tag1, typename Tag2, bool b1, bool b2 >
175inline bool operator < (
177{
178 static_assert( std::is_same_v< Tag1, Tag2 > && b1 == b2,
179 "TaggedIdentifiers with different tags or sensitivity are not comparable" );
180 // This test should be eliminated at compile time:
181 if ( b1 )
182 return x.GET(). Cmp ( y.GET() ) < 0;
183 else
184 return x.GET(). CmpNoCase ( y.GET() ) < 0;
185}
186
187template< typename Tag1, typename Tag2, bool b1, bool b2 >
188inline bool operator > (
190{ return y < x; }
191
192template< typename Tag1, typename Tag2, bool b1, bool b2 >
193inline bool operator <= (
195{ return !(y < x); }
196
197template< typename Tag1, typename Tag2, bool b1, bool b2 >
198inline bool operator >= (
200{ return !(x < y); }
201
202namespace std
203{
204 template<typename Tag, bool b > struct hash< TaggedIdentifier<Tag, b> >
205 : hash< Identifier > {};
206}
207
208/**************************************************************************/
214using PluginPath = wxString;
215using PluginPaths = std::vector< PluginPath >;
216
217// A key to be passed to wxConfigBase
218using RegistryPath = wxString;
219using RegistryPaths = std::vector< RegistryPath >;
220
221class wxArrayStringEx;
222
224using FileExtension = wxString;
226
227using FilePath = wxString;
229
230struct CommandIdTag;
233using CommandIDs = std::vector<CommandID>;
234
235struct ManualPageIDTag;
237
238#endif
239
#define str(a)
std::vector< PluginPath > PluginPaths
Definition: Identifier.h:215
bool operator<(const Identifier &x, const Identifier &y)
Definition: Identifier.h:81
wxString FileExtension
File extension, not including any leading dot.
Definition: Identifier.h:224
bool operator>=(const Identifier &x, const Identifier &y)
Definition: Identifier.h:90
wxString RegistryPath
Definition: Identifier.h:218
wxString wxToString(const Identifier &str)
This lets you pass Identifier into wxFileConfig::Write.
Definition: Identifier.h:106
std::vector< CommandID > CommandIDs
Definition: Identifier.h:233
bool operator==(const Identifier &x, const Identifier &y)
Comparisons of Identifiers are case-sensitive.
Definition: Identifier.h:75
bool operator!=(const Identifier &x, const Identifier &y)
Definition: Identifier.h:78
wxString PluginPath
type alias for identifying a Plugin supplied by a module, each module defining its own interpretation...
Definition: Identifier.h:214
std::vector< RegistryPath > RegistryPaths
Definition: Identifier.h:219
bool operator<=(const Identifier &x, const Identifier &y)
Definition: Identifier.h:87
bool wxFromString(const wxString &str, Identifier *id)
This lets you pass Identifier into wxFileConfig::Read.
Definition: Identifier.h:102
bool operator>(const Identifier &x, const Identifier &y)
Definition: Identifier.h:84
wxString FilePath
Definition: Project.h:20
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
Identifier(const Identifier &)=default
bool empty() const
Definition: Identifier.h:61
void swap(Identifier &id)
Definition: Identifier.h:53
Identifier(Identifier &&id)
Definition: Identifier.h:43
const wxString & GET() const
Explicit conversion to wxString, meant to be ugly-looking and demanding of a comment why it's correct...
Definition: Identifier.h:66
wxString value
Definition: Identifier.h:71
Identifier()=default
size_t length() const
Definition: Identifier.h:63
Identifier(const char *str)
Allow implicit conversion to this class, but not from.
Definition: Identifier.h:34
size_t size() const
Definition: Identifier.h:62
Identifier(const wxString &str)
Allow implicit conversion to this class, but not from.
Definition: Identifier.h:28
Identifier(const wxChar *str)
Allow implicit conversion to this class, but not from.
Definition: Identifier.h:31
Identifier(wxString &&str)
Definition: Identifier.h:41
Template generates different TaggedIdentifier classes that don't interconvert implicitly.
Definition: Identifier.h:113
TaggedIdentifier(const TaggedIdentifier< Tag2, b > &) PROHIBITED
Copy prohibited for other Tag classes or case sensitivity.
String CONVERT() const
Explicit conversion to another kind of TaggedIdentifier.
Definition: Identifier.h:149
TaggedIdentifier(TaggedIdentifier< Tag2, b > &&) PROHIBITED
Move prohibited for other Tag classes or case sensitivity.
TaggedIdentifier & operator=(const TaggedIdentifier &)=default
Copy allowed only for the same Tag class and case sensitivity.
TaggedIdentifier()=default
TaggedIdentifier(const TaggedIdentifier &)=default
Copy allowed only for the same Tag class and case sensitivity.
TaggedIdentifier(TaggedIdentifier &&)=default
Move allowed only for the same Tag class and case sensitivity.
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
wxArrayStringEx()=default
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:753
STL namespace.