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,55 +14,58 @@
|
|||||||
|
|
||||||
#include "dap/typeof.h"
|
#include "dap/typeof.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
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); }
|
||||||
|
inline void construct(void* ptr) const { new (ptr) null(); }
|
||||||
|
inline void copyConstruct(void* dst, const void* src) const {
|
||||||
|
new (dst) null(*reinterpret_cast<const null*>(src));
|
||||||
|
}
|
||||||
|
inline void destruct(void* ptr) const {
|
||||||
|
reinterpret_cast<null*>(ptr)->~null();
|
||||||
|
}
|
||||||
|
inline bool deserialize(const dap::Deserializer*, void*) const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
inline bool serialize(dap::Serializer*, const void*) const { return true; }
|
||||||
|
};
|
||||||
|
|
||||||
|
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 {
|
namespace dap {
|
||||||
|
|
||||||
const TypeInfo* TypeOf<boolean>::type() {
|
const TypeInfo* TypeOf<boolean>::type() {
|
||||||
static BasicTypeInfo<boolean> typeinfo("boolean");
|
return &booleanTI;
|
||||||
return &typeinfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const TypeInfo* TypeOf<string>::type() {
|
const TypeInfo* TypeOf<string>::type() {
|
||||||
static BasicTypeInfo<string> typeinfo("string");
|
return &stringTI;
|
||||||
return &typeinfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const TypeInfo* TypeOf<integer>::type() {
|
const TypeInfo* TypeOf<integer>::type() {
|
||||||
static BasicTypeInfo<integer> typeinfo("integer");
|
return &integerTI;
|
||||||
return &typeinfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const TypeInfo* TypeOf<number>::type() {
|
const TypeInfo* TypeOf<number>::type() {
|
||||||
static BasicTypeInfo<number> typeinfo("number");
|
return &numberTI;
|
||||||
return &typeinfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const TypeInfo* TypeOf<object>::type() {
|
const TypeInfo* TypeOf<object>::type() {
|
||||||
static BasicTypeInfo<object> typeinfo("object");
|
return &objectTI;
|
||||||
return &typeinfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const TypeInfo* TypeOf<any>::type() {
|
const TypeInfo* TypeOf<any>::type() {
|
||||||
static BasicTypeInfo<any> typeinfo("any");
|
return &anyTI;
|
||||||
return &typeinfo;
|
}
|
||||||
|
const TypeInfo* TypeOf<null>::type() {
|
||||||
|
return &nullTI;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TypeInfo* TypeOf<null>::type() {
|
|
||||||
struct TI : public TypeInfo {
|
|
||||||
inline std::string name() const { return "null"; }
|
|
||||||
inline size_t size() const { return sizeof(null); }
|
|
||||||
inline size_t alignment() const { return alignof(null); }
|
|
||||||
inline void construct(void* ptr) const { new (ptr) null(); }
|
|
||||||
inline void copyConstruct(void* dst, const void* src) const {
|
|
||||||
new (dst) null(*reinterpret_cast<const null*>(src));
|
|
||||||
}
|
|
||||||
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; }
|
|
||||||
};
|
|
||||||
static TI typeinfo;
|
|
||||||
return &typeinfo;
|
|
||||||
} // namespace dap
|
|
||||||
|
|
||||||
} // namespace dap
|
} // namespace dap
|
||||||
|
Loading…
x
Reference in New Issue
Block a user