Plasma Engine  2.0
Loading...
Searching...
No Matches
FormatStringArgs.h
1#pragma once
2
3#ifndef PL_INCLUDING_BASICS_H
4# error "Please don't include FormatStringArgs.h directly, but instead include Foundation/Basics.h"
5#endif
6
8class plVariant;
9class plAngle;
10class plRational;
11struct plTime;
12
13struct plArgI
14{
15 inline explicit plArgI(plInt64 value, plUInt8 uiWidth = 1, bool bPadWithZeros = false, plUInt8 uiBase = 10)
16 : m_Value(value)
17 , m_uiWidth(uiWidth)
18 , m_bPadWithZeros(bPadWithZeros)
19 , m_uiBase(uiBase)
20 {
21 }
22
23 plInt64 m_Value;
24 plUInt8 m_uiWidth;
25 bool m_bPadWithZeros;
26 plUInt8 m_uiBase;
27};
28
29struct plArgU
30{
31 inline explicit plArgU(plUInt64 value, plUInt8 uiWidth = 1, bool bPadWithZeros = false, plUInt8 uiBase = 10, bool bUpperCase = false)
32 : m_Value(value)
33 , m_uiWidth(uiWidth)
34 , m_bPadWithZeros(bPadWithZeros)
35 , m_bUpperCase(bUpperCase)
36 , m_uiBase(uiBase)
37 {
38 }
39
40 plUInt64 m_Value;
41 plUInt8 m_uiWidth;
42 bool m_bPadWithZeros;
43 bool m_bUpperCase;
44 plUInt8 m_uiBase;
45};
46
47struct plArgF
48{
49 inline explicit plArgF(double value, plInt8 iPrecision = -1, bool bScientific = false, plUInt8 uiWidth = 1, bool bPadWithZeros = false)
50 : m_Value(value)
51 , m_uiWidth(uiWidth)
52 , m_bPadWithZeros(bPadWithZeros)
53 , m_bScientific(bScientific)
54 , m_iPrecision(iPrecision)
55 {
56 }
57
58 double m_Value;
59 plUInt8 m_uiWidth;
60 bool m_bPadWithZeros;
61 bool m_bScientific;
62 plInt8 m_iPrecision;
63};
64
65struct plArgC
66{
67 inline explicit plArgC(char value)
68 : m_Value(value)
69 {
70 }
71
72 char m_Value;
73};
74
75struct plArgP
76{
77 inline explicit plArgP(const void* value)
78 : m_Value(value)
79 {
80 }
81
82 const void* m_Value;
83};
84
85
95{
96 inline plArgHumanReadable(const double value, const plUInt64 uiBase, const char* const* const pSuffixes, plUInt32 uiSuffixCount)
97 : m_Value(value)
98 , m_Base(uiBase)
99 , m_Suffixes(pSuffixes)
100 , m_SuffixCount(uiSuffixCount)
101 {
102 }
103
104 inline plArgHumanReadable(const plInt64 value, const plUInt64 uiBase, const char* const* const pSuffixes, plUInt32 uiSuffixCount)
105 : plArgHumanReadable(static_cast<double>(value), uiBase, pSuffixes, uiSuffixCount)
106 {
107 }
108
109 inline explicit plArgHumanReadable(const double value)
110 : plArgHumanReadable(value, 1000u, m_DefaultSuffixes, PL_ARRAY_SIZE(m_DefaultSuffixes))
111 {
112 }
113
114 inline explicit plArgHumanReadable(const plInt64 value)
115 : plArgHumanReadable(static_cast<double>(value), 1000u, m_DefaultSuffixes, PL_ARRAY_SIZE(m_DefaultSuffixes))
116 {
117 }
118
119 const double m_Value;
120 const plUInt64 m_Base;
121 const char* const* const m_Suffixes;
122 const char* const m_DefaultSuffixes[6] = {"", "K", "M", "G", "T", "P"};
123 const plUInt32 m_SuffixCount;
124};
125
127{
128 inline explicit plArgFileSize(const plUInt64 value)
129 : plArgHumanReadable(static_cast<double>(value), 1024u, m_ByteSuffixes, PL_ARRAY_SIZE(m_ByteSuffixes))
130 {
131 }
132
133 const char* const m_ByteSuffixes[6] = {"B", "KB", "MB", "GB", "TB", "PB"};
134};
135
140{
141 inline explicit plArgErrorCode(plUInt32 uiErrorCode)
142 : m_ErrorCode(uiErrorCode)
143 {
144 }
145
146 plUInt32 m_ErrorCode;
147};
148PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, const plArgErrorCode& arg);
149
150
151#if PL_ENABLED(PL_PLATFORM_LINUX) || PL_ENABLED(PL_PLATFORM_ANDROID)
156struct plArgErrno
157{
158 inline explicit plArgErrno(plInt32 iErrno)
159 : m_iErrno(iErrno)
160 {
161 }
162
163 plInt32 m_iErrno;
164};
165PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, const plArgErrno& arg);
166#endif
167
177{
178 inline explicit plArgSensitive(const plStringView& sSensitiveInfo, const char* szContext = nullptr)
179 : m_sSensitiveInfo(sSensitiveInfo)
180 , m_szContext(szContext)
181 {
182 }
183
184 const plStringView m_sSensitiveInfo;
185 const char* m_szContext;
186
187 using BuildStringCallback = plStringView (*)(char*, plUInt32, const plArgSensitive&);
188 PL_FOUNDATION_DLL static BuildStringCallback s_BuildStringCB;
189
191 PL_FOUNDATION_DLL static plStringView BuildString_SensitiveUserData_Hash(char* szTmp, plUInt32 uiLength, const plArgSensitive& arg);
192};
193
194PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, const plArgI& arg);
195PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, plInt64 iArg);
196PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, plInt32 iArg);
197PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, const plArgU& arg);
198PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, plUInt64 uiArg);
199PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, plUInt32 uiArg);
200PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, const plArgF& arg);
201PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, double fArg);
202PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, bool bArg);
203PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, const char* szArg);
204PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, const wchar_t* pArg);
205PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, const plStringBuilder& sArg);
206PL_FOUNDATION_DLL const plStringView& BuildString(char* szTmp, plUInt32 uiLength, const plStringView& sArg);
207PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, const plArgC& arg);
208PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, const plArgP& arg);
209PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, plResult arg);
210PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, const plVariant& arg);
211PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, const plAngle& arg);
212PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, const plRational& arg);
213PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, const plArgHumanReadable& arg);
214PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, const plTime& arg);
215PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, const plArgSensitive& arg);
216
217
218#if PL_ENABLED(PL_COMPILER_GCC) || PL_ENABLED(PL_COMPILER_CLANG)
219
220// on these platforms "long int" is a different type from "long long int"
221
222PL_ALWAYS_INLINE plStringView BuildString(char* szTmp, plUInt32 uiLength, long int iArg)
223{
224 return BuildString(szTmp, uiLength, static_cast<plInt64>(iArg));
225}
226
227PL_ALWAYS_INLINE plStringView BuildString(char* szTmp, plUInt32 uiLength, unsigned long int uiArg)
228{
229 return BuildString(szTmp, uiLength, static_cast<plUInt64>(uiArg));
230}
231
232#endif
Float wrapper struct for a safe usage and conversions of angles.
Definition Angle.h:10
A class which can be used to represent rational numbers by stating their numerator and denominator.
Definition Rational.h:13
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
plVariant is a class that can store different types of variables, which is useful in situations where...
Definition Variant.h:44
Definition FormatStringArgs.h:66
Converts a windows HRESULT into an error code and a human-readable error message. Pass in GetLastErro...
Definition FormatStringArgs.h:140
Definition FormatStringArgs.h:48
Definition FormatStringArgs.h:127
Formats a given number such that it will be in format [0, base){suffix} with suffix representing a po...
Definition FormatStringArgs.h:95
Definition FormatStringArgs.h:14
Definition FormatStringArgs.h:76
Wraps a string that may contain sensitive information, such as user file paths.
Definition FormatStringArgs.h:177
static PL_FOUNDATION_DLL plStringView BuildString_SensitiveUserData_Hash(char *szTmp, plUInt32 uiLength, const plArgSensitive &arg)
Set s_BuildStringCB to this function to enable scrambling of sensitive data.
Definition FormatString.cpp:368
Definition FormatStringArgs.h:30
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12