forked from otland/forgottenserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace LuaVariant with std::variant (otland#3981)
(cherry picked from commit 1cef0ea)
- Loading branch information
1 parent
812666d
commit d795705
Showing
7 changed files
with
113 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifndef FS_LUAVARIANT_H | ||
#define FS_LUAVARIANT_H | ||
|
||
#include <variant> | ||
|
||
enum LuaVariantType_t { | ||
VARIANT_NUMBER = 0, | ||
VARIANT_POSITION = 1, | ||
VARIANT_TARGETPOSITION = 2, | ||
VARIANT_STRING = 3, | ||
|
||
VARIANT_NONE = std::variant_npos, | ||
}; | ||
|
||
class LuaVariant { | ||
public: | ||
uint32_t getNumber() const { return std::get<VARIANT_NUMBER>(variant); } | ||
const Position& getPosition() const { return std::get<VARIANT_POSITION>(variant); } | ||
const Position& getTargetPosition() const { return std::get<VARIANT_TARGETPOSITION>(variant); } | ||
const std::string& getString() const { return std::get<VARIANT_STRING>(variant); } | ||
|
||
bool isNumber() const { return variant.index() == VARIANT_NUMBER; } | ||
bool isPosition() const { return variant.index() == VARIANT_POSITION; } | ||
bool isTargetPosition() const { return variant.index() == VARIANT_TARGETPOSITION; } | ||
bool isString() const { return variant.index() == VARIANT_STRING; } | ||
|
||
void setNumber(uint32_t value) { variant.emplace<VARIANT_NUMBER>(value); } | ||
void setPosition(const Position& value) { variant.emplace<VARIANT_POSITION>(value); } | ||
void setTargetPosition(const Position& value) { variant.emplace<VARIANT_TARGETPOSITION>(value); } | ||
void setString(const std::string& value) { variant.emplace<VARIANT_STRING>(value); } | ||
|
||
auto type() const { return static_cast<LuaVariantType_t>(variant.index()); } | ||
|
||
private: | ||
std::variant<uint32_t, Position, Position, std::string> variant; | ||
}; | ||
|
||
#endif |
Oops, something went wrong.