tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_ProjectItemID.h
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11namespace tracktion { inline namespace engine
12{
13
21{
22public:
23 ProjectItemID() noexcept = default;
24 ProjectItemID (const ProjectItemID&) noexcept = default;
25 ProjectItemID& operator= (const ProjectItemID&) noexcept = default;
26 ~ProjectItemID() noexcept = default;
27
29 explicit ProjectItemID (const juce::String& stringID) noexcept;
30
32 ProjectItemID (int itemID, int projectID) noexcept;
33
35 static ProjectItemID createNewID (int projectID) noexcept;
36 static ProjectItemID fromProperty (const juce::ValueTree&, const juce::Identifier&);
37
38 ProjectItemID withNewProjectID (int newProjectID) const;
39
40 //==============================================================================
41 // TODO: create strong types for ProjectID and the ItemID
42
44 int getProjectID() const;
46 int getItemID() const;
47
49 int64_t getRawID() const noexcept { return combinedID; }
50
51 //==============================================================================
52 bool isValid() const noexcept { return combinedID != 0; }
53 bool isInvalid() const noexcept { return combinedID == 0; }
54
55 //==============================================================================
56 juce::String toString() const;
57 juce::String toStringSuitableForFilename() const;
58
59 //==============================================================================
60 bool operator== (ProjectItemID other) const { return combinedID == other.combinedID; }
61 bool operator!= (ProjectItemID other) const { return combinedID != other.combinedID; }
62 bool operator< (ProjectItemID other) const { return combinedID < other.combinedID; }
63
64private:
65 int64_t combinedID = 0;
66
67 // (NB: this is disallowed because it's ambiguous whether a string or int64 format is intended)
68 ProjectItemID (const juce::var&) = delete;
69};
70
71}} // namespace tracktion { inline namespace engine
72
73namespace juce
74{
75 template <>
76 struct VariantConverter<tracktion::engine::ProjectItemID>
77 {
78 static tracktion::engine::ProjectItemID fromVar (const var& v) { return tracktion::engine::ProjectItemID (v.toString()); }
79 static var toVar (const tracktion::engine::ProjectItemID& v) { return v.toString(); }
80 };
81}
const String & toString() const noexcept
An ID representing one of the items in a Project.
static ProjectItemID createNewID(int projectID) noexcept
Generates a new ID for a given project.
int getItemID() const
Returns the ID of the item within the project.
int getProjectID() const
Returns the ID of the project this item belongs to.
int64_t getRawID() const noexcept
Returns a combined ID as an integer, useful for creating hashes.
typedef int64_t