All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ue4cpp.model-source.mustache Maven / Gradle / Ivy

There is a newer version: 3.0.0-rc1
Show newest version
{{>licenseInfo}}
#include "{{classname}}.h"

#include "{{unrealModuleName}}Module.h"
#include "{{modelNamePrefix}}Helpers.h"

#include "Templates/SharedPointer.h"

{{#cppNamespaceDeclarations}}
namespace {{this}} 
{
{{/cppNamespaceDeclarations}}
{{#models}}{{#model}}
{{#hasEnums}}
{{#vars}}
{{#isEnum}}
inline FString ToString(const {{classname}}::{{{enumName}}}& Value)
{
	{{#allowableValues}}
	switch (Value)
	{
	{{#enumVars}}
	case {{classname}}::{{{enumName}}}::{{name}}:
		return TEXT({{{value}}});
	{{/enumVars}}
	}
	{{/allowableValues}}

	UE_LOG(Log{{unrealModuleName}}, Error, TEXT("Invalid {{classname}}::{{{enumName}}} Value (%d)"), (int)Value);	
	return TEXT("");
}

inline FStringFormatArg ToStringFormatArg(const {{classname}}::{{{enumName}}}& Value)
{
	return FStringFormatArg(ToString(Value));
}

inline void WriteJsonValue(JsonWriter& Writer, const {{classname}}::{{{enumName}}}& Value)
{
	WriteJsonValue(Writer, ToString(Value));
}

inline bool TryGetJsonValue(const TSharedPtr& JsonValue, {{classname}}::{{{enumName}}}& Value)
{
	FString TmpValue;
	if (JsonValue->TryGetString(TmpValue))
	{
		static TMap StringToEnum = { {{#enumVars}}
			{ TEXT({{{value}}}), {{classname}}::{{{enumName}}}::{{name}} },{{/enumVars}} };

		const auto Found = StringToEnum.Find(TmpValue);
		if(Found)
		{
			Value = *Found;
			return true;
		}
	}
	return false;
}

{{/isEnum}}
{{/vars}}
{{/hasEnums}}
void {{classname}}::WriteJson(JsonWriter& Writer) const
{
	{{#parent}}
	#error inheritance not handled right now
	{{/parent}}
	Writer->WriteObjectStart();
    {{#vars}}
	{{#required}}
	Writer->WriteIdentifierPrefix(TEXT("{{baseName}}")); WriteJsonValue(Writer, {{name}});
	{{/required}}
	{{^required}}
	if ({{name}}.IsSet())
	{
		Writer->WriteIdentifierPrefix(TEXT("{{baseName}}")); WriteJsonValue(Writer, {{name}}.GetValue());	
	}
	{{/required}}
    {{/vars}}
	Writer->WriteObjectEnd();
}

bool {{classname}}::FromJson(const TSharedPtr& JsonObject)
{
	bool ParseSuccess = true;

    {{#vars}}
	ParseSuccess &= TryGetJsonValue(JsonObject, TEXT("{{baseName}}"), {{name}});
    {{/vars}}

	return ParseSuccess;
}
{{/model}}
{{/models}}
{{#cppNamespaceDeclarations}}
}
{{/cppNamespaceDeclarations}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy