63 lines
3.3 KiB
C++
63 lines
3.3 KiB
C++
#include "ConstString.hpp"
|
|
#include <Arbutils/StringView.hpp>
|
|
#include <Arbutils/Ensure.hpp>
|
|
|
|
static void ConstructConstString(void* self) { new (self) ArbUt::StringView(); }
|
|
static void ConstructConstStringFromStd(void* self, const std::string& s) {
|
|
new (self) ArbUt::StringView(s.c_str(), s.length());
|
|
}
|
|
static void CopyConstructConstString(void* self, const ArbUt::StringView& other) {
|
|
new (self) ArbUt::StringView(other);
|
|
}
|
|
static void DestructConstString(void* self) { ((ArbUt::StringView*)self)->~StringView(); }
|
|
static bool ConstStringEquality(const ArbUt::StringView& a, const ArbUt::StringView& b) { return a == b; }
|
|
static bool ConstStringStdStringEquality(const ArbUt::StringView& a, const std::string& b) { return a == b; }
|
|
static uint32_t ImplConstStringHashConv(const ArbUt::StringView& s) { return s.GetHash(); }
|
|
static std::string ImplConstStringStringConv(const ArbUt::StringView& s) { return std::string(s.std_str()); }
|
|
|
|
void ConstStringRegister::Register(asIScriptEngine* engine) {
|
|
auto r = engine->RegisterObjectType("constString", sizeof(ArbUt::StringView),
|
|
asOBJ_VALUE | asGetTypeTraits<ArbUt::StringView>());
|
|
Ensure(r >= 0);
|
|
|
|
r = engine->RegisterObjectBehaviour("constString", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructConstString),
|
|
asCALL_CDECL_OBJFIRST);
|
|
Ensure(r >= 0);
|
|
r = engine->RegisterObjectBehaviour("constString", asBEHAVE_CONSTRUCT, "void f(const string &in s)",
|
|
asFUNCTION(ConstructConstStringFromStd), asCALL_CDECL_OBJFIRST);
|
|
Ensure(r >= 0);
|
|
|
|
r = engine->RegisterObjectBehaviour("constString", asBEHAVE_CONSTRUCT, "void f(const constString &in)",
|
|
asFUNCTION(CopyConstructConstString), asCALL_CDECL_OBJFIRST);
|
|
Ensure(r >= 0);
|
|
|
|
r = engine->RegisterObjectBehaviour("constString", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(DestructConstString),
|
|
asCALL_CDECL_OBJFIRST);
|
|
Ensure(r >= 0);
|
|
|
|
r = engine->RegisterObjectMethod(
|
|
"constString", "constString &opAssign(const constString &in)",
|
|
asMETHODPR(ArbUt::StringView, operator=, (const ArbUt::StringView&), ArbUt::StringView&), asCALL_THISCALL);
|
|
Ensure(r >= 0);
|
|
|
|
r = engine->RegisterObjectMethod(
|
|
"constString", "bool opEquals(const constString &in) const",
|
|
asFUNCTIONPR(ConstStringEquality, (const ArbUt::StringView&, const ArbUt::StringView&), bool),
|
|
asCALL_CDECL_OBJFIRST);
|
|
Ensure(r >= 0);
|
|
r = engine->RegisterObjectMethod(
|
|
"constString", "bool opEquals(const string &in) const",
|
|
asFUNCTIONPR(ConstStringStdStringEquality, (const ArbUt::StringView&, const std::string&), bool),
|
|
asCALL_CDECL_OBJFIRST);
|
|
Ensure(r >= 0);
|
|
|
|
r = engine->RegisterObjectMethod("constString", "uint opImplConv()",
|
|
asFUNCTIONPR(ImplConstStringHashConv, (const ArbUt::StringView&), uint32_t),
|
|
asCALL_CDECL_OBJFIRST);
|
|
Ensure(r >= 0);
|
|
r = engine->RegisterObjectMethod("constString", "string opImplConv()",
|
|
asFUNCTIONPR(ImplConstStringStringConv, (const ArbUt::StringView&), std::string),
|
|
asCALL_CDECL_OBJFIRST);
|
|
Ensure(r >= 0);
|
|
}
|