Plasma Engine  2.0
Loading...
Searching...
No Matches
DataDirPath_inl.h
1
2
3inline plDataDirPath::plDataDirPath() = default;
4
5inline plDataDirPath::plDataDirPath(plStringView sAbsPath, plArrayPtr<plString> dataDirRoots, plUInt32 uiLastKnownDataDirIndex /*= 0*/)
6{
7 PL_ASSERT_DEBUG(!sAbsPath.EndsWith_NoCase("/"), "");
8 m_sAbsolutePath = sAbsPath;
9 UpdateDataDirInfos(dataDirRoots, uiLastKnownDataDirIndex);
10}
11
12inline plDataDirPath::plDataDirPath(const plStringBuilder& sAbsPath, plArrayPtr<plString> dataDirRoots, plUInt32 uiLastKnownDataDirIndex /*= 0*/)
13{
14 PL_ASSERT_DEBUG(!sAbsPath.EndsWith_NoCase("/"), "");
15 m_sAbsolutePath = sAbsPath;
16 UpdateDataDirInfos(dataDirRoots, uiLastKnownDataDirIndex);
17}
18
19inline plDataDirPath::plDataDirPath(plString&& sAbsPath, plArrayPtr<plString> dataDirRoots, plUInt32 uiLastKnownDataDirIndex /*= 0*/)
20{
21 PL_ASSERT_DEBUG(!sAbsPath.EndsWith_NoCase("/"), "");
22 m_sAbsolutePath = std::move(sAbsPath);
23 UpdateDataDirInfos(dataDirRoots, uiLastKnownDataDirIndex);
24}
25
26inline plDataDirPath::operator plStringView() const
27{
28 return m_sAbsolutePath;
29}
30
31inline bool plDataDirPath::operator==(plStringView rhs) const
32{
33 return m_sAbsolutePath == rhs;
34}
35
36inline bool plDataDirPath::operator!=(plStringView rhs) const
37{
38 return m_sAbsolutePath != rhs;
39}
40
41inline bool plDataDirPath::IsValid() const
42{
43 return m_uiDataDirParent != 0;
44}
45
47{
48 m_sAbsolutePath.Clear();
49 m_uiDataDirParent = 0;
50 m_uiDataDirLength = 0;
51 m_uiDataDirIndex = 0;
52}
53
55{
56 return m_sAbsolutePath;
57}
58
60{
61 PL_ASSERT_DEBUG(IsValid(), "Path is not in a data directory, only GetAbsolutePath is allowed to be called.");
62 const plUInt32 uiOffset = m_uiDataDirParent + 1;
63 return plStringView(m_sAbsolutePath.GetData() + uiOffset, m_sAbsolutePath.GetElementCount() - uiOffset);
64}
65
67{
68 PL_ASSERT_DEBUG(IsValid(), "Path is not in a data directory, only GetAbsolutePath is allowed to be called.");
69 const plUInt32 uiOffset = plMath::Min(m_sAbsolutePath.GetElementCount(), m_uiDataDirParent + m_uiDataDirLength + 1u);
70 return plStringView(m_sAbsolutePath.GetData() + uiOffset, m_sAbsolutePath.GetElementCount() - uiOffset);
71}
72
74{
75 PL_ASSERT_DEBUG(IsValid(), "Path is not in a data directory, only GetAbsolutePath is allowed to be called.");
76 return plStringView(m_sAbsolutePath.GetData(), m_uiDataDirParent + m_uiDataDirLength);
77}
78
79inline plUInt8 plDataDirPath::GetDataDirIndex() const
80{
81 PL_ASSERT_DEBUG(IsValid(), "Path is not in a data directory, only GetAbsolutePath is allowed to be called.");
82 return m_uiDataDirIndex;
83}
84
85inline plStreamWriter& plDataDirPath::Write(plStreamWriter& inout_stream) const
86{
87 inout_stream << m_sAbsolutePath;
88 inout_stream << m_uiDataDirParent;
89 inout_stream << m_uiDataDirLength;
90 inout_stream << m_uiDataDirIndex;
91 return inout_stream;
92}
93
94inline plStreamReader& plDataDirPath::Read(plStreamReader& inout_stream)
95{
96 inout_stream >> m_sAbsolutePath;
97 inout_stream >> m_uiDataDirParent;
98 inout_stream >> m_uiDataDirLength;
99 inout_stream >> m_uiDataDirIndex;
100 return inout_stream;
101}
102
103bool plCompareDataDirPath::Less(plStringView lhs, plStringView rhs)
104{
105 int res = lhs.Compare_NoCase(rhs);
106 if (res == 0)
107 {
108 return lhs.Compare(rhs) < 0;
109 }
110
111 return res < 0;
112}
113
114bool plCompareDataDirPath::Equal(plStringView lhs, plStringView rhs)
115{
116 return lhs.IsEqual(rhs);
117}
118
119inline plStreamWriter& operator<<(plStreamWriter& inout_stream, const plDataDirPath& value)
120{
121 return value.Write(inout_stream);
122}
123
124inline plStreamReader& operator>>(plStreamReader& inout_stream, plDataDirPath& out_value)
125{
126 return out_value.Read(inout_stream);
127}
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
A reference to a file or folder inside a data directory.
Definition DataDirPath.h:18
void Clear()
Same as the default constructor. Creates an empty, invalid path.
Definition DataDirPath_inl.h:46
plStringView GetDataDirParentRelativePath() const
Returns a relative path including the data directory the path belongs to, e.g. "Testing Chambers/Obje...
Definition DataDirPath_inl.h:59
bool UpdateDataDirInfos(plArrayPtr< plString > dataDirRoots, plUInt32 uiLastKnownDataDirIndex=0) const
If a plDataDirPath is de-serialized, it might not be correct anymore and its data directory reference...
Definition DataDirPath.cpp:5
plStringView GetDataDirRelativePath() const
Returns a path relative to the data directory the path belongs to, e.g. "Objects/Barrel....
Definition DataDirPath_inl.h:66
bool IsValid() const
Returns whether this path is inside a data directory. If not, none of the Get* functions except for G...
Definition DataDirPath_inl.h:41
plDataDirPath()
Default ctor, creates an invalid data directory path.
plUInt8 GetDataDirIndex() const
Returns the index of the data directory the path belongs to.
Definition DataDirPath_inl.h:79
plStringView GetDataDir() const
Returns absolute path to the data directory this path belongs to, e.g. "C:/plEngine/Data/Samples/Test...
Definition DataDirPath_inl.h:73
const plString & GetAbsolutePath() const
Returns the same path this instance was created with. Calling this function is always valid.
Definition DataDirPath_inl.h:54
Interface for binary in (read) streams.
Definition Stream.h:22
Interface for binary out (write) streams.
Definition Stream.h:107
plStringBuilder is a class that is meant for creating and modifying strings.
Definition StringBuilder.h:35
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
bool EndsWith_NoCase(plStringView sEndsWith) const
Returns true, if this string ends with the given string. Case insensitive.
Definition StringView_inl.h:115
plInt32 Compare_NoCase(plStringView sOther) const
Compares this string with the other one. Returns 0 for equality, -1 if this string is 'smaller',...
Definition StringView.cpp:41
plInt32 Compare(plStringView sOther) const
Compares this string with the other one. Returns 0 for equality, -1 if this string is 'smaller',...
Definition StringView.cpp:31
bool IsEqual(plStringView sOther) const
Compares this string view with the other string view for equality.
Definition StringView_inl.h:90
constexpr PL_ALWAYS_INLINE T Min(T f1, T f2)
Returns the smaller value, f1 or f2.
Definition Math_inl.h:27
const char * GetData() const
Returns a pointer to the internal Utf8 string.
Definition String_inl.h:56
plUInt32 GetElementCount() const
Returns the amount of bytes that this string takes (excluding the '\0' terminator).
Definition String_inl.h:65
void Clear()
Resets this string to an empty string.
Definition String_inl.h:49
bool EndsWith_NoCase(plStringView sEndsWith) const
Returns true, if this string ends with the given string. Case insensitive.
Definition StringBase_inl.h:49