Add get() functionality to static_pointer
All checks were successful
continuous-integration/drone/push Build is passing
gitea/skullc-peripherals/pipeline/head This commit looks good

This commit is contained in:
Erki 2022-06-30 19:46:56 +03:00
parent eef2e1318c
commit 0ba9416a57
2 changed files with 15 additions and 1 deletions

View File

@ -8,8 +8,11 @@
#ifndef SKULLC_UTILITY_STATICPOINTER_HPP_ #ifndef SKULLC_UTILITY_STATICPOINTER_HPP_
#define SKULLC_UTILITY_STATICPOINTER_HPP_ #define SKULLC_UTILITY_STATICPOINTER_HPP_
#include <new>
#include <utility> #include <utility>
#include <utility_assert.hpp>
namespace Utility namespace Utility
{ {
@ -57,6 +60,17 @@ struct StaticPointer
return initialized_; return initialized_;
} }
value_type* get()
{
SKULLC_ASSERT_DEBUG(initialized_);
return reinterpret_cast<value_type*>(storage);
}
const value_type* get() const
{
SKULLC_ASSERT_DEBUG(initialized_);
return reinterpret_cast<const value_type*>(storage);
}
private: private:
bool initialized_ = false; bool initialized_ = false;
}; };

View File

@ -9,4 +9,4 @@
#define SKULLC_CONCAT(x, y) SKULLC_CONCAT_IMPL(x, y) #define SKULLC_CONCAT(x, y) SKULLC_CONCAT_IMPL(x, y)
#define SKULLC_TAG struct SKULLC_CONCAT(SkullCTag_, __COUNTER__) #define SKULLC_TAG struct SKULLC_CONCAT(SkullCTag_, __COUNTER__)
#endif // SKULLC_UTILITY_TAG_HPP_ #endif// SKULLC_UTILITY_TAG_HPP_