Skip to content

Commit

Permalink
Minor code fixes / cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
mlomb committed Oct 26, 2020
1 parent 5693290 commit ef6e654
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 29 deletions.
16 changes: 8 additions & 8 deletions Example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ int main() {

Player* player = new Player();
player->health = 255;
player->position = {5, 5};
player->velocity = {1, 1};
player->position = { 5, 5 };
player->velocity = { 1, 1 };
player->name = "mlomb";

Monster* monster = new Monster();
monster->health = 255;
monster->position = {10, 10};
monster->velocity = {-1, -1};
monster->position = { 10, 10 };
monster->velocity = { -1, -1 };
monster->scary_factor = 42.123;

Map map;
map.entities = {player, monster};
map.entities = { player, monster };

map.magic_numbers = { 4, 2 };

map.map = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
{ 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 },
};

metacpp::JsonSerializer serializer = metacpp::JsonSerializer(storage);
Expand Down
12 changes: 6 additions & 6 deletions MetaCPP-CLI/MetaExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ namespace metacpp {
data["name"] = type->m_QualifiedName.GetName();
data["hasSize"] = std::to_string(type->HasSize());
data["arraySize"] = std::to_string(type->m_ArraySize);
data["kind"] = std::to_string(type->m_Kind);
data["access"] = std::to_string(type->m_Access);
data["kind"] = std::to_string(static_cast<int>(type->m_Kind));
data["access"] = std::to_string(static_cast<int>(type->m_Access));
data["valid"] = std::to_string(type->IsValid());
data["polymorphic"] = std::to_string(type->m_Polymorphic);
data["hasDefaultConstructor"] = std::to_string(type->m_HasDefaultConstructor);
Expand All @@ -101,7 +101,7 @@ namespace metacpp {
for (const BaseType& base : type->m_BaseTypes) {
mustache::data baseType;
baseType["qualifiedType"] = ExportQualifiedType(base.type);
baseType["access"] = std::to_string(base.access);
baseType["access"] = std::to_string(static_cast<int>(base.access));
baseTypes << baseType;
}

Expand Down Expand Up @@ -147,7 +147,7 @@ namespace metacpp {
mustache::data data;
data["typeID"] = std::to_string(qtype.m_Type);
data["const"] = std::to_string(qtype.m_Const);
data["operator"] = std::to_string(qtype.m_Operator);
data["operator"] = std::to_string(static_cast<int>(qtype.m_Operator));
data["arraySize"] = std::to_string(qtype.m_ArraySize);
return data;
}
Expand All @@ -171,8 +171,8 @@ namespace metacpp {
const QualifiedType& qtype = std::get<QualifiedType>(argument);
data["typeID"] = std::to_string(qtype.m_Type);
data["const"] = std::to_string(qtype.m_Const);
data["operator"] = std::to_string(qtype.m_Operator);
data["arraySize"] = std::to_string(qtype.m_ArraySize);
data["operator"] = std::to_string(static_cast<int>(qtype.m_Operator));
data["arraySize"] = std::to_string(static_cast<int>(qtype.m_ArraySize));
} else {
data["isIntegral"] = std::to_string(true);
data["integralValue"] = std::to_string(std::get<unsigned long long>(argument));
Expand Down
2 changes: 1 addition & 1 deletion MetaCPP/include/MetaCPP/QualifiedType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace metacpp {
class Storage;

enum QualifierOperator {
enum class QualifierOperator {
POINTER,
REFERENCE,
VALUE
Expand Down
4 changes: 2 additions & 2 deletions MetaCPP/include/MetaCPP/Type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
#include "Container.hpp"

namespace metacpp {
enum TypeKind {
enum class TypeKind {
PRIMITIVE,
CLASS,
STRUCT
};

enum AccessSpecifier {
enum class AccessSpecifier {
PUBLIC,
PROTECTED,
PRIVATE
Expand Down
22 changes: 12 additions & 10 deletions MetaCPP/src/MetaCPP/JsonSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ namespace metacpp {

const TypeID id = type->GetTypeID();

#define FIELD_SET(set_func, t) \
else if (id == TypeInfo< t >::ID) value.set_func(*reinterpret_cast< const t* >(ptr))
#define FIELD_SET(set_func, t) \
else if (id == TypeInfo< t >::ID) \
value.set_func(*reinterpret_cast< const t* >(ptr))

if (false) {}
FIELD_SET(SetBool, bool);
Expand Down Expand Up @@ -107,8 +108,7 @@ namespace metacpp {
if (IsBasicType(elemType)) {
subArray.PushBack(SerializeBasicType(elemType, addr, context), context.document->GetAllocator());
} else {
subArray.PushBack(SerializeObject(elemType, addr, false, pointer_recursion, context),
context.document->GetAllocator());
subArray.PushBack(SerializeObject(elemType, addr, false, pointer_recursion, context), context.document->GetAllocator());
}
}
return subArray;
Expand All @@ -125,7 +125,8 @@ namespace metacpp {
auto derived = context.serializer->GetStorage()->ResolveDerivedType(type, pointee);
return SerializeObject(derived.first, derived.second, true, pointer_recursion + 1, context);
}
}
} else
return Value();
}
default:
// not supported
Expand Down Expand Up @@ -258,8 +259,9 @@ namespace metacpp {
}

void JsonSerializer::DeSerializeBasicType(const TypeID id, const Value& value, void* ptr) {
#define FIELD_GET(is_func, t, get_func) \
else if (value.is_func() && id == TypeInfo< t >::ID) *reinterpret_cast<t*>(ptr) = value.get_func()
#define FIELD_GET(is_func, t, get_func) \
else if (value.is_func() && id == TypeInfo< t >::ID) \
*reinterpret_cast<t*>(ptr) = value.get_func()

if (false) {}
FIELD_GET(IsBool, bool, GetBool);
Expand Down Expand Up @@ -367,7 +369,7 @@ namespace metacpp {
const QualifiedType& item_qtype, const Type* item_type) {
for (const Value& item : value.GetArray()) {
switch (item_qtype.GetQualifierOperator()) {
case VALUE: {
case QualifierOperator::VALUE: {
void* temp_item_ptr = item_type->Allocate();

DeSerializeType(item_qtype, item, temp_item_ptr, context);
Expand All @@ -377,14 +379,14 @@ namespace metacpp {
item_type->Delete(temp_item_ptr);
break;
}
case POINTER: {
case QualifierOperator::POINTER: {
void* holder = 0;
DeSerializePointer(item_type, item, &holder, context);

sc->PushBack(obj, &holder);
break;
}
case REFERENCE: {
case QualifierOperator::REFERENCE: {
assert(false);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion MetaCPP/src/MetaCPP/Method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace metacpp {
}

Method::Method(const QualifiedName& qName)
: m_QualifiedName(qName), m_Owner(0) {
: m_QualifiedName(qName), m_Owner(0), m_Static(false), m_Virtual(false) {
}

TypeID Method::GetOwnerType() const {
Expand Down
4 changes: 3 additions & 1 deletion MetaCPP/src/MetaCPP/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ namespace metacpp {
m_Access(AccessSpecifier::PUBLIC),
m_Polymorphic(false),
m_HasDefaultConstructor(false),
m_Container(0) {
m_HasDefaultDestructor(false),
m_ArraySize(0),
m_Container(NULL) {
}

TypeID Type::GetTypeID() const {
Expand Down

0 comments on commit ef6e654

Please sign in to comment.