OpenShot Library | libopenshot-audio 0.2.0
juce_Identifier.h
1
2/** @weakgroup juce_core-text
3 * @{
4 */
5/*
6 ==============================================================================
7
8 This file is part of the JUCE library.
9 Copyright (c) 2017 - ROLI Ltd.
10
11 JUCE is an open source library subject to commercial or open-source
12 licensing.
13
14 The code included in this file is provided under the terms of the ISC license
15 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16 To use, copy, modify, and/or distribute this software for any purpose with or
17 without fee is hereby granted provided that the above copyright notice and
18 this permission notice appear in all copies.
19
20 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 DISCLAIMED.
23
24 ==============================================================================
25*/
26
27namespace juce
28{
29
30//==============================================================================
31/**
32 Represents a string identifier, designed for accessing properties by name.
33
34 Comparing two Identifier objects is very fast (an O(1) operation), but creating
35 them can be slower than just using a String directly, so the optimal way to use them
36 is to keep some static Identifier objects for the things you use often.
37
38 @see NamedValueSet, ValueTree
39
40 @tags{Core}
41*/
43{
44public:
45 /** Creates a null identifier. */
46 Identifier() noexcept;
47
48 /** Creates an identifier with a specified name.
49 Because this name may need to be used in contexts such as script variables or XML
50 tags, it must only contain ascii letters and digits, or the underscore character.
51 */
52 Identifier (const char* name);
53
54 /** Creates an identifier with a specified name.
55 Because this name may need to be used in contexts such as script variables or XML
56 tags, it must only contain ascii letters and digits, or the underscore character.
57 */
58 Identifier (const String& name);
59
60 /** Creates an identifier with a specified name.
61 Because this name may need to be used in contexts such as script variables or XML
62 tags, it must only contain ascii letters and digits, or the underscore character.
63 */
65
66 /** Creates a copy of another identifier. */
67 Identifier (const Identifier& other) noexcept;
68
69 /** Creates a copy of another identifier. */
70 Identifier& operator= (const Identifier& other) noexcept;
71
72 /** Creates a copy of another identifier. */
73 Identifier (Identifier&& other) noexcept;
74
75 /** Creates a copy of another identifier. */
76 Identifier& operator= (Identifier&& other) noexcept;
77
78 /** Destructor */
79 ~Identifier() noexcept;
80
81 /** Compares two identifiers. This is a very fast operation. */
82 inline bool operator== (const Identifier& other) const noexcept { return name.getCharPointer() == other.name.getCharPointer(); }
83
84 /** Compares two identifiers. This is a very fast operation. */
85 inline bool operator!= (const Identifier& other) const noexcept { return name.getCharPointer() != other.name.getCharPointer(); }
86
87 /** Compares the identifier with a string. */
88 inline bool operator== (StringRef other) const noexcept { return name == other; }
89
90 /** Compares the identifier with a string. */
91 inline bool operator!= (StringRef other) const noexcept { return name != other; }
92
93 /** Compares the identifier with a string. */
94 inline bool operator< (StringRef other) const noexcept { return name < other; }
95
96 /** Compares the identifier with a string. */
97 inline bool operator<= (StringRef other) const noexcept { return name <= other; }
98
99 /** Compares the identifier with a string. */
100 inline bool operator> (StringRef other) const noexcept { return name > other; }
101
102 /** Compares the identifier with a string. */
103 inline bool operator>= (StringRef other) const noexcept { return name >= other; }
104
105 /** Returns this identifier as a string. */
106 const String& toString() const noexcept { return name; }
107
108 /** Returns this identifier's raw string pointer. */
109 operator String::CharPointerType() const noexcept { return name.getCharPointer(); }
110
111 /** Returns this identifier's raw string pointer. */
112 String::CharPointerType getCharPointer() const noexcept { return name.getCharPointer(); }
113
114 /** Returns this identifier as a StringRef. */
115 operator StringRef() const noexcept { return name; }
116
117 /** Returns true if this Identifier is not null */
118 bool isValid() const noexcept { return name.isNotEmpty(); }
119
120 /** Returns true if this Identifier is null */
121 bool isNull() const noexcept { return name.isEmpty(); }
122
123 /** A null identifier. */
125
126 /** Checks a given string for characters that might not be valid in an Identifier.
127 Since Identifiers are used as a script variables and XML attributes, they should only contain
128 alphanumeric characters, underscores, or the '-' and ':' characters.
129 */
130 static bool isValidIdentifier (const String& possibleIdentifier) noexcept;
131
132private:
133 String name;
134};
135
136} // namespace juce
137
138/** @}*/
Wraps a pointer to a null-terminated UTF-8 character string, and provides various methods to operate ...
Represents a string identifier, designed for accessing properties by name.
bool isNull() const noexcept
Returns true if this Identifier is null.
String::CharPointerType getCharPointer() const noexcept
Returns this identifier's raw string pointer.
bool isValid() const noexcept
Returns true if this Identifier is not null.
const String & toString() const noexcept
Returns this identifier as a string.
static Identifier null
A null identifier.
A simple class for holding temporary references to a string literal or String.
The JUCE String class!
Definition juce_String.h:43
CharPointerType getCharPointer() const noexcept
Returns the character pointer currently being used to store this string.
#define JUCE_API
This macro is added to all JUCE public class declarations.