CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Identifier.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
11
13
15
18 class Identifier {
19 private:
20 bool mOriginalSet = false;
22
23 bool mRenamedSet = false;
25
27
28 public:
29 Identifier() = default;
30 Identifier(const Identifier&) = default;
31
32 // Renames this identifier by the final of the specified identifier.
34
35 // Renames this identifier by the specified string.
37
38 // Renames this identifier by appending the specified prefix to the front (if the identifier does not already have this prefix).
40
41 // Renames this identifier by removing the specified prefix.
43
44 // Returns the final identifier (i.e. renamed identifier if set, otherwise original).
45 [[nodiscard]] const String& getFinal() const;
46
47 // Returns true if the final of this identifier is empty.
48 [[nodiscard]] inline bool empty() const { return getFinal().empty(); }
49
50 // Operator shortcut for 'getFinal()'.
51 inline operator const String&() const { return getFinal(); }
52
53 // Returns the original identifier.
54 [[nodiscard]] inline const String& getOriginal() const { return mOriginal; }
55
56 // Returns true if this identifier is renamed.
57 [[nodiscard]] inline bool isRenamed() const { return !mRenamed.empty(); }
58 };
59
60 inline bool operator==(const Identifier& lhs, const Identifier& rhs) { return (String(lhs) == String(rhs)); }
61 inline bool operator==(const String& lhs, const Identifier& rhs) { return (lhs == String(rhs)); }
62 inline bool operator==(const Identifier& lhs, const String& rhs) { return (String(lhs) == rhs); }
63
64 inline bool operator!=(const Identifier& lhs, const Identifier& rhs) { return (String(lhs) != String(rhs)); }
65 inline bool operator!=(const String& lhs, const Identifier& rhs) { return (lhs != String(rhs)); }
66 inline bool operator!=(const Identifier& lhs, const String& rhs) { return (String(lhs) != rhs); }
67
68 inline bool operator<(const Identifier& lhs, const Identifier& rhs) { return (String(lhs) < String(rhs)); }
69 inline bool operator<(const String& lhs, const Identifier& rhs) { return (lhs < String(rhs)); }
70 inline bool operator<(const Identifier& lhs, const String& rhs) { return (String(lhs) < rhs); }
71
72 inline String operator+(const Identifier& lhs, const Identifier& rhs) { return (String(lhs) + String(rhs)); }
73 inline String operator+(const String& lhs, const Identifier& rhs) { return (lhs + String(rhs)); }
74 inline String operator+(const Identifier& lhs, const String& rhs) { return (String(lhs) + rhs); }
75 inline String operator+(const char lhs, const Identifier& rhs) { return (lhs + String(rhs)); }
76 inline String operator+(const Identifier& lhs, const char rhs) { return (String(lhs) + rhs); }
77
78} // namespace CeresEngine::ShaderCompiler
Class to manage identifiers that can be renamed (maybe several times), to keep track of the original ...
Definition Identifier.hpp:18
Int32 mCounter
Definition Identifier.hpp:26
Identifier & removePrefix(const String &prefix)
Identifier & appendPrefix(const String &prefix)
bool isRenamed() const
Definition Identifier.hpp:57
const String & getOriginal() const
Definition Identifier.hpp:54
bool empty() const
Definition Identifier.hpp:48
bool mRenamedSet
Definition Identifier.hpp:23
bool mOriginalSet
Definition Identifier.hpp:20
Identifier & operator=(const String &s)
String mRenamed
Definition Identifier.hpp:24
Identifier(const Identifier &)=default
String mOriginal
Definition Identifier.hpp:21
Identifier & operator=(const Identifier &rhs)
Definition AST.hpp:33
bool operator!=(const Identifier &lhs, const Identifier &rhs)
Definition Identifier.hpp:64
bool operator==(const Identifier &lhs, const Identifier &rhs)
Definition Identifier.hpp:60
bool operator<(const Identifier &lhs, const Identifier &rhs)
Definition Identifier.hpp:68
String operator+(const Identifier &lhs, const Identifier &rhs)
Definition Identifier.hpp:72
std::int32_t Int32
Definition DataTypes.hpp:21
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25