TypeOf: Move Move TypeInfos to anon namespace
Instead of constructing them as static fields. Slightly less cludgy. Related issue: #40
This commit is contained in:
parent
ed0af8fa21
commit
c9630a9aee
@ -14,40 +14,10 @@
|
||||
|
||||
#include "dap/typeof.h"
|
||||
|
||||
namespace dap {
|
||||
namespace {
|
||||
|
||||
const TypeInfo* TypeOf<boolean>::type() {
|
||||
static BasicTypeInfo<boolean> typeinfo("boolean");
|
||||
return &typeinfo;
|
||||
}
|
||||
|
||||
const TypeInfo* TypeOf<string>::type() {
|
||||
static BasicTypeInfo<string> typeinfo("string");
|
||||
return &typeinfo;
|
||||
}
|
||||
|
||||
const TypeInfo* TypeOf<integer>::type() {
|
||||
static BasicTypeInfo<integer> typeinfo("integer");
|
||||
return &typeinfo;
|
||||
}
|
||||
|
||||
const TypeInfo* TypeOf<number>::type() {
|
||||
static BasicTypeInfo<number> typeinfo("number");
|
||||
return &typeinfo;
|
||||
}
|
||||
|
||||
const TypeInfo* TypeOf<object>::type() {
|
||||
static BasicTypeInfo<object> typeinfo("object");
|
||||
return &typeinfo;
|
||||
}
|
||||
|
||||
const TypeInfo* TypeOf<any>::type() {
|
||||
static BasicTypeInfo<any> typeinfo("any");
|
||||
return &typeinfo;
|
||||
}
|
||||
|
||||
const TypeInfo* TypeOf<null>::type() {
|
||||
struct TI : public TypeInfo {
|
||||
struct NullTI : public dap::TypeInfo {
|
||||
using null = dap::null;
|
||||
inline std::string name() const { return "null"; }
|
||||
inline size_t size() const { return sizeof(null); }
|
||||
inline size_t alignment() const { return alignof(null); }
|
||||
@ -58,11 +28,44 @@ const TypeInfo* TypeOf<null>::type() {
|
||||
inline void destruct(void* ptr) const {
|
||||
reinterpret_cast<null*>(ptr)->~null();
|
||||
}
|
||||
inline bool deserialize(const Deserializer*, void*) const { return true; }
|
||||
inline bool serialize(Serializer*, const void*) const { return true; }
|
||||
inline bool deserialize(const dap::Deserializer*, void*) const {
|
||||
return true;
|
||||
}
|
||||
inline bool serialize(dap::Serializer*, const void*) const { return true; }
|
||||
};
|
||||
static TI typeinfo;
|
||||
return &typeinfo;
|
||||
} // namespace dap
|
||||
|
||||
static dap::BasicTypeInfo<dap::boolean> booleanTI("boolean");
|
||||
static dap::BasicTypeInfo<dap::string> stringTI("string");
|
||||
static dap::BasicTypeInfo<dap::integer> integerTI("integer");
|
||||
static dap::BasicTypeInfo<dap::number> numberTI("number");
|
||||
static dap::BasicTypeInfo<dap::object> objectTI("object");
|
||||
static dap::BasicTypeInfo<dap::any> anyTI("any");
|
||||
static NullTI nullTI;
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace dap {
|
||||
|
||||
const TypeInfo* TypeOf<boolean>::type() {
|
||||
return &booleanTI;
|
||||
}
|
||||
const TypeInfo* TypeOf<string>::type() {
|
||||
return &stringTI;
|
||||
}
|
||||
const TypeInfo* TypeOf<integer>::type() {
|
||||
return &integerTI;
|
||||
}
|
||||
const TypeInfo* TypeOf<number>::type() {
|
||||
return &numberTI;
|
||||
}
|
||||
const TypeInfo* TypeOf<object>::type() {
|
||||
return &objectTI;
|
||||
}
|
||||
const TypeInfo* TypeOf<any>::type() {
|
||||
return &anyTI;
|
||||
}
|
||||
const TypeInfo* TypeOf<null>::type() {
|
||||
return &nullTI;
|
||||
}
|
||||
|
||||
} // namespace dap
|
||||
|
Loading…
x
Reference in New Issue
Block a user