mirror of
https://github.com/hyprwm/hyprlang.git
synced 2024-12-22 09:59:48 +01:00
configvalue: add getDataStaticPtr()
This commit is contained in:
parent
1210de188c
commit
5150f64f15
3 changed files with 21 additions and 2 deletions
|
@ -71,7 +71,7 @@ namespace Hyprlang {
|
|||
bool throwAllErrors = false;
|
||||
|
||||
/*!
|
||||
@since 0.2.0
|
||||
\since 0.2.0
|
||||
Don't throw on a missing config file. Carry on as if nothing happened.
|
||||
*/
|
||||
bool allowMissingConfig = false;
|
||||
|
@ -148,10 +148,18 @@ namespace Hyprlang {
|
|||
~CConfigValue();
|
||||
|
||||
/*!
|
||||
Return a pointer to the data. Prefer getValue().
|
||||
Return a pointer to the data. Prefer getDataStaticPtr()
|
||||
*/
|
||||
void* dataPtr() const;
|
||||
|
||||
/*!
|
||||
\since 0.2.0
|
||||
Return a static pointer to the m_pData.
|
||||
As long as this configValue is alive, this pointer is valid.
|
||||
CConfigValues are alive as long as the owning CConfig is alive.
|
||||
*/
|
||||
void* const* getDataStaticPtr() const;
|
||||
|
||||
/*!
|
||||
Get the contained value as an std::any.
|
||||
For strings, this is a const char*.
|
||||
|
|
|
@ -62,6 +62,10 @@ void* CConfigValue::dataPtr() const {
|
|||
return m_pData;
|
||||
}
|
||||
|
||||
void* const* CConfigValue::getDataStaticPtr() const {
|
||||
return &m_pData;
|
||||
}
|
||||
|
||||
CConfigCustomValueType::CConfigCustomValueType(PCONFIGCUSTOMVALUEHANDLERFUNC handler_, PCONFIGCUSTOMVALUEDESTRUCTOR dtor_, const char* def) {
|
||||
handler = handler_;
|
||||
dtor = dtor_;
|
||||
|
|
|
@ -140,6 +140,13 @@ int main(int argc, char** argv, char** envp) {
|
|||
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testCategory:testColor2")), 0xFF000000L);
|
||||
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testCategory:testColor3")), 0x22ffeeffL);
|
||||
|
||||
// test static values
|
||||
std::cout << " → Testing static values\n";
|
||||
static auto* const PTESTINT = config.getConfigValuePtr("testInt")->getDataStaticPtr();
|
||||
EXPECT(*reinterpret_cast<int64_t*>(*PTESTINT), 123);
|
||||
config.parse();
|
||||
EXPECT(*reinterpret_cast<int64_t*>(*PTESTINT), 123);
|
||||
|
||||
// test handlers
|
||||
std::cout << " → Testing handlers\n";
|
||||
EXPECT(barrelRoll, true);
|
||||
|
|
Loading…
Reference in a new issue