Skip to content

Commit

Permalink
idk
Browse files Browse the repository at this point in the history
  • Loading branch information
playmer committed May 7, 2018
1 parent 7c1bb5c commit c380cc0
Show file tree
Hide file tree
Showing 12 changed files with 369 additions and 343 deletions.
2 changes: 1 addition & 1 deletion Reflection/Any.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ namespace YTE
template <typename T>
T& As()
{
runtime_assert(IsType<T>(), "This Any is being casted into the incorrect type.");
//runtime_assert(IsType<T>(), "This Any is being casted into the incorrect type.");

return TypeCasting<T>::TypeCast(GetData());
}
Expand Down
1 change: 1 addition & 0 deletions Reflection/Attribute.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "Meta.hpp"
#include "Attribute.hpp"

namespace YTE
Expand Down
1 change: 1 addition & 0 deletions Reflection/Field.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "Any.hpp"
#include "Property.hpp"
#include "TypeTraits.hpp"

Expand Down
167 changes: 167 additions & 0 deletions Reflection/Function.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#include "Meta.hpp"
#include "Function.hpp"

namespace YTE
{
YTEDefineType(Function)
{
YTERegisterType(Function);

YTEBindProperty(&Function::GetOwningType, YTENoSetter, "OwningType")
.Description() = "Type that owns this Function.";
YTEBindProperty(&Function::GetName, YTENoSetter, "Name")
.Description() = "Name of the property.";
YTEBindProperty(&Function::GetReturnType, YTENoSetter, "ReturnType")
.Description() = "The return type of the function.";
YTEBindProperty(&Function::IsStaticOrFree, YTENoSetter, "StaticOrFree")
.Description() = "Lets you know if this function is a static or free function, as in not a member function.";
}

Function::Parameter::Parameter(Type *aType, const char *aName)
: mType(aType)
, mName(aName)
{

}

Type *mType;
std::string mName;

Function::Function(const char *aName,
Type *aReturnType,
Type *aOwningType)
: mName(aName)
, mReturnType(aReturnType)
, mCaller(nullptr)
, mOwningType(aOwningType)
, mStaticOrFree(nullptr == aOwningType)
{
if ((aOwningType == nullptr) && (mStaticOrFree == false))
{
runtime_assert(false,
"A function without an owning type is, by definition, static.");
}
}

Any Function::Invoke(std::vector<Any> &aArguments) const
{
if (mParameters.size() != aArguments.size())
{
std::cout << "Different argument amounts." << std::endl;
return Any();
}

for (size_t i = 0; i < mParameters.size(); ++i)
{
auto parameterType = mParameters[i].mType->GetMostBasicType();
auto argumentType = aArguments[i].mType->GetMostBasicType();

if (false == argumentType->IsA(parameterType) &&
false == parameterType->IsA(argumentType))
{
std::cout << "Different argument types." << std::endl;
return Any();
}
}

return mCaller(aArguments);
}

void Function::AddParameter(Type *aType, const char *aName)
{
mParameters.emplace_back(aType, aName);
}

void Function::SetCaller(CallingFunction aCaller)
{
mCaller = aCaller;
}

const std::string& Function::GetName() const
{
return mName;
}

void Function::SetOwningType(Type *aOwningType)
{
mOwningType = aOwningType;
}

Type* Function::GetOwningType() const
{
return mOwningType;
}

bool Function::IsSame(Function &aFunction) const
{
if (mName != aFunction.mName)
{
return false;
}

if (mReturnType != aFunction.mReturnType)
{
return false;
}

if (mParameters.size() == aFunction.mParameters.size())
{
for (size_t i = 0; i < mParameters.size(); ++i)
{
if (mParameters[i].mType != aFunction.mParameters[i].mType)
{
return false;
}
}
}

return true;
}


Type* Function::GetReturnType() const
{
return mReturnType;
}

bool Function::IsStaticOrFree()
{
return mStaticOrFree;
}

void Function::SetParameterNames(std::initializer_list<const char *> aNames)
{
// Member Function
if (false == mStaticOrFree &&
aNames.size() == (mParameters.size() - 1))
{
mParameters[0].mName = "aThisPointer";

for (size_t i = 1; i < mParameters.size(); ++i)
{
mParameters[i].mName = *(aNames.begin() + i - 1);
}
}
else if (aNames.size() == mParameters.size())
{
for (size_t i = 0; i < mParameters.size(); ++i)
{
mParameters[i].mName = *(aNames.begin() + i);
}
}
else
{
for (size_t i = 0; i < mParameters.size(); ++i)
{
std::string argumentName{ "aArgument" };
argumentName += std::to_string(i);
mParameters[i].mName = argumentName;
}
}
}

std::vector<Function::Parameter>& Function::GetParameters()
{
return mParameters;
}
}
Loading

0 comments on commit c380cc0

Please sign in to comment.