aboutsummaryrefslogtreecommitdiff
path: root/src/linda.hpp
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-11-20 17:51:49 +0100
committerBenoit Germain <benoit.germain@ubisoft.com>2024-11-20 17:51:49 +0100
commit304e4dfabe4555dff4aa72e75b677405fd30d1b3 (patch)
treeac934000415b46f784bda25ba671e74b9481573b /src/linda.hpp
parent872826ecaca5370e3492385cff3795d995b33ec7 (diff)
downloadlanes-304e4dfabe4555dff4aa72e75b677405fd30d1b3.tar.gz
lanes-304e4dfabe4555dff4aa72e75b677405fd30d1b3.tar.bz2
lanes-304e4dfabe4555dff4aa72e75b677405fd30d1b3.zip
Some [[nodiscard]] boyscouting
Diffstat (limited to 'src/linda.hpp')
-rw-r--r--src/linda.hpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/linda.hpp b/src/linda.hpp
index 5b5f683..aa63316 100644
--- a/src/linda.hpp
+++ b/src/linda.hpp
@@ -19,7 +19,7 @@ class Linda
19: public DeepPrelude // Deep userdata MUST start with this header 19: public DeepPrelude // Deep userdata MUST start with this header
20{ 20{
21 public: 21 public:
22 class KeeperOperationInProgress 22 class [[nodiscard]] KeeperOperationInProgress
23 { 23 {
24 private: 24 private:
25 Linda& linda; 25 Linda& linda;
@@ -64,7 +64,8 @@ class Linda
64 Status cancelStatus{ Status::Active }; 64 Status cancelStatus{ Status::Active };
65 65
66 public: 66 public:
67 [[nodiscard]] static void* operator new(size_t size_, Universe* U_) noexcept { return U_->internalAllocator.alloc(size_); } 67 [[nodiscard]]
68 static void* operator new(size_t size_, Universe* U_) noexcept { return U_->internalAllocator.alloc(size_); }
68 // always embedded somewhere else or "in-place constructed" as a full userdata 69 // always embedded somewhere else or "in-place constructed" as a full userdata
69 // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception 70 // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception
70 static void operator delete(void* p_, Universe* U_) { U_->internalAllocator.free(p_, sizeof(Linda)); } 71 static void operator delete(void* p_, Universe* U_) { U_->internalAllocator.free(p_, sizeof(Linda)); }
@@ -85,19 +86,26 @@ class Linda
85 void setName(std::string_view const& name_); 86 void setName(std::string_view const& name_);
86 87
87 public: 88 public:
88 [[nodiscard]] Keeper* acquireKeeper() const; 89 [[nodiscard]]
89 [[nodiscard]] std::string_view getName() const; 90 Keeper* acquireKeeper() const;
90 [[nodiscard]] bool inKeeperOperation() const { return keeperOperationCount.load(std::memory_order_seq_cst) != 0; } 91 [[nodiscard]]
92 std::string_view getName() const;
93 [[nodiscard]]
94 bool inKeeperOperation() const { return keeperOperationCount.load(std::memory_order_seq_cst) != 0; }
91 template <typename T = uintptr_t> 95 template <typename T = uintptr_t>
92 [[nodiscard]] T obfuscated() const 96 [[nodiscard]]
97 T obfuscated() const
93 { 98 {
94 // xxh64 of string "kObfuscator" generated at https://www.pelock.com/products/hash-calculator 99 // xxh64 of string "kObfuscator" generated at https://www.pelock.com/products/hash-calculator
95 static constexpr UniqueKey kObfuscator{ 0x7B8AA1F99A3BD782ull }; 100 static constexpr UniqueKey kObfuscator{ 0x7B8AA1F99A3BD782ull };
96 return std::bit_cast<T>(std::bit_cast<uintptr_t>(this) ^ kObfuscator.storage); 101 return std::bit_cast<T>(std::bit_cast<uintptr_t>(this) ^ kObfuscator.storage);
97 }; 102 };
98 void releaseKeeper(Keeper* keeper_) const; 103 void releaseKeeper(Keeper* keeper_) const;
99 [[nodiscard]] static int ProtectedCall(lua_State* L_, lua_CFunction f_); 104 [[nodiscard]]
105 static int ProtectedCall(lua_State* L_, lua_CFunction f_);
100 void pushCancelString(lua_State* L_) const; 106 void pushCancelString(lua_State* L_) const;
101 [[nodiscard]] KeeperOperationInProgress startKeeperOperation(lua_State* const L_) { return KeeperOperationInProgress{ *this, L_ }; }; 107 [[nodiscard]]
102 [[nodiscard]] Keeper* whichKeeper() const { return U->keepers.getKeeper(keeperIndex); } 108 KeeperOperationInProgress startKeeperOperation(lua_State* const L_) { return KeeperOperationInProgress{ *this, L_ }; };
109 [[nodiscard]]
110 Keeper* whichKeeper() const { return U->keepers.getKeeper(keeperIndex); }
103}; 111};