Plasma Engine  2.0
Loading...
Searching...
No Matches
TagSet.h
1
2#pragma once
3
4#include <Foundation/Containers/SmallArray.h>
5#include <Foundation/Reflection/Reflection.h>
6#include <Foundation/Types/TagRegistry.h>
7
8class plTag;
9using plTagSetBlockStorage = plUInt64;
10
21template <typename BlockStorageAllocator = plDefaultAllocatorWrapper>
23{
24public:
26
27 bool operator==(const plTagSetTemplate& other) const;
28 bool operator!=(const plTagSetTemplate& other) const;
29
31 void Set(const plTag& tag); // [tested]
32
34 void Remove(const plTag& tag); // [tested]
35
37 bool IsSet(const plTag& tag) const; // [tested]
38
40 bool IsAnySet(const plTagSetTemplate& otherSet) const; // [tested]
41
43 plUInt32 GetNumTagsSet() const;
44
46 bool IsEmpty() const;
47
49 void Clear();
50
52 void SetByName(plStringView sTag);
53
55 void RemoveByName(plStringView sTag);
56
58 bool IsSetByName(plStringView sTag) const;
59
62 {
63 public:
64 Iterator(const plTagSetTemplate<BlockStorageAllocator>* pSet, bool bEnd = false);
65
67 const plTag& operator*() const;
68
70 const plTag* operator->() const;
71
73 PL_ALWAYS_INLINE bool IsValid() const { return m_uiIndex != 0xFFFFFFFF; }
74
75 PL_ALWAYS_INLINE bool operator!=(const Iterator& rhs) const { return m_pTagSet != rhs.m_pTagSet || m_uiIndex != rhs.m_uiIndex; }
76
78 void operator++();
79
80 private:
81 bool IsBitSet() const;
82
84 plUInt32 m_uiIndex = 0;
85 };
86
88 Iterator GetIterator() const { return Iterator(this); }
89
91 void Save(plStreamWriter& inout_stream) const;
92
94 void Load(plStreamReader& inout_stream, plTagRegistry& inout_registry);
95
96private:
97 friend class Iterator;
98
99 bool IsTagInAllocatedRange(const plTag& Tag) const;
100
101 void Reallocate(plUInt32 uiNewTagBlockStart, plUInt32 uiNewMaxBlockIndex);
102
104
105 struct UserData
106 {
107 plUInt16 m_uiTagBlockStart;
108 plUInt16 m_uiTagCount;
109 };
110
111 plUInt16 GetTagBlockStart() const;
112 plUInt16 GetTagBlockEnd() const;
113 void SetTagBlockStart(plUInt16 uiTagBlockStart);
114
115 plUInt16 GetTagCount() const;
116 void SetTagCount(plUInt16 uiTagCount);
117 void IncreaseTagCount();
118 void DecreaseTagCount();
119};
120
123
124PL_DECLARE_REFLECTABLE_TYPE(PL_FOUNDATION_DLL, plTagSet);
125
126template <typename BlockStorageAllocator>
128{
130}
131
132template <typename BlockStorageAllocator>
134{
135 return typename plTagSetTemplate<BlockStorageAllocator>::Iterator(&cont, true);
136}
137
138template <typename BlockStorageAllocator>
140{
142}
143
144template <typename BlockStorageAllocator>
146{
147 return typename plTagSetTemplate<BlockStorageAllocator>::Iterator(&cont, true);
148}
149
150#include <Foundation/Types/Implementation/TagSet_inl.h>
Definition SmallArray.h:219
Interface for binary in (read) streams.
Definition Stream.h:22
Interface for binary out (write) streams.
Definition Stream.h:107
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
The tag class stores the necessary lookup information for a single tag which can be used in conjuncti...
Definition Tag.h:16
The tag registry for tags in tag sets.
Definition TagRegistry.h:22
Allows to iterate over all tags in this set.
Definition TagSet.h:62
const plTag & operator*() const
Returns a reference to the current tag.
Definition TagSet_inl.h:204
PL_ALWAYS_INLINE bool IsValid() const
Returns whether the iterator is still pointing to a valid item.
Definition TagSet.h:73
void operator++()
Advances the iterator to the next item.
Definition TagSet_inl.h:190
const plTag * operator->() const
Returns a pointer to the current tag.
Definition TagSet_inl.h:210
A dynamic collection of tags featuring fast lookups.
Definition TagSet.h:23
void RemoveByName(plStringView sTag)
Removes the given tag. If it doesn't exist, nothing happens.
Definition TagSet_inl.h:356
bool IsSet(const plTag &tag) const
Returns true, if the given tag is in the set.
Definition TagSet_inl.h:286
void Remove(const plTag &tag)
Removes the given tag.
Definition TagSet_inl.h:265
bool IsEmpty() const
True if the tag set never contained any tag or was cleared.
Definition TagSet_inl.h:335
void Save(plStreamWriter &inout_stream) const
Writes the tag set state to a stream. Tags itself are serialized as strings.
Definition TagSet_inl.h:456
bool IsSetByName(plStringView sTag) const
Checks whether the named tag is part of this set. Returns false if the tag does not exist.
Definition TagSet_inl.h:365
void Load(plStreamReader &inout_stream, plTagRegistry &inout_registry)
Reads the tag set state from a stream and registers the tags with the given registry.
Definition TagSet_inl.h:472
bool IsAnySet(const plTagSetTemplate &otherSet) const
Returns true if this tag set contains any tag set in the given other tag set.
Definition TagSet_inl.h:301
Iterator GetIterator() const
Returns an iterator to list all tags in this set.
Definition TagSet.h:88
void Set(const plTag &tag)
Adds the given tag to the set.
Definition TagSet_inl.h:235
plUInt32 GetNumTagsSet() const
Returns how many tags are in this set.
Definition TagSet_inl.h:329
void SetByName(plStringView sTag)
Adds the tag with the given name. If the tag does not exist, it will be registered.
Definition TagSet_inl.h:349
void Clear()
Removes all tags from the set.
Definition TagSet_inl.h:341