├── .gitattributes ├── Examples ├── Arrays.cpp ├── CMakeLists.txt ├── Enums.cpp ├── FunctionsAndMethods.cpp ├── MetaProperties.cpp ├── Serialization.cpp ├── TestProperties.h ├── TestReflection.h ├── TestReflectionModule.h └── TestTypes.h ├── LICENSE.txt ├── README.md ├── Resources └── Templates │ ├── field-getter.mustache │ ├── field-setter.mustache │ ├── global-getter.mustache │ ├── global-setter.mustache │ ├── meta-initializer-list.mustache │ ├── module-file-header.mustache │ ├── module-file-source.mustache │ ├── module-header.mustache │ └── module-source.mustache └── Source ├── CMake ├── FindLLVM.cmake ├── MetaParser.cmake └── Precompiled.cmake ├── Common ├── Compiler.h ├── Lib │ ├── Mustache.h │ ├── json11.cpp │ └── json11.hpp ├── Logging.h └── Logging.hpp ├── Parser ├── CMakeLists.txt ├── Cursor.cpp ├── Cursor.h ├── CursorType.cpp ├── CursorType.h ├── LanguageTypes │ ├── Class.cpp │ ├── Class.h │ ├── Constructor.cpp │ ├── Constructor.h │ ├── Enum.cpp │ ├── Enum.h │ ├── External.cpp │ ├── External.h │ ├── Field.cpp │ ├── Field.h │ ├── Function.cpp │ ├── Function.h │ ├── Global.cpp │ ├── Global.h │ ├── Invokable.cpp │ ├── Invokable.h │ ├── LanguageType.cpp │ ├── LanguageType.h │ ├── Method.cpp │ └── Method.h ├── Main.cpp ├── MetaDataConfig.h ├── MetaDataManager.cpp ├── MetaDataManager.h ├── MetaUtils.cpp ├── MetaUtils.h ├── MetaUtils.hpp ├── Module │ └── ModuleFile.h ├── Namespace.h ├── Precompiled.cpp ├── Precompiled.h ├── ReflectionOptions.h ├── ReflectionParser.cpp ├── ReflectionParser.h ├── ReservedTypes.h ├── Switches.h ├── Templates.h ├── Tokenizer │ ├── ConstructorTokenSymbols.inl │ ├── Impl │ │ ├── Token.hpp │ │ ├── Tokenizer.hpp │ │ ├── TokenizerResult.hpp │ │ └── TokenizerState.hpp │ ├── Token.h │ ├── TokenType.h │ ├── Tokenizer.h │ ├── TokenizerResult.h │ └── TokenizerState.h └── Version.h └── Runtime ├── Argument.cpp ├── Argument.h ├── ArgumentConfig.h ├── Array.h ├── ArrayVariantContainer.h ├── ArrayWrapper.cpp ├── ArrayWrapper.h ├── ArrayWrapperBase.h ├── ArrayWrapperContainer.h ├── CMakeLists.txt ├── Constructor.cpp ├── Constructor.h ├── ConstructorInvoker.h ├── ConstructorInvokerBase.h ├── Destructor.cpp ├── Destructor.h ├── DestructorInvoker.h ├── DestructorInvokerBase.h ├── Enum.cpp ├── Enum.h ├── EnumBase.cpp ├── EnumBase.h ├── EnumContainer.h ├── Field.cpp ├── Field.h ├── FieldGetter.h ├── FieldGetterBase.h ├── FieldSetter.h ├── FieldSetterBase.h ├── Function.cpp ├── Function.h ├── FunctionInvoker.h ├── FunctionInvokerBase.h ├── Global.cpp ├── Global.h ├── GlobalGetter.h ├── GlobalGetterBase.h ├── GlobalSetter.h ├── GlobalSetterBase.h ├── Impl ├── Argument.hpp ├── Array.hpp ├── ArrayVariantContainer.hpp ├── ArrayWrapper.hpp ├── ArrayWrapperContainer.hpp ├── Constructor.hpp ├── ConstructorInvoker.hpp ├── DestructorInvoker.hpp ├── EnumContainer.hpp ├── FieldGetter.hpp ├── FieldSetter.hpp ├── Function.hpp ├── FunctionInvoker.hpp ├── GlobalGetter.hpp ├── GlobalSetter.hpp ├── Invokable.hpp ├── MetaManager.hpp ├── MetaProperty.hpp ├── Method.hpp ├── MethodInvoker.hpp ├── ReflectionDatabase.hpp ├── Type.hpp ├── TypeCreator.hpp ├── TypeData.hpp ├── TypeInfo.hpp ├── TypeUnpacker.hpp ├── Variant.hpp ├── VariantContainer.hpp ├── VariantContainerStandardTypes.hpp ├── VoidFunctionInvoker.hpp └── VoidMethodInvoker.hpp ├── Invokable.cpp ├── Invokable.h ├── InvokableConfig.h ├── JsonConfig.h ├── Macros.h ├── Meta.h ├── MetaContainer.cpp ├── MetaContainer.h ├── MetaManager.cpp ├── MetaManager.h ├── MetaProperty.h ├── MetaTraits.h ├── Method.cpp ├── Method.h ├── MethodInvoker.h ├── MethodInvokerBase.h ├── Object.h ├── ObjectWrapper.cpp ├── ObjectWrapper.h ├── Precompiled.cpp ├── Precompiled.h ├── ReflectionDatabase.cpp ├── ReflectionDatabase.h ├── ReflectionModule.cpp ├── ReflectionModule.h ├── RuntimeMetaProperties.h ├── Type.cpp ├── Type.h ├── TypeConfig.h ├── TypeCreator.cpp ├── TypeCreator.h ├── TypeData.cpp ├── TypeData.h ├── TypeID.h ├── TypeInfo.h ├── Variant.cpp ├── Variant.h ├── VariantBase.cpp ├── VariantBase.h ├── VariantContainer.cpp ├── VariantContainer.h └── VariantPolicy.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /Examples/Arrays.cpp: -------------------------------------------------------------------------------- 1 | #include "TestReflectionModule.h" 2 | 3 | #include "TestTypes.h" 4 | #include "TestProperties.h" 5 | 6 | using namespace ursine; 7 | using namespace meta; 8 | 9 | int main(void) 10 | { 11 | MetaInitialize( UsingModule( TestModule ) ); 12 | 13 | Array intArray { 1, 2, 3, 4, 5 }; 14 | 15 | Variant intArrayVariant = intArray; 16 | 17 | ArrayWrapper arrayWrapper = intArrayVariant.GetArray( ); 18 | 19 | // updating a value 20 | arrayWrapper.SetValue( 0, 1000 ); 21 | 22 | // inserting a value 23 | arrayWrapper.Insert( 0, -100 ); 24 | 25 | // removing a value 26 | arrayWrapper.Remove( 5 ); 27 | 28 | size_t size = arrayWrapper.Size( ); 29 | 30 | std::cout << "values: "; 31 | 32 | for (size_t i = 0; i < size; ++i) 33 | { 34 | // could also use .GetValue( ) 35 | std::cout << arrayWrapper.GetValue( i ).ToInt( ) << " "; 36 | } 37 | 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.3) 2 | 3 | project(MetaTests CXX) 4 | 5 | add_subdirectory(../Source/Runtime MetaRuntime) 6 | add_subdirectory(../Source/Parser MetaParser) 7 | 8 | set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../Source/CMake") 9 | 10 | include(MetaParser) 11 | 12 | include_directories(${META_RUNTIME_INCLUDE_DIRS}) 13 | 14 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 15 | set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake") 16 | 17 | set(TEST_META_SOURCE_ROOT "${CMAKE_CURRENT_LIST_DIR}") 18 | set(TEST_META_GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/Generated") 19 | 20 | set(TEST_META_GENERATED_HEADERS "") 21 | set(TEST_META_GENERATED_SOURCES "") 22 | 23 | set(TEST_REFLECTION_HEADER TestReflection.h) 24 | set(TEST_MODULE_HEADER TestReflectionModule.h) 25 | set(TEST_MODULE_TARGET TestModule) 26 | 27 | set(TEST_HEADERS TestProperties.h TestTypes.h) 28 | 29 | meta_parser_prebuild( 30 | TARGET ${TEST_MODULE_TARGET} 31 | GENERATED_DIR ${TEST_META_GENERATED_DIR} 32 | SOURCE_ROOT ${TEST_META_SOURCE_ROOT} 33 | HEADER_FILES ${TEST_HEADERS} 34 | MODULE_HEADER ${TEST_MODULE_HEADER} 35 | OUT_MODULE_SOURCE META_MODULE_SOURCE 36 | OUT_GENERATED_FILES META_GENERATED_FILES 37 | OUT_INC TEST_META_GENERATED_HEADERS 38 | OUT_SRC TEST_META_GENERATED_SOURCES 39 | ) 40 | 41 | add_library(${TEST_MODULE_TARGET} ${META_GENERATED_FILES}) 42 | 43 | target_link_libraries(${TEST_MODULE_TARGET} MetaRuntime) 44 | 45 | if (MSVC) 46 | add_compile_options( 47 | # treat warnings as errors 48 | /WX 49 | # multi process compilation 50 | /MP 51 | ) 52 | else () 53 | add_compile_options( 54 | -std=c++11 55 | ) 56 | endif () 57 | 58 | macro (add_meta_test TARGET SOURCES) 59 | add_executable(${TARGET} 60 | ${TEST_HEADERS} 61 | ${TEST_META_GENERATED_HEADERS} 62 | ${TEST_META_GENERATED_SOURCES} 63 | ${SOURCES} 64 | ) 65 | 66 | target_link_libraries(${TARGET} MetaRuntime ${TEST_MODULE_TARGET}) 67 | set_property(TARGET ${TARGET} PROPERTY FOLDER Tests) 68 | endmacro () 69 | 70 | add_meta_test(MetaProperties MetaProperties.cpp) 71 | add_meta_test(Enums Enums.cpp) 72 | add_meta_test(FunctionsAndMethods FunctionsAndMethods.cpp) 73 | add_meta_test(Arrays Arrays.cpp) 74 | add_meta_test(Serialization Serialization.cpp) 75 | 76 | meta_parser_build( 77 | TARGET ${TEST_MODULE_TARGET} 78 | SOURCE_ROOT ${TEST_META_SOURCE_ROOT} 79 | GENERATED_DIR ${TEST_META_GENERATED_DIR} 80 | GENERATED_FILES ${META_GENERATED_FILES} 81 | SOURCE_FILE ${TEST_REFLECTION_HEADER} 82 | MODULE_HEADER ${TEST_MODULE_HEADER} 83 | MODULE_SOURCE_FILE ${META_MODULE_SOURCE} 84 | HEADER_FILES ${TEST_HEADERS} 85 | PARSER_EXECUTABLE "$" 86 | ) 87 | -------------------------------------------------------------------------------- /Examples/Enums.cpp: -------------------------------------------------------------------------------- 1 | #include "TestReflectionModule.h" 2 | 3 | #include "TestTypes.h" 4 | #include "TestProperties.h" 5 | 6 | using namespace ursine; 7 | using namespace meta; 8 | 9 | int main(void) 10 | { 11 | MetaInitialize( UsingModule( TestModule ) ); 12 | 13 | return 0; 14 | } -------------------------------------------------------------------------------- /Examples/FunctionsAndMethods.cpp: -------------------------------------------------------------------------------- 1 | #include "TestReflectionModule.h" 2 | 3 | #include "TestTypes.h" 4 | #include "TestProperties.h" 5 | 6 | #include "TypeCreator.h" 7 | 8 | using namespace ursine::meta; 9 | 10 | int main(void) 11 | { 12 | MetaInitialize( UsingModule( TestModule ) ); 13 | 14 | Type soundEffectType = typeof( SoundEffect ); 15 | Field volumeField = soundEffectType.GetField( "volume" ); 16 | 17 | // the runtime supports overloading, but by default returns the first overload 18 | Method loadMethod = soundEffectType.GetMethod( "Load" ); 19 | 20 | // creates an instance of a sound effect 21 | Variant effect = TypeCreator::Create( soundEffectType ); 22 | 23 | // effect.volume is now 85 24 | volumeField.SetValue( effect, 85.0f ); 25 | 26 | // 85 -- can also use GetValue( ) 27 | float volumeValue = volumeField.GetValue( effect ).ToFloat( ); 28 | 29 | std::cout << "SoundEffect.volume: " << volumeValue << std::endl; 30 | 31 | // effect.Load is called 32 | loadMethod.Invoke( effect, std::string { "Explosion.wav" } ); 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Examples/MetaProperties.cpp: -------------------------------------------------------------------------------- 1 | #include "TestReflectionModule.h" 2 | 3 | #include "TestTypes.h" 4 | #include "TestProperties.h" 5 | 6 | using namespace ursine::meta; 7 | 8 | int main(void) 9 | { 10 | MetaInitialize( UsingModule( TestModule ) ); 11 | 12 | // you can also use type meta::Type::GetFromName( "SoundEffect" ) based on a string name 13 | Type soundEffectType = typeof( SoundEffect ); 14 | 15 | // the volume field in the SoundEffect struct 16 | Field volumeField = soundEffectType.GetField( "volume" ); 17 | 18 | // meta data for the volume field 19 | const MetaManager &volumeMeta = volumeField.GetMeta( ); 20 | 21 | // getting the "Range" property, then casting the variant as a Range 22 | Range &volumeRange = volumeMeta.GetProperty( typeof( Range ) ).GetValue( ); 23 | 24 | // 0.0f 25 | std::cout << "SoundEffect::volume [Range.min]: " << volumeRange.min << std::endl; 26 | 27 | // 100.0f 28 | std::cout << "SoundEffect::volume [Range.max]: " << volumeRange.max << std::endl; 29 | 30 | // getting the "Slider" property, then casting the variant as a Slider 31 | Slider &volumeSlider = volumeMeta.GetProperty( typeof( Slider ) ).GetValue( ); 32 | 33 | // type representing the SlideType enum 34 | Type sliderTypeEnumType = typeof( SliderType ); 35 | 36 | // enum representing the SliderType 37 | const Enum &sliderTypeEnum = sliderTypeEnumType.GetEnum( ); 38 | 39 | // get the associative value of the enum 40 | std::cout << "SoundEffect::volume [Slider.type]: " << sliderTypeEnum.GetKey( volumeSlider.type ) << std::endl; 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Examples/Serialization.cpp: -------------------------------------------------------------------------------- 1 | #include "TestReflectionModule.h" 2 | 3 | #include "TestTypes.h" 4 | #include "TestProperties.h" 5 | 6 | using namespace ursine; 7 | using namespace meta; 8 | 9 | int main(void) 10 | { 11 | MetaInitialize( UsingModule( TestModule ) ); 12 | 13 | /////////////////////////////////////////////////////////////////////////// 14 | // Serialization 15 | /////////////////////////////////////////////////////////////////////////// 16 | 17 | ComplexType complexType; 18 | 19 | complexType.stringValue = "Testing"; 20 | complexType.intValue = 23; 21 | complexType.floatValue = 77.0f; 22 | complexType.doubleValue = 86.35f; 23 | 24 | complexType.soundEffect.volume = 50.0f; 25 | 26 | complexType.arrayValue = { 1, 2, 3, 4, 5 }; 27 | 28 | complexType.enumValue = Eighty; 29 | 30 | std::cout << "Serialized: " 31 | << Variant( complexType ).SerializeJson( ).dump( ) 32 | << std::endl; 33 | 34 | /////////////////////////////////////////////////////////////////////////// 35 | // Deserialization 36 | /////////////////////////////////////////////////////////////////////////// 37 | 38 | std::string complexJson = R"( 39 | { 40 | "arrayValue": [ 5, 6, 7, 8 ], 41 | "doubleValue": 100.0, 42 | "enumValue": "Two", 43 | "floatValue": 98.5, 44 | "intValue": -25, 45 | "soundEffect":{ 46 | "volume": 100.0 47 | }, 48 | "stringValue": "Deserialization!" 49 | } 50 | )"; 51 | 52 | std::string jsonError; 53 | 54 | // This is a static helper method. It is essentially doing this - 55 | // typeof( ComplexType ).DeserializeJson( ).GetValue( ) 56 | ComplexType deserializedComplexType = Type::DeserializeJson( 57 | Json::parse( complexJson, jsonError ) 58 | ); 59 | 60 | std::cout << "Deserialized: " << std::endl 61 | << Variant( deserializedComplexType ).SerializeJson( ).dump( ) 62 | << std::endl; 63 | 64 | return 0; 65 | } -------------------------------------------------------------------------------- /Examples/TestProperties.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | enum class SliderType 6 | { 7 | Horizontal, 8 | Vertical 9 | } Meta(Enable); 10 | 11 | struct Slider : ursine::meta::MetaProperty 12 | { 13 | META_OBJECT; 14 | 15 | SliderType type; 16 | 17 | Slider(SliderType type) 18 | : type(type) { } 19 | } Meta(Enable); 20 | 21 | struct Range : ursine::meta::MetaProperty 22 | { 23 | META_OBJECT; 24 | 25 | float min, max; 26 | 27 | Range(float min, float max) 28 | : min(min) 29 | , max(max) { } 30 | } Meta(Enable); -------------------------------------------------------------------------------- /Examples/TestReflection.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "TestProperties.h" 4 | #include "TestTypes.h" 5 | -------------------------------------------------------------------------------- /Examples/TestReflectionModule.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DECLARE_REFLECTION_MODULE( TestModule ); -------------------------------------------------------------------------------- /Examples/TestTypes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "TestProperties.h" 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | enum TestEnum 13 | { 14 | One, 15 | Two, 16 | Three, 17 | Four, 18 | Five, 19 | Eighty = 80 20 | } Meta(Enable); 21 | 22 | struct SoundEffect 23 | { 24 | Meta(Range(0.0f, 100.0f), Slider(SliderType::Horizontal)) 25 | float volume; 26 | 27 | void Load(const std::string &filename) 28 | { 29 | std::cout << "Loaded sound effect \"" << filename << "\"." << std::endl; 30 | } 31 | } Meta(Enable); 32 | 33 | struct ComplexType 34 | { 35 | std::string stringValue; 36 | int intValue; 37 | float floatValue; 38 | double doubleValue; 39 | 40 | SoundEffect soundEffect; 41 | 42 | ursine::Array arrayValue; 43 | 44 | TestEnum enumValue; 45 | 46 | ComplexType(void) = default; 47 | } Meta(Enable); -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Austin Brunkhorst 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Resources/Templates/field-getter.mustache: -------------------------------------------------------------------------------- 1 | {{#hasExplicitGetter}}{{& explicitGetter}}{{/hasExplicitGetter}}{{^hasExplicitGetter}}&{{& parentQualifiedName}}::{{& name}}{{/hasExplicitGetter}} -------------------------------------------------------------------------------- /Resources/Templates/field-setter.mustache: -------------------------------------------------------------------------------- 1 | {{#hasExplicitSetter}}&{{& parentQualifiedName}}::{{& explicitSetter}}{{/hasExplicitSetter}}{{^hasExplicitSetter}}&{{& parentQualifiedName}}::{{& name}}{{/hasExplicitSetter}} -------------------------------------------------------------------------------- /Resources/Templates/global-getter.mustache: -------------------------------------------------------------------------------- 1 | {{#hasExplicitGetter}}{{#hasParent}}&{{& parentQualifiedName}}::{{& explicitGetter}}{{/hasParent}}{{^hasParent}}&{{& explicitGetter}}{{/hasParent}}{{/hasExplicitGetter}}{{^hasExplicitGetter}}{{#hasParent}}&{{& parentQualifiedName}}::{{name}}{{/hasParent}}{{^hasParent}}&{{& qualifiedName}}{{/hasParent}}{{/hasExplicitGetter}} -------------------------------------------------------------------------------- /Resources/Templates/global-setter.mustache: -------------------------------------------------------------------------------- 1 | {{#hasExplicitSetter}}{{#hasParent}}&{{& parentQualifiedName}}::{{& explicitSetter}}{{/hasParent}}{{^hasParent}}&{{& explicitSetter}}{{/hasParent}}{{/hasExplicitSetter}}{{^hasExplicitSetter}}{{#hasParent}}&{{& parentQualifiedName}}::{{name}}{{/hasParent}}{{^hasParent}}&{{& qualifiedName}}{{/hasParent}}{{/hasExplicitSetter}} -------------------------------------------------------------------------------- /Resources/Templates/meta-initializer-list.mustache: -------------------------------------------------------------------------------- 1 | {{#metaProperty}}std::make_pair( typeof( {{& type}} ), m::MetaPropertyInitializer<{{& type}}>( {{& arguments}} ) ){{^isLast}}, {{/isLast}} 2 | {{/metaProperty}} -------------------------------------------------------------------------------- /Resources/Templates/module-file-header.mustache: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** GENERATED HEADER FILE 3 | ** Do not modify the contents of this file. 4 | ** 5 | ** Ursine Meta Generator v{{version}} 6 | ** --------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | namespace ursine { namespace meta { class ReflectionDatabase; } } 11 | 12 | namespace meta_generated 13 | { 14 | extern void AllocateModuleFile{{targetName}}{{moduleFileName}}(ursine::meta::ReflectionDatabase &db); 15 | extern void DefineModuleFile{{targetName}}{{moduleFileName}}(ursine::meta::ReflectionDatabase &db); 16 | } -------------------------------------------------------------------------------- /Resources/Templates/module-header.mustache: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** GENERATED HEADER FILE 3 | ** Do not modify the contents of this file. 4 | ** 5 | ** Ursine Meta Generator v{{version}} 6 | ** --------------------------------------------------------------------------*/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace meta_generated 13 | { 14 | namespace module 15 | { 16 | class Module{{targetName}} : public ursine::meta::ReflectionModule 17 | { 18 | public: 19 | Module{{targetName}}(ursine::meta::ReflectionDatabase &db); 20 | ~Module{{targetName}}(void); 21 | }; 22 | } 23 | } -------------------------------------------------------------------------------- /Resources/Templates/module-source.mustache: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** GENERATED SOURCE FILE 3 | ** Do not modify the contents of this file. 4 | ** 5 | ** Ursine Meta Generator v{{version}} 6 | ** --------------------------------------------------------------------------*/ 7 | {{#usingPrecompiledHeader}}#include "{{precompiledHeader}}" 8 | {{/usingPrecompiledHeader}} 9 | 10 | #include "{{moduleHeaderFile}}" 11 | 12 | /////////////////////////////////////////////////////////////////////////////// 13 | // Module Files 14 | /////////////////////////////////////////////////////////////////////////////// 15 | 16 | {{#moduleFile}} 17 | #include "{{& header}}"{{/moduleFile}} 18 | 19 | namespace m = ursine::meta; 20 | 21 | meta_generated::Module{{targetName}}::Module{{targetName}}(m::ReflectionDatabase &db) 22 | : ReflectionModule( db ) 23 | { 24 | /////////////////////////////////////////////////////////////////////////// 25 | // External Allocation 26 | /////////////////////////////////////////////////////////////////////////// 27 | {{#external}} 28 | { 29 | { // Base Type 30 | auto id = db.AllocateType( "{{& displayName}}" ); 31 | auto &type = db.types[ id ]; 32 | 33 | m::TypeInfo<{{& qualifiedName}}>::Register( id, type, true ); 34 | } 35 | {{#ptrTypeEnabled}} 36 | { // Pointer Type 37 | auto id = db.AllocateType( "{{& displayName}}*" ); 38 | auto &type = db.types[ id ]; 39 | 40 | m::TypeInfo<{{& qualifiedName}}*>::Register( id, type, false ); 41 | } 42 | {{/ptrTypeEnabled}} 43 | {{#constPtrTypeEnabled}} 44 | { // Const Pointer Type 45 | auto id = db.AllocateType( "const {{& displayName}}*" ); 46 | auto &type = db.types[ id ]; 47 | 48 | m::TypeInfo::Register( id, type, false ); 49 | } 50 | {{/constPtrTypeEnabled}} 51 | } 52 | {{/external}} 53 | /////////////////////////////////////////////////////////////////////////// 54 | // Module File Allocation 55 | /////////////////////////////////////////////////////////////////////////// 56 | {{#moduleFile}} 57 | AllocateModuleFile{{targetName}}{{& name}}( db );{{/moduleFile}} 58 | } 59 | 60 | meta_generated::Module{{targetName}}::~Module{{targetName}}(void) 61 | { 62 | /////////////////////////////////////////////////////////////////////////// 63 | // Module File Definition 64 | /////////////////////////////////////////////////////////////////////////// 65 | {{#moduleFile}} 66 | DefineModuleFile{{targetName}}{{& name}}( db );{{/moduleFile}} 67 | } -------------------------------------------------------------------------------- /Source/CMake/FindLLVM.cmake: -------------------------------------------------------------------------------- 1 | # by default, only use the libclang static lib on MSVC 2 | if (NOT DEFINED LIBCLANG_USE_STATIC_LIBRARY) 3 | if (MSVC) 4 | set(LIBCLANG_USE_STATIC_LIBRARY YES) 5 | else () 6 | set(LIBCLANG_USE_STATIC_LIBRARY NO) 7 | endif () 8 | endif () 9 | 10 | set(LLVM_SEARCH_PATHS 11 | ${LLVM_ROOT} 12 | $ENV{LLVM_ROOT} 13 | ) 14 | 15 | set(LIBCLANG_STATIC_LIBRARY_NAME 16 | "libclang${CMAKE_STATIC_LIBRARY_SUFFIX}" 17 | ) 18 | 19 | set(LIBCLANG_SHARED_LIBRARY_NAME 20 | "libclang${CMAKE_SHARED_LIBRARY_SUFFIX}" 21 | ) 22 | 23 | # include directories 24 | find_path(LLVM_INCLUDE_DIRS 25 | NAMES "clang-c/Index.h" 26 | PATHS ${LLVM_SEARCH_PATHS} 27 | PATH_SUFFIXES "include" 28 | ) 29 | 30 | if (LIBCLANG_USE_STATIC_LIBRARY) 31 | # find static library directory 32 | find_path(LLVM_LIBRARY_DIR 33 | NAMES ${LIBCLANG_STATIC_LIBRARY_NAME} 34 | PATHS ${LLVM_SEARCH_PATHS} 35 | PATH_SUFFIXES "lib" "bin" 36 | ) 37 | endif () 38 | 39 | # shared library directory 40 | find_path(LLVM_BINARY_DIR 41 | NAMES ${LIBCLANG_SHARED_LIBRARY_NAME} 42 | PATHS ${LLVM_SEARCH_PATHS} 43 | PATH_SUFFIXES "bin" "lib" 44 | ) 45 | 46 | # unable to find everything 47 | if (NOT LLVM_INCLUDE_DIRS OR 48 | NOT LLVM_BINARY_DIR OR 49 | (NOT LLVM_LIBRARY_DIR AND LIBCLANG_USE_STATIC_LIBRARY)) 50 | message(SEND_ERROR 51 | "Unable to find LLVM installation. " 52 | "Make sure that \"LLVM_ROOT\" is set with the installation directory in either an environment variable or through the CMake GUI." 53 | ) 54 | endif () 55 | 56 | set(LIBCLANG_SHARED_LIBRARY 57 | "${LLVM_BINARY_DIR}/${LIBCLANG_SHARED_LIBRARY_NAME}" 58 | ) 59 | 60 | if (LIBCLANG_USE_STATIC_LIBRARY) 61 | set(LIBCLANG_LIBRARY 62 | "${LLVM_LIBRARY_DIR}/${LIBCLANG_STATIC_LIBRARY_NAME}" 63 | ) 64 | else () 65 | # we can assume this is a unix system, in which case we link to the shared object file 66 | set(LIBCLANG_LIBRARY ${LIBCLANG_SHARED_LIBRARY}) 67 | endif () -------------------------------------------------------------------------------- /Source/CMake/Precompiled.cmake: -------------------------------------------------------------------------------- 1 | function (set_precompiled_header target header source) 2 | if (MSVC) 3 | set_target_properties(${target} PROPERTIES 4 | COMPILE_FLAGS "/Yu${header}" 5 | ) 6 | 7 | set_source_files_properties(${source} PROPERTIES 8 | COMPILE_FLAGS "/Yc${header}" 9 | ) 10 | endif () 11 | endfunction () -------------------------------------------------------------------------------- /Source/Common/Compiler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__clang__) 4 | 5 | #define COMPILER_CLANG 6 | 7 | #elif defined(__GNUC__) || defined(__GNUG__) 8 | 9 | #define COMPILER_GNU 10 | 11 | #elif defined(_MSC_VER) && !__INTEL_COMPILER 12 | 13 | #define COMPILER_MSVC 14 | 15 | #endif -------------------------------------------------------------------------------- /Source/Common/Logging.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Logging.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #define UAssert(assertion, ...) (!!(assertion) || \ 10 | (ursine::logging::Assert(__FILE__, __FUNCTION__, __LINE__,##__VA_ARGS__), 0)) \ 11 | 12 | namespace ursine 13 | { 14 | namespace logging 15 | { 16 | template 17 | void Assert( 18 | const std::string &file, 19 | const std::string &function, 20 | unsigned line, 21 | const std::string &format, 22 | const Args&... args 23 | ); 24 | } 25 | } 26 | 27 | #include "Logging.hpp" -------------------------------------------------------------------------------- /Source/Common/Logging.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Logging.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace ursine 12 | { 13 | namespace logging 14 | { 15 | template 16 | void Assert( 17 | const std::string &file, 18 | const std::string &function, 19 | unsigned line, 20 | const std::string &format, 21 | const Args&... args 22 | ) 23 | { 24 | std::cerr << "----- Assertion Failed -----" << std::endl 25 | << "----------------------------" << std::endl; 26 | 27 | std::fprintf( stderr, format.c_str( ), args... ); 28 | 29 | std::cerr << std::endl; 30 | std::cerr << "----------------------------" << std::endl; 31 | std::cerr << "file: " << file << std::endl; 32 | std::cerr << "function: " << function << std::endl; 33 | std::cerr << "line: " << line << std::endl; 34 | std::cerr << "----------------------------" << std::endl; 35 | std::cerr << std::endl; 36 | 37 | std::abort( ); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Source/Parser/Cursor.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Cursor.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "CursorType.h" 10 | 11 | class Cursor 12 | { 13 | public: 14 | typedef std::vector List; 15 | typedef CXCursorVisitor Visitor; 16 | 17 | Cursor(const CXCursor &handle); 18 | 19 | CXCursorKind GetKind(void) const; 20 | 21 | Cursor GetLexicalParent(void) const; 22 | Cursor GetTemplateSpecialization(void) const; 23 | 24 | std::string GetSpelling(void) const; 25 | std::string GetDisplayName(void) const; 26 | std::string GetMangledName(void) const; 27 | std::string GetUSR(void) const; 28 | 29 | std::string GetSourceFile(void) const; 30 | 31 | bool IsDefinition(void) const; 32 | bool IsConst(void) const; 33 | bool IsStatic(void) const; 34 | 35 | CX_CXXAccessSpecifier GetAccessModifier(void) const; 36 | CX_StorageClass GetStorageClass(void) const; 37 | 38 | CursorType GetType(void) const; 39 | CursorType GetReturnType(void) const; 40 | CursorType GetTypedefType(void) const; 41 | 42 | List GetChildren(void) const; 43 | void VisitChildren(Visitor visitor, void *data = nullptr); 44 | 45 | unsigned GetHash(void) const; 46 | 47 | private: 48 | CXCursor m_handle; 49 | }; -------------------------------------------------------------------------------- /Source/Parser/CursorType.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** CursorType.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "CursorType.h" 10 | 11 | CursorType::CursorType(const CXType &handle) 12 | : m_handle( handle ) 13 | { 14 | 15 | } 16 | 17 | std::string CursorType::GetDisplayName(void) const 18 | { 19 | std::string displayName; 20 | 21 | utils::ToString( clang_getTypeSpelling( m_handle ), displayName ); 22 | 23 | return displayName; 24 | } 25 | 26 | int CursorType::GetArgumentCount(void) const 27 | { 28 | return clang_getNumArgTypes( m_handle ); 29 | } 30 | 31 | CursorType CursorType::GetArgument(unsigned index) const 32 | { 33 | return clang_getArgType( m_handle, index ); 34 | } 35 | 36 | CursorType CursorType::GetCanonicalType(void) const 37 | { 38 | return clang_getCanonicalType( m_handle ); 39 | } 40 | 41 | Cursor CursorType::GetDeclaration(void) const 42 | { 43 | return clang_getTypeDeclaration( m_handle ); 44 | } 45 | 46 | CXTypeKind CursorType::GetKind(void) const 47 | { 48 | return m_handle.kind; 49 | } 50 | 51 | bool CursorType::IsConst(void) const 52 | { 53 | return clang_isConstQualifiedType( m_handle ) ? true : false; 54 | } -------------------------------------------------------------------------------- /Source/Parser/CursorType.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** CursorType.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | class Cursor; 10 | 11 | class CursorType 12 | { 13 | public: 14 | CursorType(const CXType &handle); 15 | 16 | std::string GetDisplayName(void) const; 17 | 18 | int GetArgumentCount(void) const; 19 | CursorType GetArgument(unsigned index) const; 20 | 21 | CursorType GetCanonicalType(void) const; 22 | 23 | Cursor GetDeclaration(void) const; 24 | 25 | CXTypeKind GetKind(void) const; 26 | 27 | bool IsConst(void) const; 28 | 29 | private: 30 | CXType m_handle; 31 | }; -------------------------------------------------------------------------------- /Source/Parser/LanguageTypes/Class.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Class.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "LanguageType.h" 10 | 11 | #include "LanguageTypes/Constructor.h" 12 | #include "LanguageTypes/Field.h" 13 | #include "LanguageTypes/Global.h" 14 | #include "LanguageTypes/Method.h" 15 | #include "LanguageTypes/Function.h" 16 | 17 | struct BaseClass 18 | { 19 | BaseClass(const Cursor &cursor); 20 | 21 | std::string name; 22 | }; 23 | 24 | class Class : public LanguageType 25 | { 26 | // to access m_qualifiedName 27 | friend class Global; 28 | friend class Function; 29 | friend class Method; 30 | friend class Constructor; 31 | friend class Field; 32 | 33 | public: 34 | Class(const Cursor &cursor, const Namespace ¤tNamespace); 35 | 36 | virtual bool ShouldCompile(void) const; 37 | 38 | TemplateData CompileTemplate( 39 | const ReflectionParser *context 40 | ) const override; 41 | 42 | private: 43 | std::string m_name; 44 | std::string m_displayName; 45 | std::string m_qualifiedName; 46 | 47 | template 48 | using SharedPtrVector = std::vector>; 49 | 50 | SharedPtrVector m_baseClasses; 51 | 52 | SharedPtrVector m_constructors; 53 | 54 | SharedPtrVector m_fields; 55 | SharedPtrVector m_staticFields; 56 | 57 | SharedPtrVector m_methods; 58 | SharedPtrVector m_staticMethods; 59 | 60 | bool isAccessible(void) const; 61 | }; 62 | -------------------------------------------------------------------------------- /Source/Parser/LanguageTypes/Constructor.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Constructor.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "LanguageTypes/Class.h" 10 | #include "LanguageTypes/Constructor.h" 11 | 12 | #include 13 | 14 | Constructor::Constructor( 15 | const Cursor &cursor, 16 | const Namespace ¤tNamespace, 17 | Class *parent 18 | ) 19 | : LanguageType( cursor, currentNamespace ) 20 | , Invokable( cursor ) 21 | , m_parent( parent ) 22 | { 23 | 24 | } 25 | 26 | bool Constructor::ShouldCompile(void) const 27 | { 28 | return isAccessible( ); 29 | } 30 | 31 | TemplateData Constructor::CompileTemplate( 32 | const ReflectionParser *context 33 | ) const 34 | { 35 | TemplateData data { TemplateData::Type::Object }; 36 | 37 | data[ "parentQualifiedName" ] = m_parent->m_qualifiedName; 38 | 39 | auto enableNonDynamic = !m_metaData.GetFlag( native_property::DisableNonDynamicCtor ); 40 | 41 | if (enableNonDynamic) 42 | data[ "templateParameters" ] = getTemplateParameters( false ); 43 | 44 | data[ "dynamicTemplateParameters" ] = getTemplateParameters( true ); 45 | 46 | data[ "enableNonDynamic" ] = utils::TemplateBool( enableNonDynamic ); 47 | 48 | m_metaData.CompileTemplateData( data, context ); 49 | 50 | return data; 51 | } 52 | 53 | bool Constructor::isAccessible(void) const 54 | { 55 | if (m_accessModifier != CX_CXXPublic) 56 | return false; 57 | 58 | // if the parent wants white listed method, then we must have 59 | // the enable flag 60 | if (m_parent->GetMetaData( ).GetFlag( native_property::WhiteListMethods )) 61 | return m_metaData.GetFlag( native_property::Enable ); 62 | 63 | // must not be explicitly disabled 64 | return !m_metaData.GetFlag( native_property::Disable ); 65 | } 66 | 67 | std::string Constructor::getTemplateParameters(bool isDynamic) const 68 | { 69 | std::vector params; 70 | 71 | // ClassType 72 | params.push_back( m_parent->m_qualifiedName ); 73 | 74 | // IsDynamic 75 | params.emplace_back( isDynamic ? "true" : "false" ); 76 | 77 | // IsWrapped 78 | params.emplace_back( 79 | m_metaData.GetFlag( native_property::DynamicCtorWrap ) ? "true" : "false" 80 | ); 81 | 82 | // Args... 83 | params.insert( params.end( ), m_signature.begin( ), m_signature.end( ) ); 84 | 85 | return boost::join( params, ", " ); 86 | } -------------------------------------------------------------------------------- /Source/Parser/LanguageTypes/Constructor.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Constructor.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "LanguageType.h" 10 | #include "Invokable.h" 11 | 12 | class Class; 13 | 14 | class Constructor 15 | : public LanguageType 16 | , public Invokable 17 | { 18 | public: 19 | Constructor( 20 | const Cursor &cursor, 21 | const Namespace ¤tNamespace, 22 | Class *parent = nullptr 23 | ); 24 | 25 | virtual ~Constructor(void) { } 26 | 27 | bool ShouldCompile(void) const; 28 | 29 | TemplateData CompileTemplate( 30 | const ReflectionParser *context 31 | ) const override; 32 | 33 | private: 34 | Class *m_parent; 35 | 36 | bool isAccessible(void) const; 37 | 38 | std::string getTemplateParameters(bool isDynamic) const; 39 | }; -------------------------------------------------------------------------------- /Source/Parser/LanguageTypes/Enum.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Enum.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "LanguageTypes/Enum.h" 10 | 11 | Enum::Value::Value(Enum *parent, const Cursor &cursor) 12 | : key( cursor.GetDisplayName( ) ) 13 | , value( parent->m_qualifiedName + "::" + key ) 14 | { 15 | 16 | } 17 | 18 | Enum::Enum(const Cursor &cursor, const Namespace ¤tNamespace) 19 | : LanguageType( cursor, currentNamespace ) 20 | , m_name( cursor.GetType( ).GetDisplayName( ) ) 21 | , m_qualifiedName( m_name ) 22 | { 23 | auto displayName = m_metaData.GetNativeString( native_property::DisplayName ); 24 | 25 | if (displayName.empty( )) 26 | m_displayName = m_qualifiedName; 27 | else 28 | m_displayName = utils::GetQualifiedName( cursor, currentNamespace ); 29 | 30 | // it's an anonymous enum? 31 | if (m_displayName.find( "anonymous enum" ) != std::string::npos) 32 | m_displayName = ""; 33 | 34 | for (auto &child : cursor.GetChildren( )) 35 | { 36 | if (child.GetKind( ) == CXCursor_EnumConstantDecl) 37 | { 38 | MetaDataManager valueMeta( child ); 39 | 40 | // don't add disabled values 41 | if (!valueMeta.GetFlag( native_property::Disable )) 42 | m_values.emplace_back( this, child ); 43 | } 44 | } 45 | } 46 | 47 | bool Enum::ShouldCompile(void) const 48 | { 49 | return isAccessible( ); 50 | } 51 | 52 | TemplateData Enum::CompileTemplate(const ReflectionParser *context) const 53 | { 54 | TemplateData data { TemplateData::Type::Object }; 55 | 56 | data[ "displayName" ] = m_displayName; 57 | data[ "qualifiedName" ] = m_qualifiedName; 58 | data[ "ptrTypeEnabled" ] = utils::TemplateBool( m_ptrTypeEnabled ); 59 | 60 | data[ "constPtrTypeEnabled" ] = 61 | utils::TemplateBool( m_constPtrTypeEnabled ); 62 | 63 | TemplateData members { TemplateData::Type::List }; 64 | 65 | int i = 0; 66 | 67 | for (auto &value : m_values) 68 | { 69 | TemplateData member { TemplateData::Type::Object }; 70 | 71 | member[ "key" ] = value.key; 72 | member[ "value" ] = value.value; 73 | member[ "isLast" ] = utils::TemplateBool( i == m_values.size( ) - 1 ); 74 | 75 | members << member; 76 | 77 | ++i; 78 | } 79 | 80 | data[ "member" ] = members; 81 | 82 | m_metaData.CompileTemplateData( data, context ); 83 | 84 | return data; 85 | } 86 | 87 | bool Enum::isAccessible(void) const 88 | { 89 | return m_metaData.GetFlag( native_property::Enable ); 90 | } -------------------------------------------------------------------------------- /Source/Parser/LanguageTypes/Enum.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Enum.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "LanguageType.h" 10 | 11 | #include "LanguageTypes/Global.h" 12 | 13 | class Enum : public LanguageType 14 | { 15 | public: 16 | struct Value 17 | { 18 | Value(Enum *parent, const Cursor &cursor); 19 | 20 | std::string key; 21 | std::string value; 22 | }; 23 | 24 | friend struct Value; 25 | 26 | Enum(const Cursor &cursor, const Namespace ¤tNamespace); 27 | virtual ~Enum(void) { } 28 | 29 | bool ShouldCompile(void) const; 30 | 31 | TemplateData CompileTemplate( 32 | const ReflectionParser *context 33 | ) const override; 34 | 35 | private: 36 | std::string m_name; 37 | std::string m_displayName; 38 | std::string m_qualifiedName; 39 | 40 | std::vector m_values; 41 | 42 | bool isAccessible(void) const; 43 | }; -------------------------------------------------------------------------------- /Source/Parser/LanguageTypes/External.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** External.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "External.h" 10 | 11 | External::External(const Cursor &cursor) 12 | : Class( cursor, { } ) 13 | { 14 | 15 | } 16 | 17 | bool External::ShouldCompile(void) const 18 | { 19 | return true; 20 | } -------------------------------------------------------------------------------- /Source/Parser/LanguageTypes/External.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** External.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "LanguageTypes/Class.h" 10 | 11 | class External : public Class 12 | { 13 | public: 14 | External(const Cursor &cursor); 15 | 16 | bool ShouldCompile(void) const override; 17 | }; -------------------------------------------------------------------------------- /Source/Parser/LanguageTypes/Field.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Field.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "LanguageTypes/Class.h" 10 | #include "LanguageTypes/Field.h" 11 | 12 | Field::Field( 13 | const Cursor &cursor, 14 | const Namespace ¤tNamespace, 15 | Class *parent 16 | ) 17 | : LanguageType( cursor, currentNamespace ) 18 | , m_isConst( cursor.GetType( ).IsConst( ) ) 19 | , m_parent( parent ) 20 | , m_name( cursor.GetSpelling( ) ) 21 | , m_type( utils::GetQualifiedName( cursor.GetType( ) ) ) 22 | { 23 | auto displayName = m_metaData.GetNativeString( native_property::DisplayName ); 24 | 25 | if (displayName.empty( )) 26 | m_displayName = m_name; 27 | else 28 | m_displayName = displayName; 29 | 30 | m_explicitGetter = m_metaData.GetNativeString( native_property::ExplicitGetter ); 31 | m_veryExplicitGetter = m_metaData.GetNativeString( native_property::VeryExplicitGetter ); 32 | m_hasExplicitGetter = !m_explicitGetter.empty( ) || !m_veryExplicitGetter.empty( ); 33 | 34 | m_explicitSetter = m_metaData.GetNativeString( native_property::ExplicitSetter ); 35 | m_hasExplicitSetter = !m_explicitSetter.empty( ); 36 | } 37 | 38 | bool Field::ShouldCompile(void) const 39 | { 40 | return isAccessible( ); 41 | } 42 | 43 | TemplateData Field::CompileTemplate(const ReflectionParser *context) const 44 | { 45 | TemplateData data = { TemplateData::Type::Object }; 46 | 47 | data[ "name" ] = m_name; 48 | data[ "displayName" ] = m_displayName; 49 | data[ "type" ] = m_type; 50 | 51 | data[ "hasParent" ] = utils::TemplateBool( !!m_parent ); 52 | 53 | data[ "parentQualifiedName" ] = m_parent->m_qualifiedName; 54 | 55 | // getter 56 | 57 | data[ "isGetterAccessible" ] = utils::TemplateBool( isGetterAccessible( ) ); 58 | data[ "hasExplicitGetter" ] = utils::TemplateBool( m_hasExplicitGetter ); 59 | 60 | if (m_hasExplicitGetter) 61 | { 62 | std::string explicitGetter; 63 | 64 | if (m_parent && m_veryExplicitGetter.empty( )) 65 | { 66 | explicitGetter = "&"+ m_parent->m_qualifiedName + "::" + m_explicitGetter; 67 | } 68 | else 69 | { 70 | explicitGetter = m_veryExplicitGetter; 71 | } 72 | 73 | data[ "explicitGetter" ] = explicitGetter; 74 | } 75 | 76 | data[ "getterBody" ] = context->LoadTemplatePartial( kPartialFieldGetter ); 77 | 78 | // setter 79 | 80 | data[ "isSetterAccessible" ] = utils::TemplateBool( isSetterAccessible( ) ); 81 | data[ "hasExplicitSetter" ] = utils::TemplateBool( m_hasExplicitSetter ); 82 | data[ "explicitSetter" ] = m_explicitSetter; 83 | data[ "setterBody" ] = context->LoadTemplatePartial( kPartialFieldSetter ); 84 | 85 | m_metaData.CompileTemplateData( data, context ); 86 | 87 | return data; 88 | } 89 | 90 | bool Field::isAccessible(void) const 91 | { 92 | return (m_hasExplicitGetter || m_hasExplicitSetter) || 93 | ( 94 | m_accessModifier == CX_CXXPublic && 95 | !m_metaData.GetFlag( native_property::Disable ) 96 | ); 97 | } 98 | 99 | bool Field::isGetterAccessible(void) const 100 | { 101 | return m_hasExplicitGetter || m_accessModifier == CX_CXXPublic; 102 | } 103 | 104 | bool Field::isSetterAccessible(void) const 105 | { 106 | return m_hasExplicitSetter || 107 | (!m_isConst && m_accessModifier == CX_CXXPublic); 108 | } -------------------------------------------------------------------------------- /Source/Parser/LanguageTypes/Field.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Field.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "LanguageType.h" 10 | 11 | class Class; 12 | 13 | class Field : public LanguageType 14 | { 15 | public: 16 | Field( 17 | const Cursor &cursor, 18 | const Namespace ¤tNamespace, 19 | Class *parent = nullptr 20 | ); 21 | 22 | virtual ~Field(void) { } 23 | 24 | bool ShouldCompile(void) const; 25 | 26 | TemplateData CompileTemplate( 27 | const ReflectionParser *context 28 | ) const override; 29 | 30 | private: 31 | bool m_isConst; 32 | 33 | bool m_hasExplicitGetter; 34 | bool m_hasExplicitSetter; 35 | 36 | Class *m_parent; 37 | 38 | std::string m_name; 39 | std::string m_displayName; 40 | std::string m_type; 41 | 42 | std::string m_explicitGetter; 43 | std::string m_explicitSetter; 44 | 45 | std::string m_veryExplicitGetter; 46 | std::string m_veryExplicitSetter; 47 | 48 | bool isAccessible(void) const; 49 | bool isGetterAccessible(void) const; 50 | bool isSetterAccessible(void) const; 51 | }; -------------------------------------------------------------------------------- /Source/Parser/LanguageTypes/Function.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Function.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "LanguageTypes/Function.h" 10 | #include "LanguageTypes/Class.h" 11 | 12 | #include 13 | #include 14 | 15 | Function::Function( 16 | const Cursor &cursor, 17 | const Namespace ¤tNamespace, 18 | Class *parent 19 | ) 20 | : LanguageType( cursor, currentNamespace ) 21 | , Invokable( cursor ) 22 | , m_parent( parent ) 23 | , m_name( cursor.GetSpelling( ) ) 24 | , m_qualifiedName( utils::GetQualifiedName( cursor, currentNamespace ) ) 25 | { 26 | 27 | } 28 | 29 | bool Function::ShouldCompile(void) const 30 | { 31 | return isAccessible( ); 32 | } 33 | 34 | TemplateData Function::CompileTemplate(const ReflectionParser *context) const 35 | { 36 | TemplateData data { TemplateData::Type::Object }; 37 | 38 | data[ "name" ] = m_name; 39 | data[ "qualifiedName" ] = m_qualifiedName; 40 | 41 | if (m_parent) 42 | data[ "parentQualifiedName" ] = m_parent->m_qualifiedName; 43 | 44 | data[ "qualifiedSignature" ] = getQualifiedSignature( ); 45 | 46 | m_metaData.CompileTemplateData( data, context ); 47 | 48 | return data; 49 | } 50 | 51 | bool Function::isAccessible(void) const 52 | { 53 | if (m_parent && m_accessModifier != CX_CXXPublic) 54 | return false; 55 | 56 | return m_enabled; 57 | } 58 | 59 | std::string Function::getQualifiedSignature(void) const 60 | { 61 | auto argsList = boost::join( m_signature, ", " ); 62 | 63 | return (boost::format( "%1%(*)(%2%)" ) % m_returnType % argsList).str( ); 64 | } -------------------------------------------------------------------------------- /Source/Parser/LanguageTypes/Function.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Function.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "LanguageType.h" 10 | #include "Invokable.h" 11 | 12 | class Class; 13 | 14 | class Function 15 | : public LanguageType 16 | , public Invokable 17 | { 18 | public: 19 | Function( 20 | const Cursor &cursor, 21 | const Namespace ¤tNamespace, 22 | Class *parent = nullptr 23 | ); 24 | 25 | virtual ~Function(void) { } 26 | 27 | bool ShouldCompile(void) const; 28 | 29 | TemplateData CompileTemplate( 30 | const ReflectionParser *context 31 | ) const override; 32 | 33 | private: 34 | Class *m_parent; 35 | 36 | std::string m_name; 37 | std::string m_qualifiedName; 38 | 39 | bool isAccessible(void) const; 40 | 41 | std::string getQualifiedSignature(void) const; 42 | }; -------------------------------------------------------------------------------- /Source/Parser/LanguageTypes/Global.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Global.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "LanguageTypes/Global.h" 10 | #include "LanguageTypes/Class.h" 11 | 12 | Global::Global( 13 | const Cursor &cursor, 14 | const Namespace ¤tNamespace, 15 | Class *parent 16 | ) 17 | : LanguageType( cursor, currentNamespace ) 18 | , m_isConst( cursor.GetType( ).IsConst( ) ) 19 | , m_hasExplicitGetter( m_metaData.GetFlag( native_property::ExplicitGetter ) ) 20 | , m_hasExplicitSetter( m_metaData.GetFlag( native_property::ExplicitSetter ) ) 21 | , m_parent( parent ) 22 | , m_name( cursor.GetSpelling( ) ) 23 | , m_qualifiedName( utils::GetQualifiedName( cursor, currentNamespace ) ) 24 | , m_type( utils::GetQualifiedName( cursor.GetType( ) ) ) 25 | { 26 | auto displayName = m_metaData.GetNativeString( native_property::DisplayName ); 27 | 28 | if (displayName.empty( )) 29 | { 30 | m_displayName = m_qualifiedName; 31 | } 32 | else 33 | { 34 | m_displayName = 35 | utils::GetQualifiedName( displayName, currentNamespace ); 36 | } 37 | } 38 | 39 | bool Global::ShouldCompile(void) const 40 | { 41 | return isAccessible( ); 42 | } 43 | 44 | TemplateData Global::CompileTemplate(const ReflectionParser *context) const 45 | { 46 | TemplateData data = { TemplateData::Type::Object }; 47 | 48 | data[ "name" ] = m_name; 49 | data[ "displayName" ] = m_displayName; 50 | data[ "qualifiedName" ] = m_qualifiedName; 51 | data[ "type" ] = m_type; 52 | 53 | data[ "hasParent" ] = utils::TemplateBool( !!m_parent ); 54 | 55 | if (m_parent) 56 | data[ "parentQualifiedName" ] = m_parent->m_qualifiedName; 57 | 58 | // getter 59 | 60 | data[ "isGetterAccessible" ] = 61 | utils::TemplateBool( isGetterAccessible( ) ); 62 | 63 | data[ "hasExplicitGetter" ] = 64 | utils::TemplateBool( m_hasExplicitGetter ); 65 | 66 | data[ "explicitGetter" ] = 67 | m_metaData.GetProperty( native_property::ExplicitGetter ); 68 | 69 | data[ "getterBody" ] = 70 | context->LoadTemplatePartial( kPartialGlobalGetter ); 71 | 72 | // setter 73 | 74 | data[ "isSetterAccessible" ] = 75 | utils::TemplateBool( isSetterAccessible( ) ); 76 | 77 | data[ "hasExplicitSetter" ] = 78 | utils::TemplateBool( m_hasExplicitSetter ); 79 | 80 | data[ "explicitSetter" ] = 81 | m_metaData.GetProperty( native_property::ExplicitSetter ); 82 | 83 | data[ "setterBody" ] = 84 | context->LoadTemplatePartial( kPartialGlobalSetter ); 85 | 86 | m_metaData.CompileTemplateData( data, context ); 87 | 88 | return data; 89 | } 90 | 91 | bool Global::isAccessible(void) const 92 | { 93 | return isGetterAccessible( ) || isSetterAccessible( ); 94 | } 95 | 96 | bool Global::isGetterAccessible(void) const 97 | { 98 | if (m_enabled) 99 | { 100 | if (m_parent) 101 | return m_hasExplicitGetter || m_accessModifier == CX_CXXPublic; 102 | 103 | return true; 104 | } 105 | 106 | return false; 107 | } 108 | 109 | bool Global::isSetterAccessible(void) const 110 | { 111 | if (m_isConst) 112 | return false; 113 | 114 | if (m_enabled) 115 | { 116 | if (m_parent) 117 | return m_hasExplicitSetter || m_accessModifier == CX_CXXPublic; 118 | 119 | return true; 120 | } 121 | 122 | return false; 123 | } -------------------------------------------------------------------------------- /Source/Parser/LanguageTypes/Global.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Global.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "LanguageType.h" 10 | 11 | class Class; 12 | 13 | class Global : public LanguageType 14 | { 15 | public: 16 | Global( 17 | const Cursor &cursor, 18 | const Namespace ¤tNamespace, 19 | Class *parent = nullptr 20 | ); 21 | 22 | virtual ~Global(void) { } 23 | 24 | bool ShouldCompile(void) const; 25 | 26 | TemplateData CompileTemplate( 27 | const ReflectionParser *context 28 | ) const override; 29 | 30 | private: 31 | bool m_isConst; 32 | 33 | bool m_hasExplicitGetter; 34 | bool m_hasExplicitSetter; 35 | 36 | Class *m_parent; 37 | 38 | std::string m_name; 39 | std::string m_displayName; 40 | std::string m_qualifiedName; 41 | std::string m_type; 42 | 43 | bool isAccessible(void) const; 44 | bool isGetterAccessible(void) const; 45 | bool isSetterAccessible(void) const; 46 | }; -------------------------------------------------------------------------------- /Source/Parser/LanguageTypes/Invokable.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Invokable.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "LanguageTypes/Invokable.h" 10 | 11 | Invokable::Invokable(const Cursor &cursor) 12 | : m_returnType( utils::GetQualifiedName( cursor.GetReturnType( ) )) 13 | { 14 | auto type = cursor.GetType( ); 15 | unsigned count = type.GetArgumentCount( ); 16 | 17 | m_signature.clear( ); 18 | 19 | for (unsigned i = 0; i < count; ++i) 20 | { 21 | auto argument = type.GetArgument( i ); 22 | 23 | m_signature.emplace_back( 24 | utils::GetQualifiedName( argument ) 25 | ); 26 | } 27 | } -------------------------------------------------------------------------------- /Source/Parser/LanguageTypes/Invokable.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Invokable.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "Cursor.h" 10 | #include "Namespace.h" 11 | 12 | class Invokable 13 | { 14 | public: 15 | typedef std::vector Signature; 16 | 17 | Invokable(const Cursor &cursor); 18 | 19 | protected: 20 | std::string m_returnType; 21 | 22 | Signature m_signature; 23 | }; 24 | 25 | const auto kReturnTypeVoid = "void"; -------------------------------------------------------------------------------- /Source/Parser/LanguageTypes/LanguageType.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** LanguageType.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "LanguageType.h" 10 | 11 | LanguageType::LanguageType( 12 | const Cursor &cursor, 13 | const Namespace ¤tNamespace 14 | ) 15 | : m_metaData( cursor ) 16 | , m_enabled( m_metaData.GetFlag( native_property::Enable ) ) 17 | , m_ptrTypeEnabled( m_metaData.GetFlag( native_property::EnablePtrType ) ) 18 | , m_constPtrTypeEnabled( m_metaData.GetFlag( native_property::EnableConstPtrType ) ) 19 | , m_arrayTypeEnabled( m_metaData.GetFlag( native_property::EnableArrayType ) ) 20 | , m_accessModifier( cursor.GetAccessModifier( ) ) 21 | , m_rootCursor( cursor ) 22 | { 23 | 24 | } 25 | 26 | const MetaDataManager &LanguageType::GetMetaData(void) const 27 | { 28 | return m_metaData; 29 | } 30 | 31 | std::string LanguageType::GetSourceFile(void) const 32 | { 33 | return m_rootCursor.GetSourceFile( ); 34 | } -------------------------------------------------------------------------------- /Source/Parser/LanguageTypes/LanguageType.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** LanguageType.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "Cursor.h" 10 | #include "Namespace.h" 11 | 12 | #include "MetaDataManager.h" 13 | #include "ReflectionParser.h" 14 | 15 | class LanguageType 16 | { 17 | public: 18 | LanguageType(const Cursor &cursor, const Namespace ¤tNamespace); 19 | virtual ~LanguageType(void) { } 20 | 21 | const MetaDataManager &GetMetaData(void) const; 22 | 23 | std::string GetSourceFile(void) const; 24 | 25 | virtual TemplateData CompileTemplate( 26 | const ReflectionParser *context 27 | ) const = 0; 28 | 29 | protected: 30 | MetaDataManager m_metaData; 31 | 32 | // determines if the type is enabled in reflection database generation 33 | bool m_enabled; 34 | 35 | // determines if the pointer type to this type will be generated 36 | // in the reflection database 37 | bool m_ptrTypeEnabled; 38 | 39 | // determines if the constant pointer type to this type will be 40 | // generated in the reflection database 41 | bool m_constPtrTypeEnabled; 42 | 43 | // determines if this type generates data for its respective array type 44 | bool m_arrayTypeEnabled; 45 | 46 | CX_CXXAccessSpecifier m_accessModifier; 47 | 48 | private: 49 | // cursor that represents the root of this language type 50 | Cursor m_rootCursor; 51 | }; -------------------------------------------------------------------------------- /Source/Parser/LanguageTypes/Method.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Method.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "LanguageTypes/Class.h" 10 | #include "LanguageTypes/Method.h" 11 | 12 | #include 13 | #include 14 | 15 | Method::Method( 16 | const Cursor &cursor, 17 | const Namespace ¤tNamespace, 18 | Class *parent 19 | ) 20 | : LanguageType( cursor, currentNamespace ) 21 | , Invokable( cursor ) 22 | , m_isConst( cursor.IsConst( ) ) 23 | , m_parent( parent ) 24 | , m_name( cursor.GetSpelling( ) ) 25 | { 26 | 27 | } 28 | 29 | bool Method::ShouldCompile(void) const 30 | { 31 | return isAccessible( ); 32 | } 33 | 34 | TemplateData Method::CompileTemplate(const ReflectionParser *context) const 35 | { 36 | TemplateData data { TemplateData::Type::Object }; 37 | 38 | data[ "name" ] = m_name; 39 | 40 | data[ "parentQualifiedName" ] = m_parent->m_qualifiedName; 41 | 42 | data[ "qualifiedSignature" ] = getQualifiedSignature( ); 43 | 44 | m_metaData.CompileTemplateData( data, context ); 45 | 46 | return data; 47 | } 48 | 49 | bool Method::isAccessible(void) const 50 | { 51 | if (m_accessModifier != CX_CXXPublic) 52 | return false; 53 | 54 | // if the parent wants white listed method, then we must have 55 | // the enable flag 56 | if (m_parent->GetMetaData( ).GetFlag( native_property::WhiteListMethods )) 57 | return m_metaData.GetFlag( native_property::Enable ); 58 | 59 | // must not be explicitly disabled 60 | return !m_metaData.GetFlag( native_property::Disable ); 61 | } 62 | 63 | std::string Method::getQualifiedSignature(void) const 64 | { 65 | auto argsList = boost::join( m_signature, ", " ); 66 | 67 | std::string constNess = m_isConst ? " const" : ""; 68 | 69 | return (boost::format( "%1%(%2%::*)(%3%)%4%" ) % 70 | m_returnType % 71 | m_parent->m_qualifiedName % 72 | argsList % constNess 73 | ).str( ); 74 | } -------------------------------------------------------------------------------- /Source/Parser/LanguageTypes/Method.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Method.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "LanguageType.h" 10 | #include "Invokable.h" 11 | 12 | class Class; 13 | 14 | class Method 15 | : public LanguageType 16 | , public Invokable 17 | { 18 | public: 19 | Method( 20 | const Cursor &cursor, 21 | const Namespace ¤tNamespace, 22 | Class *parent = nullptr 23 | ); 24 | 25 | virtual ~Method(void) { } 26 | 27 | bool ShouldCompile(void) const; 28 | 29 | TemplateData CompileTemplate( 30 | const ReflectionParser *context 31 | ) const override; 32 | 33 | private: 34 | bool m_isConst; 35 | 36 | Class *m_parent; 37 | 38 | std::string m_name; 39 | 40 | bool isAccessible(void) const; 41 | 42 | std::string getQualifiedSignature(void) const; 43 | }; -------------------------------------------------------------------------------- /Source/Parser/MetaDataConfig.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** MetaDataConfig.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | namespace native_property 10 | { 11 | const auto Enable = "Enable"; 12 | const auto Disable = "Disable"; 13 | const auto WhiteListMethods = "WhiteListMethods"; 14 | 15 | const auto Register = "Register"; 16 | 17 | const auto DisplayName = "DisplayName"; 18 | 19 | const auto EnablePtrType = "EnablePtrType"; 20 | const auto EnableConstPtrType = "EnableConstPtrType"; 21 | 22 | const auto EnableArrayType = "EnableArrayType"; 23 | 24 | const auto DisableNonDynamicCtor = "DisableNonDynamic"; 25 | const auto DynamicCtorWrap = "WrapObject"; 26 | 27 | const auto ExplicitGetter = "Getter"; 28 | const auto ExplicitSetter = "Setter"; 29 | 30 | const auto VeryExplicitGetter = "ExplicitGetter"; 31 | const auto VeryExplicitSetter = "ExplicitSetter"; 32 | } 33 | 34 | const auto kMetaExternalTypeDefName = "__META_EXTERNAL__"; -------------------------------------------------------------------------------- /Source/Parser/MetaDataManager.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** MetaDataManager.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "Cursor.h" 10 | 11 | class ReflectionParser; 12 | 13 | class MetaDataManager 14 | { 15 | public: 16 | MetaDataManager(const Cursor &cursor); 17 | 18 | std::string GetProperty(const std::string &key) const; 19 | bool GetFlag(const std::string &key) const; 20 | 21 | std::string GetNativeString(const std::string &key) const; 22 | 23 | void CompileTemplateData( 24 | TemplateData &data, 25 | const ReflectionParser *context 26 | ) const; 27 | private: 28 | typedef std::pair Property; 29 | 30 | std::unordered_map m_properties; 31 | 32 | std::vector extractProperties(const Cursor &cursor) const; 33 | }; -------------------------------------------------------------------------------- /Source/Parser/MetaUtils.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** MetaUtils.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "Cursor.h" 10 | #include "Namespace.h" 11 | 12 | #include "Mustache.h" 13 | 14 | namespace utils 15 | { 16 | void ToString(const CXString &str, std::string &output); 17 | 18 | Mustache::Data::Type TemplateBool(bool value); 19 | 20 | std::string GetQualifiedName(const CursorType &type); 21 | 22 | std::string GetQualifiedName( 23 | const std::string &displayName, 24 | const Namespace ¤tNamespace 25 | ); 26 | 27 | std::string GetQualifiedName( 28 | const Cursor &cursor, 29 | const Namespace ¤tNamespace 30 | ); 31 | 32 | void LoadText(const std::string &filename, std::string &output); 33 | void WriteText(const std::string &filename, const std::string &text); 34 | 35 | boost::filesystem::path MakeRelativePath( 36 | const boost::filesystem::path &from, 37 | const boost::filesystem::path &to 38 | ); 39 | 40 | void FatalError(const std::string &error); 41 | 42 | template 43 | bool RangeEqual(A startA, A endA, B startB, B endB); 44 | } 45 | 46 | #include "MetaUtils.hpp" -------------------------------------------------------------------------------- /Source/Parser/MetaUtils.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** MetaUtils.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | namespace utils 8 | { 9 | template 10 | bool RangeEqual(A startA, A endA, B startB, B endB) 11 | { 12 | while (startA != endA && startB != endB) 13 | { 14 | if (*startA != *startB) 15 | return false; 16 | 17 | ++startA; 18 | ++startB; 19 | } 20 | 21 | return (startA == endA) && (startB == endB); 22 | } 23 | } -------------------------------------------------------------------------------- /Source/Parser/Module/ModuleFile.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** ModuleFile.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | class Class; 10 | class Global; 11 | class Function; 12 | class Enum; 13 | 14 | struct ModuleFile 15 | { 16 | std::string name; 17 | 18 | std::vector> classes; 19 | std::vector> globals; 20 | std::vector> globalFunctions; 21 | std::vector> enums; 22 | }; -------------------------------------------------------------------------------- /Source/Parser/Namespace.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Namespace.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | typedef std::vector Namespace; -------------------------------------------------------------------------------- /Source/Parser/Precompiled.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Precompiled.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | // intentionally left blank -------------------------------------------------------------------------------- /Source/Parser/Precompiled.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Precompiled.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #include 17 | 18 | #include 19 | #include 20 | 21 | #include "MetaUtils.h" 22 | #include "MetaDataConfig.h" 23 | 24 | #include 25 | 26 | using MustacheTemplate = Mustache::Mustache; 27 | using TemplateData = Mustache::Data; 28 | 29 | namespace fs = boost::filesystem; 30 | namespace po = boost::program_options; -------------------------------------------------------------------------------- /Source/Parser/ReflectionOptions.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** ReflectionOptions.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | struct ReflectionOptions 10 | { 11 | bool forceRebuild; 12 | bool displayDiagnostics; 13 | 14 | std::string targetName; 15 | 16 | std::string sourceRoot; 17 | std::string inputSourceFile; 18 | std::string moduleHeaderFile; 19 | 20 | std::string outputModuleSource; 21 | std::string outputModuleFileDirectory; 22 | 23 | std::string precompiledHeader; 24 | 25 | std::string templateDirectory; 26 | 27 | std::vector arguments; 28 | }; -------------------------------------------------------------------------------- /Source/Parser/ReflectionParser.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** ReflectionParser.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "ReflectionOptions.h" 10 | 11 | #include "Cursor.h" 12 | #include "Namespace.h" 13 | 14 | #include "Templates.h" 15 | 16 | #include "Module/ModuleFile.h" 17 | 18 | class Class; 19 | class External; 20 | class Global; 21 | class Function; 22 | class Enum; 23 | 24 | class ReflectionParser 25 | { 26 | public: 27 | ReflectionParser(const ReflectionOptions &options); 28 | ~ReflectionParser(void); 29 | 30 | void Parse(void); 31 | void GenerateFiles(void); 32 | 33 | MustacheTemplate LoadTemplate(const std::string &name) const; 34 | 35 | TemplateData::PartialType LoadTemplatePartial( 36 | const std::string &name 37 | ) const; 38 | 39 | void GenerateHeader(std::string &output) const; 40 | void GenerateSource(std::string &output) const; 41 | 42 | private: 43 | ReflectionOptions m_options; 44 | 45 | CXIndex m_index; 46 | CXTranslationUnit m_translationUnit; 47 | 48 | MustacheTemplate m_moduleFileHeaderTemplate; 49 | MustacheTemplate m_moduleFileSourceTemplate; 50 | 51 | mutable std::unordered_map< 52 | std::string, 53 | std::string 54 | > m_templatePartialCache; 55 | 56 | std::vector> m_externals; 57 | std::unordered_map m_moduleFiles; 58 | 59 | void buildClasses( 60 | const Cursor &cursor, 61 | Namespace ¤tNamespace 62 | ); 63 | 64 | void buildGlobals( 65 | const Cursor &cursor, 66 | Namespace ¤tNamespace 67 | ); 68 | 69 | void buildGlobalFunctions( 70 | const Cursor &cursor, 71 | Namespace ¤tNamespace 72 | ); 73 | 74 | void buildEnums( 75 | const Cursor &cursor, 76 | Namespace ¤tNamespace 77 | ); 78 | 79 | void addGlobalTemplateData(TemplateData &data); 80 | 81 | void generateModuleFile( 82 | const fs::path &fileHeader, 83 | const fs::path &fileSource, 84 | const std::string &sourceHeader, 85 | const ModuleFile &file 86 | ); 87 | }; -------------------------------------------------------------------------------- /Source/Parser/ReservedTypes.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** ReservedTypes.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | const auto kTypeObject = "ursine::meta::Object"; 10 | const auto kTypeMetaProperty = "ursine::meta::MetaProperty"; -------------------------------------------------------------------------------- /Source/Parser/Switches.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Switches.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #define DEFINE_SWITCH(name, value) \ 12 | const std::string kSwitch##name = value; \ 13 | const std::string kSwitch##name##Shorthand = ""; \ 14 | 15 | #define DEFINE_SWITCH_FULL(name, value, shorthand) \ 16 | const std::string kSwitch##name = value; \ 17 | const std::string kSwitch##name##Shorthand = "," shorthand; \ 18 | 19 | #define SWITCH_OPTION(name) \ 20 | ((kSwitch##name) + (kSwitch##name##Shorthand)).c_str( ) \ 21 | 22 | DEFINE_SWITCH_FULL( Help, "help", "h" ); 23 | DEFINE_SWITCH_FULL( TargetName, "target-name", "t" ); 24 | DEFINE_SWITCH_FULL( SourceRoot, "source-root", "r" ); 25 | DEFINE_SWITCH_FULL( InputSource, "in-source", "i" ); 26 | DEFINE_SWITCH_FULL( ModuleHeaderFile, "module-header", "m" ); 27 | DEFINE_SWITCH_FULL( OutputModuleSource, "out-source", "s" ); 28 | DEFINE_SWITCH_FULL( OutputModuleFileDirectory, "out-dir", "c" ); 29 | DEFINE_SWITCH_FULL( TemplateDirectory, "tmpl-directory", "d" ); 30 | DEFINE_SWITCH_FULL( PrecompiledHeader, "pch", "p" ); 31 | DEFINE_SWITCH_FULL( ForceRebuild, "force-rebuild", "e" ); 32 | DEFINE_SWITCH_FULL( DisplayDiagnostics, "display-diagnostics", "o" ); 33 | DEFINE_SWITCH_FULL( CompilerIncludes, "includes", "f" ); 34 | DEFINE_SWITCH_FULL( CompilerDefines, "defines", "x" ); 35 | -------------------------------------------------------------------------------- /Source/Parser/Templates.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Templates.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #define EXT ".mustache" 10 | 11 | const auto kTemplateModuleHeader = "module-header" EXT; 12 | const auto kTemplateModuleSource = "module-source" EXT; 13 | const auto kTemplateModuleFileHeader = "module-file-header" EXT; 14 | const auto kTemplateModuleFileSource = "module-file-source" EXT; 15 | 16 | const auto kPartialGlobalGetter = "global-getter" EXT; 17 | const auto kPartialGlobalSetter = "global-setter" EXT; 18 | 19 | const auto kPartialFieldGetter = "field-getter" EXT; 20 | const auto kPartialFieldSetter = "field-setter" EXT; 21 | 22 | const auto kPartialMetaInitializerList = "meta-initializer-list" EXT; 23 | 24 | #undef EXT -------------------------------------------------------------------------------- /Source/Parser/Tokenizer/ConstructorTokenSymbols.inl: -------------------------------------------------------------------------------- 1 | TOKEN( OpenCurley, "{" ) 2 | TOKEN( CloseCurley, "}" ) 3 | TOKEN( OpenParentheses, "(" ) 4 | TOKEN( CloseParentheses, ")" ) 5 | TOKEN( OpenBracket, "[" ) 6 | TOKEN( CloseBracket, "]" ) 7 | TOKEN( Semicolon, ";" ) 8 | TOKEN( Colon, ":" ) 9 | TOKEN( Comma, "," ) 10 | TOKEN( ScopeResolution, "::" ) 11 | TOKEN( Ternary, "?" ) 12 | TOKEN( Dot, "." ) 13 | TOKEN( Arrow, "->" ) 14 | TOKEN( Assignment, "=" ) 15 | TOKEN( LessThan, "<" ) 16 | TOKEN( LessThanOrEqualTo, "<=" ) 17 | TOKEN( GreaterThan, ">" ) 18 | TOKEN( GreaterThanOrEqualTo, ">=" ) 19 | TOKEN( Equality, "==" ) 20 | TOKEN( Inequality, "!=" ) 21 | TOKEN( Increment, "++" ) 22 | TOKEN( Decrement, "--" ) 23 | TOKEN( LogicalNot, "!" ) 24 | TOKEN( LogicalAnd, "&&" ) 25 | TOKEN( LogicalOr, "||" ) 26 | TOKEN( BitwiseNot, "~" ) 27 | TOKEN( BitwiseAndAddressOf, "&" ) 28 | TOKEN( BitwiseOr, "|" ) 29 | TOKEN( BitwiseXor, "^" ) 30 | TOKEN( Plus, "+" ) 31 | TOKEN( Minus, "-" ) 32 | TOKEN( Asterisk, "*" ) 33 | TOKEN( Divide, "/" ) 34 | TOKEN( Modulo, "%" ) 35 | TOKEN( BitshiftLeft, "<<" ) 36 | TOKEN( BitshiftRight, ">>" ) 37 | TOKEN( AssignmentPlus, "+=" ) 38 | TOKEN( AssignmentMinus, "-=" ) 39 | TOKEN( AssignmentMultiply, "*=" ) 40 | TOKEN( AssignmentDivide, "/=" ) 41 | TOKEN( AssignmentModulo, "%=" ) 42 | TOKEN( AssignmentBitshiftLeft, "<<=" ) 43 | TOKEN( AssignmentBitshiftRight, ">>=" ) 44 | TOKEN( AssignmentBitwiseAnd, "&=" ) 45 | TOKEN( AssignmentBitwiseOr, "|=" ) 46 | TOKEN( AssignmentBitwiseXor, "^=" ) -------------------------------------------------------------------------------- /Source/Parser/Tokenizer/Impl/Token.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Token.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | template 8 | Token::Token(void) 9 | : type( TokenEnumType::Invalid ) { } 10 | 11 | template 12 | Token::Token(TokenEnumType type, const InputType &value) 13 | : type( type ) 14 | , value( value ) { } -------------------------------------------------------------------------------- /Source/Parser/Tokenizer/Impl/TokenizerState.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** TokenizerState.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | template 8 | TokenizerState::TokenizerState(TokenEnumType acceptingType) 9 | : m_acceptingType( acceptingType ) 10 | , m_defaultEdge( nullptr ) { } 11 | 12 | template 13 | void TokenizerState::SetAcceptingType(TokenEnumType acceptingType) 14 | { 15 | m_acceptingType = acceptingType; 16 | } 17 | 18 | template 19 | void TokenizerState::AddEdge(Handle to, char character) 20 | { 21 | m_edges[ character ] = to; 22 | } 23 | 24 | template 25 | template 26 | void TokenizerState::AddEdge(Handle to, char character, CharacterList &&...list) 27 | { 28 | AddEdge( to, character ); 29 | AddEdge( to, list... ); 30 | } 31 | 32 | template 33 | template 34 | void TokenizerState::SetLooping(CharacterList &&...list) 35 | { 36 | AddEdge( Handle( this ), list... ); 37 | } 38 | 39 | template 40 | void TokenizerState::SetDefaultEdge(Handle defaultEdge) 41 | { 42 | m_defaultEdge = defaultEdge; 43 | } -------------------------------------------------------------------------------- /Source/Parser/Tokenizer/Token.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Token.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | template 10 | struct Token 11 | { 12 | typedef TokenEnumType EnumType; 13 | typedef InputType InputValueType; 14 | 15 | TokenEnumType type; 16 | InputType value; 17 | 18 | Token(void); 19 | Token(TokenEnumType type, const InputType &value); 20 | }; 21 | 22 | #include "Impl/Token.hpp" -------------------------------------------------------------------------------- /Source/Parser/Tokenizer/TokenType.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** TokenType.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #define TOKEN(name, value) name, 10 | 11 | enum class ConstructorTokenType 12 | { 13 | Invalid, 14 | Whitespace, 15 | Identifier, 16 | IntegerLiteral, 17 | FloatLiteral, 18 | StringLiteral, 19 | SYMBOL_START, 20 | 21 | #include "ConstructorTokenSymbols.inl" 22 | 23 | SYMBOL_END 24 | }; 25 | 26 | #undef TOKEN -------------------------------------------------------------------------------- /Source/Parser/Tokenizer/Tokenizer.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Tokenizer.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "Token.h" 10 | #include "TokenizerState.h" 11 | #include "TokenizerResult.h" 12 | 13 | template 14 | class Tokenizer 15 | { 16 | public: 17 | typedef Token TokenType; 18 | typedef TokenizerResult ResultType; 19 | typedef TokenizerState StateType; 20 | typedef typename InputType::const_iterator InputIterator; 21 | typedef std::unordered_map SymbolTable; 22 | 23 | Tokenizer(void); 24 | ~Tokenizer(void); 25 | 26 | const typename StateType::Handle GetRootState(void) const; 27 | 28 | typename StateType::Handle CreateState(TokenEnumType acceptingType = TokenEnumType::Invalid); 29 | 30 | void LoadSymbols(const SymbolTable &table); 31 | 32 | ResultType Tokenize(const InputType &input) const; 33 | 34 | private: 35 | void readToken(InputIterator start, InputIterator end, TokenType &outputToken) const; 36 | 37 | std::vector m_createdStates; 38 | 39 | typename StateType::Handle m_rootState; 40 | }; 41 | 42 | #include "Impl/Tokenizer.hpp" -------------------------------------------------------------------------------- /Source/Parser/Tokenizer/TokenizerResult.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** TokenizerResult.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | template 10 | class TokenizerResult 11 | { 12 | public: 13 | typedef std::vector TokenList; 14 | 15 | TokenizerResult(const TokenList &tokens); 16 | 17 | const TokenList &GetTokens(void) const; 18 | 19 | template 20 | size_t FindNext(size_t start, TokenTypeList &&...types); 21 | 22 | template 23 | size_t FindPrevious(size_t start, TokenTypeList &&...types); 24 | 25 | template 26 | void RemoveAll(TokenTypeList &&...types); 27 | 28 | typename TokenType::InputValueType ConsumeRange(size_t start, size_t end); 29 | 30 | template 31 | typename TokenType::InputValueType ConsumeAllPrevious(size_t start, TokenTypeList &&...types); 32 | 33 | template 34 | typename TokenType::InputValueType ConsumeAllNext(size_t start, TokenTypeList &&...types); 35 | private: 36 | TokenList m_tokens; 37 | }; 38 | 39 | #include "Impl/TokenizerResult.hpp" -------------------------------------------------------------------------------- /Source/Parser/Tokenizer/TokenizerState.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** TokenizerState.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | template 13 | class Tokenizer; 14 | 15 | template 16 | class TokenizerState 17 | { 18 | public: 19 | typedef TokenizerState* Handle; 20 | 21 | explicit TokenizerState(TokenEnumType acceptingType); 22 | 23 | void SetAcceptingType(TokenEnumType acceptingType); 24 | 25 | void AddEdge(Handle to, char character); 26 | 27 | template 28 | void AddEdge(Handle to, char character, CharacterList &&...list); 29 | 30 | template 31 | void SetLooping(CharacterList &&...list); 32 | 33 | void SetDefaultEdge(Handle defaultEdge); 34 | 35 | private: 36 | friend class Tokenizer; 37 | 38 | TokenEnumType m_acceptingType; 39 | 40 | std::unordered_map m_edges; 41 | Handle m_defaultEdge; 42 | }; 43 | 44 | #include "Impl/TokenizerState.hpp" -------------------------------------------------------------------------------- /Source/Parser/Version.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Version.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | const auto kMetaGeneratorVersion = "1.0"; -------------------------------------------------------------------------------- /Source/Runtime/Argument.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Argument.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "Argument.h" 10 | 11 | #include "Type.h" 12 | 13 | #include "Variant.h" 14 | 15 | namespace ursine 16 | { 17 | namespace meta 18 | { 19 | Argument::Argument(void) 20 | : m_typeID( InvalidTypeID ) 21 | , m_isArray( false ) 22 | , m_data( nullptr ) { } 23 | 24 | Argument::Argument(const Argument &rhs) 25 | : m_typeID( rhs.m_typeID ) 26 | , m_isArray( rhs.m_isArray ) 27 | , m_data( rhs.m_data ) { } 28 | 29 | Argument::Argument(Variant &obj) 30 | : m_typeID( obj.GetType( ).GetID( ) ) 31 | , m_isArray( obj.GetType().IsArray( ) ) 32 | , m_data( obj.getPtr( ) ) { } 33 | 34 | Argument::Argument(const Variant &obj) 35 | : m_typeID( obj.GetType( ).GetID( ) ) 36 | , m_isArray( obj.GetType( ).IsArray( ) ) 37 | , m_data( obj.getPtr( ) ) { } 38 | 39 | Argument &Argument::operator=(const Argument &rhs) 40 | { 41 | m_data = rhs.m_data; 42 | 43 | const_cast( m_typeID ) = rhs.m_typeID; 44 | 45 | return *this; 46 | } 47 | 48 | Type Argument::GetType(void) const 49 | { 50 | return Type( m_typeID, m_isArray ); 51 | } 52 | 53 | void *Argument::GetPtr(void) const 54 | { 55 | return const_cast( m_data ); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Source/Runtime/Argument.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Argument.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "TypeConfig.h" 10 | 11 | #include 12 | 13 | namespace ursine 14 | { 15 | namespace meta 16 | { 17 | class Type; 18 | class Variant; 19 | 20 | class Argument 21 | { 22 | public: 23 | Argument(void); 24 | Argument(const Argument &rhs); 25 | Argument(Variant &obj); 26 | Argument(const Variant &obj); 27 | 28 | template 29 | Argument(const T &data); 30 | 31 | template 32 | Argument(T &data); 33 | 34 | Argument &operator=(const Argument &rhs); 35 | 36 | Type GetType(void) const; 37 | 38 | void *GetPtr(void) const; 39 | 40 | template 41 | T &GetValue(void) const; 42 | 43 | private: 44 | const TypeID m_typeID; 45 | const bool m_isArray; 46 | 47 | const void *m_data; 48 | }; 49 | } 50 | } 51 | 52 | #include "Impl/Argument.hpp" -------------------------------------------------------------------------------- /Source/Runtime/ArgumentConfig.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** ArgumentConfig.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | class Argument; 16 | 17 | typedef std::vector ArgumentList; 18 | } 19 | } -------------------------------------------------------------------------------- /Source/Runtime/Array.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** ArrayConfig.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace ursine 12 | { 13 | // Basic wrapper around std::vector. Clang has a hard time with other 14 | // compilers implementation of std::vector, so this must be used in order to have 15 | // Array like functionality within the runtime 16 | template 17 | class Array : public std::vector 18 | { 19 | public: 20 | Array(void); 21 | Array(const std::vector &rhs); 22 | Array(const std::vector &&rhs); 23 | Array(const std::initializer_list &rhs); 24 | Array(const std::initializer_list &&rhs); 25 | }; 26 | } 27 | 28 | #include "Impl/Array.hpp" -------------------------------------------------------------------------------- /Source/Runtime/ArrayVariantContainer.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** ArrayVariantContainer.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "VariantBase.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | class ArrayWrapper; 16 | 17 | template 18 | class ArrayVariantContainer : public VariantBase 19 | { 20 | public: 21 | ArrayVariantContainer(StorageType &rhs); 22 | 23 | Type GetType(void) const override; 24 | void *GetPtr(void) const override; 25 | 26 | int ToInt(void) const override; 27 | bool ToBool(void) const override; 28 | float ToFloat(void) const override; 29 | double ToDouble(void) const override; 30 | std::string ToString(void) const override; 31 | 32 | bool IsArray(void) const override; 33 | ArrayWrapper GetArray(void) const override; 34 | 35 | VariantBase *Clone(void) const override; 36 | 37 | private: 38 | StorageType m_array; 39 | }; 40 | } 41 | } 42 | 43 | #include "Impl/ArrayVariantContainer.hpp" -------------------------------------------------------------------------------- /Source/Runtime/ArrayWrapper.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** ArrayWrapper.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "ArrayWrapper.h" 10 | 11 | #include "Common/Logging.h" 12 | 13 | namespace ursine 14 | { 15 | namespace meta 16 | { 17 | ArrayWrapper::ArrayWrapper(void) 18 | : m_isConst( true ) 19 | , m_base( nullptr ) { } 20 | 21 | Variant ArrayWrapper::GetValue(size_t index) const 22 | { 23 | return m_base ? m_base->GetValue( index ) : Variant( ); 24 | } 25 | 26 | void ArrayWrapper::SetValue(size_t index, const Argument &value) 27 | { 28 | UAssert( !m_isConst, "Array is const." ); 29 | 30 | if (m_base) 31 | m_base->SetValue( index, value ); 32 | } 33 | 34 | void ArrayWrapper::Insert(size_t index, const Argument &value) 35 | { 36 | UAssert( !m_isConst, "Array is const." ); 37 | 38 | if (m_base) 39 | m_base->Insert( index, value ); 40 | } 41 | 42 | void ArrayWrapper::Remove(size_t index) 43 | { 44 | UAssert( !m_isConst, "Array is const." ); 45 | 46 | if (m_base) 47 | m_base->Remove( index ); 48 | } 49 | 50 | size_t ArrayWrapper::Size(void) const 51 | { 52 | return m_base ? m_base->Size( ) : 0; 53 | } 54 | 55 | bool ArrayWrapper::IsValid(void) const 56 | { 57 | return m_base != nullptr; 58 | } 59 | 60 | bool ArrayWrapper::IsConst(void) const 61 | { 62 | return m_isConst; 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /Source/Runtime/ArrayWrapper.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** ArrayWrapper.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "ArrayWrapperBase.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | class Argument; 16 | 17 | class ArrayWrapper 18 | { 19 | public: 20 | ArrayWrapper(void); 21 | 22 | template 23 | ArrayWrapper(Array &rhs); 24 | 25 | template 26 | ArrayWrapper(const Array &rhs); 27 | 28 | Variant GetValue(size_t index) const; 29 | void SetValue(size_t index, const Argument &value); 30 | 31 | void Insert(size_t index, const Argument &value); 32 | void Remove(size_t index); 33 | 34 | size_t Size(void) const; 35 | 36 | bool IsValid(void) const; 37 | bool IsConst(void) const; 38 | private: 39 | bool m_isConst; 40 | 41 | ArrayWrapperBase *m_base; 42 | }; 43 | } 44 | } 45 | 46 | #include "Impl/ArrayWrapper.hpp" -------------------------------------------------------------------------------- /Source/Runtime/ArrayWrapperBase.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** ArrayWrapperBase.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "Array.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | class Variant; 16 | class Argument; 17 | 18 | class ArrayWrapperBase 19 | { 20 | public: 21 | virtual ~ArrayWrapperBase(void) { } 22 | 23 | virtual Variant GetValue(size_t index) = 0; 24 | virtual void SetValue(size_t index, const Argument &value) = 0; 25 | 26 | virtual void Insert(size_t index, const Argument &value) = 0; 27 | virtual void Remove(size_t index) = 0; 28 | 29 | virtual size_t Size(void) const = 0; 30 | }; 31 | } 32 | } -------------------------------------------------------------------------------- /Source/Runtime/ArrayWrapperContainer.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** ArrayWrapperContainer.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "ArrayWrapperBase.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | class Variant; 16 | class Argument; 17 | 18 | template 19 | class ArrayWrapperContainer : public ArrayWrapperBase 20 | { 21 | public: 22 | ArrayWrapperContainer(Array &a); 23 | 24 | Variant GetValue(size_t index) override; 25 | void SetValue(size_t index, const Argument &value) override; 26 | 27 | void Insert(size_t index, const Argument &value) override; 28 | void Remove(size_t index) override; 29 | 30 | size_t Size(void) const override; 31 | 32 | private: 33 | Array &m_array; 34 | }; 35 | } 36 | } 37 | 38 | #include "Impl/ArrayWrapperContainer.hpp" -------------------------------------------------------------------------------- /Source/Runtime/Constructor.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Constructor.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "Constructor.h" 10 | #include "Invokable.h" 11 | #include "Type.h" 12 | 13 | #include "Common/Logging.h" 14 | 15 | namespace ursine 16 | { 17 | namespace meta 18 | { 19 | namespace 20 | { 21 | const auto kConstructorName = "constructor"; 22 | } 23 | 24 | Constructor::Constructor(void) 25 | : Invokable( ) 26 | , m_isDynamic( false ) 27 | , m_classType( InvalidTypeID ) 28 | , m_invoker( nullptr ) { } 29 | 30 | Constructor::Constructor(const Constructor &rhs) 31 | : Invokable( kConstructorName ) 32 | , m_isDynamic( rhs.m_isDynamic ) 33 | , m_classType( rhs.m_classType ) 34 | , m_invoker( rhs.m_invoker ) 35 | { 36 | m_signature = rhs.m_signature; 37 | } 38 | 39 | Constructor::Constructor(const Constructor &&rhs) noexcept 40 | : Invokable( kConstructorName ) 41 | , m_isDynamic( rhs.m_isDynamic ) 42 | , m_classType( rhs.m_classType ) 43 | , m_invoker( std::move( rhs.m_invoker ) ) 44 | { 45 | m_signature = std::move( rhs.m_signature ); 46 | } 47 | 48 | Constructor::Constructor( 49 | Type classType, 50 | InvokableSignature signature, 51 | ConstructorInvokerBase *invoker, 52 | bool isDynamic 53 | ) 54 | : Invokable( kConstructorName ) 55 | , m_isDynamic( isDynamic ) 56 | , m_classType( classType ) 57 | , m_invoker( invoker ) 58 | { 59 | m_signature = signature; 60 | } 61 | 62 | Constructor &Constructor::operator=(const Constructor &&rhs) 63 | { 64 | m_isDynamic = rhs.m_isDynamic; 65 | m_classType= rhs.m_classType; 66 | m_invoker = std::move( rhs.m_invoker ); 67 | 68 | m_signature = std::move( rhs.m_signature ); 69 | 70 | return *this; 71 | } 72 | 73 | const Constructor &Constructor::Invalid(void) 74 | { 75 | static Constructor invalid; 76 | 77 | return invalid; 78 | } 79 | 80 | Type Constructor::GetClassType(void) const 81 | { 82 | return m_classType; 83 | } 84 | 85 | bool Constructor::IsValid(void) const 86 | { 87 | return m_invoker != nullptr; 88 | } 89 | 90 | bool Constructor::IsDynamic(void) const 91 | { 92 | return m_isDynamic; 93 | } 94 | 95 | Variant Constructor::InvokeVariadic(const ArgumentList &arguments) const 96 | { 97 | UAssert( IsValid( ), "Invalid constructor invoked." ); 98 | 99 | return m_invoker->Invoke( arguments ); 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /Source/Runtime/Constructor.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Constructor.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "MetaContainer.h" 10 | #include "Invokable.h" 11 | 12 | #include "Type.h" 13 | 14 | #include "ConstructorInvoker.h" 15 | 16 | #include 17 | 18 | namespace ursine 19 | { 20 | namespace meta 21 | { 22 | class Variant; 23 | class Argument; 24 | 25 | class Constructor 26 | : public MetaContainer 27 | , public Invokable 28 | { 29 | public: 30 | Constructor(void); 31 | Constructor(const Constructor &rhs); 32 | Constructor(const Constructor &&rhs) noexcept; 33 | 34 | Constructor( 35 | Type classType, 36 | InvokableSignature signature, 37 | ConstructorInvokerBase *invoker, 38 | bool isDynamic 39 | ); 40 | 41 | Constructor &operator=(const Constructor &&rhs); 42 | 43 | static const Constructor &Invalid(void); 44 | 45 | Type GetClassType(void) const; 46 | 47 | bool IsValid(void) const; 48 | bool IsDynamic(void) const; 49 | 50 | Variant InvokeVariadic(const ArgumentList &arguments) const; 51 | 52 | template 53 | Variant Invoke(Args &&...args) const; 54 | 55 | private: 56 | bool m_isDynamic; 57 | 58 | Type m_classType; 59 | 60 | std::shared_ptr m_invoker; 61 | }; 62 | } 63 | } 64 | 65 | #include "Impl/Constructor.hpp" -------------------------------------------------------------------------------- /Source/Runtime/ConstructorInvoker.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** ConstructorInvoker.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "ConstructorInvokerBase.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | class Variant; 16 | class Argument; 17 | 18 | template 19 | class ConstructorInvoker : public ConstructorInvokerBase 20 | { 21 | public: 22 | static_assert( THIS_ARG_COUNT <= MaxArgumentCount, 23 | "Constructor has too many arguments. It's time to generate more overloads." 24 | ); 25 | 26 | Variant Invoke(const ArgumentList &arguments) override; 27 | }; 28 | } 29 | } 30 | 31 | #include "Impl/ConstructorInvoker.hpp" -------------------------------------------------------------------------------- /Source/Runtime/ConstructorInvokerBase.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** ConstructorInvokerBase.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "InvokableConfig.h" 10 | #include "ArgumentConfig.h" 11 | 12 | namespace ursine 13 | { 14 | namespace meta 15 | { 16 | class Variant; 17 | class Argument; 18 | 19 | class ConstructorInvokerBase 20 | { 21 | public: 22 | virtual ~ConstructorInvokerBase(void) { } 23 | 24 | virtual Variant Invoke(const ArgumentList &arguments) = 0; 25 | }; 26 | } 27 | } -------------------------------------------------------------------------------- /Source/Runtime/Destructor.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Destructor.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "Destructor.h" 10 | 11 | #include "Variant.h" 12 | 13 | #include "Common/Logging.h" 14 | 15 | namespace ursine 16 | { 17 | namespace meta 18 | { 19 | namespace 20 | { 21 | const auto kDestructorName = "destructor"; 22 | } 23 | 24 | Destructor::Destructor(void) 25 | : Invokable( ) 26 | , m_classType( Type::Invalid( ) ) { } 27 | 28 | Destructor::Destructor(Type classType, DestructorInvokerBase *invoker) 29 | : Invokable( kDestructorName ) 30 | , m_classType( classType ) 31 | , m_invoker( invoker ) { } 32 | 33 | Type Destructor::GetClassType(void) const 34 | { 35 | return m_classType; 36 | } 37 | 38 | void Destructor::Invoke(Variant &instance) const 39 | { 40 | UAssert( IsValid( ), 41 | "Invalid constructor invoked." 42 | ); 43 | 44 | UAssert( m_classType == instance.GetType( ), 45 | "Destructor called on incompatible type." 46 | ); 47 | 48 | m_invoker->Invoke( instance ); 49 | 50 | delete instance.m_base; 51 | 52 | instance.m_base = nullptr; 53 | } 54 | 55 | const Destructor &Destructor::Invalid(void) 56 | { 57 | static Destructor invalid; 58 | 59 | return invalid; 60 | } 61 | 62 | bool Destructor::IsValid(void) const 63 | { 64 | return m_invoker != nullptr; 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /Source/Runtime/Destructor.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Destructor.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "Invokable.h" 10 | 11 | #include "DestructorInvoker.h" 12 | 13 | namespace ursine 14 | { 15 | namespace meta 16 | { 17 | class Destructor : public Invokable 18 | { 19 | public: 20 | Destructor(void); 21 | Destructor(Type classType, DestructorInvokerBase *invoker); 22 | 23 | static const Destructor &Invalid(void); 24 | 25 | Type GetClassType(void) const; 26 | 27 | bool IsValid(void) const; 28 | 29 | void Invoke(Variant &instance) const; 30 | 31 | private: 32 | Type m_classType; 33 | 34 | std::shared_ptr m_invoker; 35 | }; 36 | } 37 | } -------------------------------------------------------------------------------- /Source/Runtime/DestructorInvoker.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** DestructorInvoker.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "DestructorInvokerBase.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | template 16 | class DestructorInvoker : public DestructorInvokerBase 17 | { 18 | public: 19 | void Invoke(const Variant &obj) override; 20 | }; 21 | } 22 | } 23 | 24 | #include "Impl/DestructorInvoker.hpp" -------------------------------------------------------------------------------- /Source/Runtime/DestructorInvokerBase.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** DestructorInvokerBase.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "InvokableConfig.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | class Variant; 16 | 17 | class DestructorInvokerBase 18 | { 19 | public: 20 | virtual ~DestructorInvokerBase(void) { } 21 | 22 | virtual void Invoke(const Variant &obj) = 0; 23 | }; 24 | } 25 | } -------------------------------------------------------------------------------- /Source/Runtime/Enum.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Enum.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "Enum.h" 10 | 11 | #include "Variant.h" 12 | 13 | namespace ursine 14 | { 15 | namespace meta 16 | { 17 | Enum::Enum(const EnumBase *base) 18 | : m_base( base ) { } 19 | 20 | bool Enum::IsValid(void) const 21 | { 22 | return m_base != nullptr; 23 | } 24 | 25 | Enum::operator bool(void) const 26 | { 27 | return m_base != nullptr; 28 | } 29 | 30 | bool Enum::operator==(const Enum &rhs) const 31 | { 32 | return m_base == rhs.m_base; 33 | } 34 | 35 | bool Enum::operator!=(const Enum &rhs) const 36 | { 37 | return m_base != rhs.m_base; 38 | } 39 | 40 | std::string Enum::GetName(void) const 41 | { 42 | return m_base ? m_base->GetName( ) : std::string( ); 43 | } 44 | 45 | Type Enum::GetType(void) const 46 | { 47 | return m_base ? m_base->GetType( ) : Type::Invalid( ); 48 | } 49 | 50 | Type Enum::GetParentType(void) const 51 | { 52 | return m_base ? m_base->GetParentType( ) : Type::Invalid( ); 53 | } 54 | 55 | Type Enum::GetUnderlyingType(void) const 56 | { 57 | return m_base ? m_base->GetUnderlyingType( ) : Type::Invalid( ); 58 | } 59 | 60 | std::vector Enum::GetKeys(void) const 61 | { 62 | return m_base ? m_base->GetKeys( ) : std::vector( ); 63 | } 64 | 65 | std::vector Enum::GetValues(void) const 66 | { 67 | return m_base ? m_base->GetValues( ) : std::vector( ); 68 | } 69 | 70 | std::string Enum::GetKey(const Argument &value) const 71 | { 72 | return m_base ? m_base->GetKey( value ) : std::string( ); 73 | } 74 | 75 | Variant Enum::GetValue(const std::string &key) const 76 | { 77 | return m_base ? m_base->GetValue( key ) : Variant( ); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Source/Runtime/Enum.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Enum.h 5 | ** --------------------------------------------------------------------------*/ 6 | #pragma once 7 | 8 | #include "EnumBase.h" 9 | 10 | namespace ursine 11 | { 12 | namespace meta 13 | { 14 | class Enum 15 | { 16 | public: 17 | bool IsValid(void) const; 18 | 19 | operator bool(void) const; 20 | 21 | bool operator ==(const Enum &rhs) const; 22 | bool operator !=(const Enum &rhs) const; 23 | 24 | std::string GetName(void) const; 25 | 26 | Type GetType(void) const; 27 | Type GetParentType(void) const; 28 | Type GetUnderlyingType(void) const; 29 | 30 | std::vector GetKeys(void) const; 31 | std::vector GetValues(void) const; 32 | 33 | std::string GetKey(const Argument &value) const; 34 | Variant GetValue(const std::string &key) const; 35 | 36 | private: 37 | friend struct TypeData; 38 | 39 | Enum(const EnumBase *base); 40 | 41 | std::shared_ptr m_base; 42 | }; 43 | } 44 | } -------------------------------------------------------------------------------- /Source/Runtime/EnumBase.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** EnumBase.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "EnumBase.h" 10 | 11 | #include "Variant.h" 12 | #include "Argument.h" 13 | 14 | namespace ursine 15 | { 16 | namespace meta 17 | { 18 | EnumBase::EnumBase(const std::string &name, TypeID owner) 19 | : m_parentType( owner ) 20 | , m_name( name ) { } 21 | 22 | Type EnumBase::GetParentType(void) const 23 | { 24 | return m_parentType; 25 | } 26 | 27 | const std::string &EnumBase::GetName(void) const 28 | { 29 | return m_name; 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Source/Runtime/EnumBase.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** EnumBase.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "Type.h" 10 | 11 | #include 12 | #include 13 | 14 | namespace ursine 15 | { 16 | namespace meta 17 | { 18 | class Variant; 19 | class Argument; 20 | 21 | class EnumBase 22 | { 23 | public: 24 | EnumBase(const std::string &name, TypeID owner); 25 | 26 | virtual ~EnumBase(void) { } 27 | 28 | virtual Type GetType(void) const = 0; 29 | virtual Type GetUnderlyingType(void) const = 0; 30 | 31 | virtual const std::vector &GetKeys(void) const = 0; 32 | virtual std::vector GetValues(void) const = 0; 33 | 34 | virtual std::string GetKey(const Argument &value) const = 0; 35 | virtual Variant GetValue(const std::string &key) const = 0; 36 | 37 | Type GetParentType(void) const; 38 | 39 | const std::string &GetName(void) const; 40 | 41 | private: 42 | Type m_parentType; 43 | 44 | std::string m_name; 45 | }; 46 | } 47 | } -------------------------------------------------------------------------------- /Source/Runtime/EnumContainer.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** EnumContainer.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "EnumBase.h" 10 | 11 | #include "Variant.h" 12 | 13 | #include 14 | 15 | namespace ursine 16 | { 17 | namespace meta 18 | { 19 | template 20 | class EnumContainer : public EnumBase 21 | { 22 | public: 23 | typedef std::initializer_list> Initializer; 24 | typedef std::unordered_map Table; 25 | 26 | EnumContainer(const std::string &name, const Initializer &initializer); 27 | 28 | EnumContainer( 29 | const std::string &name, 30 | const Initializer &initializer, 31 | TypeID owner 32 | ); 33 | 34 | Type GetType(void) const override; 35 | Type GetUnderlyingType(void) const override; 36 | 37 | const std::vector &GetKeys(void) const override; 38 | std::vector GetValues(void) const override; 39 | 40 | std::string GetKey(const Argument &value) const override; 41 | Variant GetValue(const std::string &key) const override; 42 | 43 | private: 44 | Table m_keyToValue; 45 | std::vector m_keys; 46 | }; 47 | } 48 | } 49 | 50 | #include "Impl/EnumContainer.hpp" -------------------------------------------------------------------------------- /Source/Runtime/Field.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Field.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "Field.h" 10 | #include "Method.h" 11 | 12 | namespace ursine 13 | { 14 | namespace meta 15 | { 16 | Field::Field(void) 17 | : m_type( Type::Invalid( ) ) 18 | , m_classType( Type::Invalid( ) ) 19 | , m_name( "INVALID" ) 20 | , m_getter( nullptr ) 21 | , m_setter( nullptr ) { } 22 | 23 | Field::Field( 24 | const std::string &name, 25 | Type type, 26 | Type classType, 27 | FieldGetterBase *getter, 28 | FieldSetterBase *setter 29 | ) 30 | : m_type( type ) 31 | , m_classType( classType ) 32 | , m_name( name ) 33 | , m_getter( getter ) 34 | , m_setter( setter ) { } 35 | 36 | const Field &Field::Invalid(void) 37 | { 38 | static Field field; 39 | 40 | return field; 41 | } 42 | 43 | bool Field::SetValue(Variant &instance, const Variant &value, const Method &setter) 44 | { 45 | // read only? 46 | if (!instance.IsConst( )) 47 | { 48 | setter.Invoke( instance, value ); 49 | 50 | return true; 51 | } 52 | 53 | return false; 54 | } 55 | 56 | bool Field::IsValid(void) const 57 | { 58 | return m_getter != nullptr; 59 | } 60 | 61 | bool Field::IsReadOnly(void) const 62 | { 63 | return m_setter == nullptr; 64 | } 65 | 66 | Type Field::GetType(void) const 67 | { 68 | return m_type; 69 | } 70 | 71 | Type Field::GetClassType(void) const 72 | { 73 | return m_classType; 74 | } 75 | 76 | const std::string &Field::GetName(void) const 77 | { 78 | return m_name; 79 | } 80 | 81 | Variant Field::GetValue(const Variant &instance) const 82 | { 83 | return m_getter->GetValue( instance ); 84 | } 85 | 86 | Variant Field::GetValueReference(const Variant &instance) const 87 | { 88 | return m_getter->GetValueReference( instance ); 89 | } 90 | 91 | bool Field::SetValue(Variant &instance, const Variant &value) const 92 | { 93 | // read only? 94 | if (m_setter && !instance.IsConst( )) 95 | { 96 | m_setter->SetValue( instance, value ); 97 | 98 | return true; 99 | } 100 | 101 | return false; 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /Source/Runtime/Field.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Field.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "MetaContainer.h" 10 | 11 | #include "Variant.h" 12 | 13 | #include "FieldGetter.h" 14 | #include "FieldSetter.h" 15 | 16 | namespace ursine 17 | { 18 | namespace meta 19 | { 20 | class Field : public MetaContainer 21 | { 22 | public: 23 | static bool SetValue(Variant &instance, const Variant &value, const Method &setter); 24 | 25 | Field(void); 26 | 27 | Field( 28 | const std::string &name, 29 | Type type, 30 | Type classType, 31 | FieldGetterBase *getter, 32 | FieldSetterBase *setter 33 | ); 34 | 35 | static const Field &Invalid(void); 36 | 37 | bool IsValid(void) const; 38 | bool IsReadOnly(void) const; 39 | 40 | Type GetType(void) const; 41 | Type GetClassType(void) const; 42 | 43 | const std::string &GetName(void) const; 44 | 45 | Variant GetValue(const Variant &instance) const; 46 | Variant GetValueReference(const Variant &instance) const; 47 | 48 | bool SetValue(Variant &instance, const Variant &value) const; 49 | 50 | private: 51 | friend struct TypeData; 52 | 53 | Type m_type; 54 | Type m_classType; 55 | 56 | std::string m_name; 57 | 58 | std::shared_ptr m_getter; 59 | std::shared_ptr m_setter; 60 | }; 61 | } 62 | } -------------------------------------------------------------------------------- /Source/Runtime/FieldGetter.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** FieldGetter.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "FieldGetterBase.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | template 16 | class FieldGetter : public FieldGetterBase 17 | { 18 | public: 19 | Variant GetValue(const Variant &obj) override; 20 | Variant GetValueReference(const Variant &obj) override; 21 | }; 22 | } 23 | } 24 | 25 | #include "Impl/FieldGetter.hpp" -------------------------------------------------------------------------------- /Source/Runtime/FieldGetterBase.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** FieldGetterBase.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | namespace ursine 10 | { 11 | namespace meta 12 | { 13 | class Variant; 14 | 15 | class FieldGetterBase 16 | { 17 | public: 18 | virtual ~FieldGetterBase(void) { } 19 | 20 | virtual Variant GetValue(const Variant &obj) = 0; 21 | virtual Variant GetValueReference(const Variant &obj) = 0; 22 | }; 23 | } 24 | } -------------------------------------------------------------------------------- /Source/Runtime/FieldSetter.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** FieldSetter.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "FieldSetterBase.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | template 16 | class FieldSetter : public FieldSetterBase 17 | { 18 | public: 19 | void SetValue(Variant &obj, const Variant &value) override; 20 | }; 21 | } 22 | } 23 | 24 | #include "Impl/FieldSetter.hpp" -------------------------------------------------------------------------------- /Source/Runtime/FieldSetterBase.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** FieldSetterBase.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | namespace ursine 10 | { 11 | namespace meta 12 | { 13 | class Variant; 14 | 15 | class FieldSetterBase 16 | { 17 | public: 18 | virtual ~FieldSetterBase(void) { } 19 | 20 | virtual void SetValue(Variant &obj, const Variant &value) = 0; 21 | }; 22 | } 23 | } -------------------------------------------------------------------------------- /Source/Runtime/Function.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Function.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "Function.h" 10 | 11 | #include "Common/Logging.h" 12 | 13 | namespace ursine 14 | { 15 | namespace meta 16 | { 17 | Function::Function(void) 18 | : Invokable( ) 19 | , m_parentType( Type::Invalid( ) ) 20 | , m_invoker( nullptr ) { } 21 | 22 | const Function &Function::Invalid(void) 23 | { 24 | static Function invalid; 25 | 26 | return invalid; 27 | } 28 | 29 | Type Function::GetParentType(void) const 30 | { 31 | return m_parentType; 32 | } 33 | 34 | bool Function::IsValid(void) const 35 | { 36 | return m_invoker != nullptr; 37 | } 38 | 39 | Variant Function::InvokeVariadic(ArgumentList &arguments) const 40 | { 41 | #if defined(_DEBUG) 42 | 43 | UAssert( IsValid( ), "Invalid function invocation." ); 44 | 45 | #endif 46 | 47 | return m_invoker->Invoke( arguments ); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Source/Runtime/Function.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Function.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "MetaContainer.h" 10 | #include "Invokable.h" 11 | 12 | #include "Variant.h" 13 | #include "Argument.h" 14 | 15 | #include "FunctionInvoker.h" 16 | 17 | #include 18 | 19 | namespace ursine 20 | { 21 | namespace meta 22 | { 23 | class Function 24 | : public MetaContainer 25 | , public Invokable 26 | { 27 | public: 28 | typedef std::function Invoker; 29 | 30 | Function(void); 31 | 32 | template 33 | Function( 34 | const std::string &name, 35 | ReturnType (*function)(ArgTypes...), 36 | Type parentType = Type::Invalid( ) 37 | ); 38 | 39 | static const Function &Invalid(void); 40 | 41 | Type GetParentType(void) const; 42 | 43 | bool IsValid(void) const; 44 | 45 | Variant InvokeVariadic(ArgumentList &arguments) const; 46 | 47 | template 48 | Variant Invoke(Args &&...args) const; 49 | 50 | private: 51 | Type m_parentType; 52 | 53 | std::shared_ptr m_invoker; 54 | }; 55 | } 56 | } 57 | 58 | #include "Impl/Function.hpp" -------------------------------------------------------------------------------- /Source/Runtime/FunctionInvoker.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** FunctionInvoker.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "FunctionInvokerBase.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | template 16 | class FunctionInvoker : public FunctionInvokerBase 17 | { 18 | public: 19 | typedef ReturnType (*Signature)(ArgTypes...); 20 | 21 | static_assert( THIS_ARG_COUNT <= MaxArgumentCount, 22 | "Function has too many arguments. It's time to generate more overloads." 23 | ); 24 | 25 | FunctionInvoker(Signature function); 26 | 27 | Variant Invoke(const ArgumentList &arguments) override; 28 | 29 | private: 30 | template 31 | Variant invoke(const ArgumentList &arguments); 32 | 33 | template 34 | Variant invoke(const ArgumentList &arguments); 35 | 36 | template 37 | Variant invoke(const ArgumentList &arguments); 38 | 39 | template 40 | Variant invoke(const ArgumentList &arguments); 41 | 42 | template 43 | Variant invoke(const ArgumentList &arguments); 44 | 45 | template 46 | Variant invoke(const ArgumentList &arguments); 47 | 48 | template 49 | Variant invoke(const ArgumentList &arguments); 50 | 51 | template 52 | Variant invoke(const ArgumentList &arguments); 53 | 54 | template 55 | Variant invoke(const ArgumentList &arguments); 56 | 57 | template 58 | Variant invoke(const ArgumentList &arguments); 59 | 60 | template 61 | Variant invoke(const ArgumentList &arguments); 62 | 63 | Signature m_function; 64 | }; 65 | } 66 | } 67 | 68 | #include "Impl/FunctionInvoker.hpp" 69 | #include "Impl/VoidFunctionInvoker.hpp" -------------------------------------------------------------------------------- /Source/Runtime/FunctionInvokerBase.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** FunctionInvokerBase.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "InvokableConfig.h" 10 | #include "ArgumentConfig.h" 11 | 12 | namespace ursine 13 | { 14 | namespace meta 15 | { 16 | class Variant; 17 | 18 | class FunctionInvokerBase 19 | { 20 | public: 21 | virtual ~FunctionInvokerBase(void) { } 22 | 23 | virtual Variant Invoke(const ArgumentList &arguments) = 0; 24 | }; 25 | } 26 | } -------------------------------------------------------------------------------- /Source/Runtime/Global.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Global.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "Global.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | Global::Global(void) 16 | : m_type( Type::Invalid( ) ) 17 | , m_parentType( Type::Invalid( ) ) 18 | , m_name( "INVALID" ) 19 | , m_getter( nullptr ) 20 | , m_setter( nullptr ) { } 21 | 22 | Global::Global( 23 | const std::string &name, 24 | Type type, 25 | GlobalGetterBase *getter, 26 | GlobalSetterBase *setter, 27 | Type parentType 28 | ) 29 | : m_type( type ) 30 | , m_parentType( parentType ) 31 | , m_name( name ) 32 | , m_getter( getter ) 33 | , m_setter( setter ) { } 34 | 35 | const Global &Global::Invalid(void) 36 | { 37 | static Global global; 38 | 39 | return global; 40 | } 41 | 42 | bool Global::IsValid(void) const 43 | { 44 | return m_getter != nullptr; 45 | } 46 | 47 | bool Global::IsReadOnly(void) const 48 | { 49 | return m_setter == nullptr; 50 | } 51 | 52 | Type Global::GetType(void) const 53 | { 54 | return m_type; 55 | } 56 | 57 | Type Global::GetParentType(void) const 58 | { 59 | return m_parentType; 60 | } 61 | 62 | const std::string &Global::GetName(void) const 63 | { 64 | return m_name; 65 | } 66 | 67 | Variant Global::GetValue(void) const 68 | { 69 | return m_getter->GetValue( ); 70 | } 71 | 72 | bool Global::SetValue(const Argument &value) const 73 | { 74 | // read only? 75 | if (m_setter != nullptr) 76 | { 77 | m_setter->SetValue( value ); 78 | 79 | return true; 80 | } 81 | 82 | return false; 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Source/Runtime/Global.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Global.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "MetaContainer.h" 10 | 11 | #include "Variant.h" 12 | 13 | #include "GlobalGetter.h" 14 | #include "GlobalSetter.h" 15 | 16 | namespace ursine 17 | { 18 | namespace meta 19 | { 20 | class Global : public MetaContainer 21 | { 22 | public: 23 | Global(void); 24 | 25 | Global( 26 | const std::string &name, 27 | Type type, 28 | GlobalGetterBase *getter, 29 | GlobalSetterBase *setter, 30 | Type parentType = Type::Invalid( ) 31 | ); 32 | 33 | static const Global &Invalid(void); 34 | 35 | bool IsValid(void) const; 36 | bool IsReadOnly(void) const; 37 | 38 | Type GetType(void) const; 39 | Type GetParentType(void) const; 40 | 41 | const std::string &GetName(void) const; 42 | 43 | Variant GetValue(void) const; 44 | bool SetValue(const Argument &value) const; 45 | 46 | private: 47 | friend struct TypeData; 48 | 49 | Type m_type; 50 | Type m_parentType; 51 | 52 | std::string m_name; 53 | 54 | std::shared_ptr m_getter; 55 | std::shared_ptr m_setter; 56 | }; 57 | } 58 | } -------------------------------------------------------------------------------- /Source/Runtime/GlobalGetter.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** GlobalGetter.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "GlobalGetterBase.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | template 16 | class GlobalGetter : public GlobalGetterBase 17 | { 18 | public: 19 | Variant GetValue(void) override; 20 | }; 21 | } 22 | } 23 | 24 | #include "Impl/GlobalGetter.hpp" -------------------------------------------------------------------------------- /Source/Runtime/GlobalGetterBase.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** GlobalGetterBase.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | namespace ursine 10 | { 11 | namespace meta 12 | { 13 | class Variant; 14 | 15 | class GlobalGetterBase 16 | { 17 | public: 18 | virtual ~GlobalGetterBase(void) { } 19 | 20 | virtual Variant GetValue(void) = 0; 21 | }; 22 | } 23 | } -------------------------------------------------------------------------------- /Source/Runtime/GlobalSetter.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** GlobalSetter.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "GlobalSetterBase.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | template 16 | class GlobalSetter : public GlobalSetterBase 17 | { 18 | public: 19 | void SetValue(const Argument &value) override; 20 | }; 21 | } 22 | } 23 | 24 | #include "Impl/GlobalSetter.hpp" -------------------------------------------------------------------------------- /Source/Runtime/GlobalSetterBase.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** GlobalSetterBase.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | namespace ursine 10 | { 11 | namespace meta 12 | { 13 | class Argument; 14 | 15 | class GlobalSetterBase 16 | { 17 | public: 18 | virtual ~GlobalSetterBase(void) { } 19 | 20 | virtual void SetValue(const Argument &value) = 0; 21 | }; 22 | } 23 | } -------------------------------------------------------------------------------- /Source/Runtime/Impl/Argument.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Argument.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | namespace ursine 10 | { 11 | namespace meta 12 | { 13 | template 14 | Argument::Argument(const T &data) 15 | : m_typeID( typeidof( T ) ) 16 | , m_isArray( meta_traits::IsArray::value ) 17 | , m_data( reinterpret_cast( std::addressof( data ) ) ) 18 | { 19 | static_assert( !std::is_same< Argument, T >::value, 20 | "Cannot use Argument as an argument" 21 | ); 22 | } 23 | 24 | /////////////////////////////////////////////////////////////////////// 25 | 26 | template 27 | Argument::Argument(T &data) 28 | : m_typeID( typeidof( T ) ) 29 | , m_isArray( meta_traits::IsArray::value ) 30 | , m_data( reinterpret_cast( std::addressof( data ) ) ) 31 | { 32 | static_assert( !std::is_same< Argument, T >::value, 33 | "Cannot use Argument as an argument" 34 | ); 35 | } 36 | 37 | /////////////////////////////////////////////////////////////////////// 38 | 39 | template 40 | T &Argument::GetValue(void) const 41 | { 42 | return *reinterpret_cast< 43 | typename std::remove_reference< T >::type* 44 | >( 45 | const_cast( m_data ) 46 | ); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Source/Runtime/Impl/Array.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Array.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | namespace ursine 10 | { 11 | template 12 | Array::Array(void) { } 13 | 14 | template 15 | Array::Array(const std::vector &rhs) 16 | : std::vector( rhs ) { } 17 | 18 | template 19 | Array::Array(const std::vector &&rhs) 20 | : std::vector( std::move( rhs ) ) { } 21 | 22 | template 23 | Array::Array(const std::initializer_list &rhs) 24 | : std::vector( rhs ) { } 25 | 26 | template 27 | Array::Array(const std::initializer_list &&rhs) 28 | : std::vector( std::move( rhs ) ) { } 29 | } -------------------------------------------------------------------------------- /Source/Runtime/Impl/ArrayVariantContainer.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** ArrayVariantContainer.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "../ArrayWrapper.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | template 16 | ArrayVariantContainer::ArrayVariantContainer(StorageType &rhs) 17 | : m_array( rhs ) 18 | { 19 | 20 | } 21 | 22 | template 23 | Type ArrayVariantContainer::GetType(void) const 24 | { 25 | return typeof( Array ); 26 | } 27 | 28 | template 29 | void *ArrayVariantContainer::GetPtr(void) const 30 | { 31 | return const_cast( 32 | reinterpret_cast( 33 | std::addressof( m_array ) 34 | ) 35 | ); 36 | } 37 | 38 | template 39 | int ArrayVariantContainer::ToInt(void) const 40 | { 41 | return int( ); 42 | } 43 | 44 | template 45 | bool ArrayVariantContainer::ToBool(void) const 46 | { 47 | return bool( ); 48 | } 49 | 50 | template 51 | float ArrayVariantContainer::ToFloat(void) const 52 | { 53 | return float( ); 54 | } 55 | 56 | template 57 | double ArrayVariantContainer::ToDouble(void) const 58 | { 59 | return double( ); 60 | } 61 | 62 | template 63 | std::string ArrayVariantContainer::ToString(void) const 64 | { 65 | return std::string( ); 66 | } 67 | 68 | template 69 | bool ArrayVariantContainer::IsArray(void) const 70 | { 71 | return true; 72 | } 73 | 74 | template 75 | ArrayWrapper ArrayVariantContainer::GetArray(void) const 76 | { 77 | return ArrayWrapper( const_cast&>( m_array ) ); 78 | } 79 | 80 | template 81 | VariantBase *ArrayVariantContainer::Clone(void) const 82 | { 83 | return new ArrayVariantContainer( const_cast&>( m_array ) ); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /Source/Runtime/Impl/ArrayWrapper.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** ArrayWrapper.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "../ArrayWrapperContainer.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | template 16 | ArrayWrapper::ArrayWrapper(Array &rhs) 17 | : m_isConst( false ) 18 | , m_base( new ArrayWrapperContainer( rhs ) ) 19 | { 20 | 21 | } 22 | 23 | template 24 | ArrayWrapper::ArrayWrapper(const Array &rhs) 25 | : m_isConst( true ) 26 | , m_base( new ArrayWrapperContainer( const_cast &>( rhs ) ) ) 27 | { 28 | 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Source/Runtime/Impl/ArrayWrapperContainer.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** ArrayWrapperContainer.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "../Argument.h" 10 | #include "../Variant.h" 11 | 12 | namespace ursine 13 | { 14 | namespace meta 15 | { 16 | template 17 | ArrayWrapperContainer::ArrayWrapperContainer(Array &a) 18 | : m_array( a ) 19 | { 20 | 21 | } 22 | 23 | template 24 | Variant ArrayWrapperContainer::GetValue(size_t index) 25 | { 26 | return { m_array[ index ] }; 27 | } 28 | 29 | template 30 | void ArrayWrapperContainer::SetValue(size_t index, const Argument &value) 31 | { 32 | m_array.at( index ) = value.GetValue( ); 33 | } 34 | 35 | template 36 | void ArrayWrapperContainer::Insert(size_t index, const Argument &value) 37 | { 38 | m_array.insert( m_array.begin( ) + index, value.GetValue( ) ); 39 | } 40 | 41 | template 42 | void ArrayWrapperContainer::Remove(size_t index) 43 | { 44 | m_array.erase( m_array.begin( ) + index ); 45 | } 46 | 47 | template 48 | size_t ArrayWrapperContainer::Size(void) const 49 | { 50 | return m_array.size( ); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /Source/Runtime/Impl/Constructor.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Constructor.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "../Variant.h" 10 | #include "../Argument.h" 11 | 12 | namespace ursine 13 | { 14 | namespace meta 15 | { 16 | template 17 | Variant Constructor::Invoke(Args &&...args) const 18 | { 19 | ArgumentList arguments { std::forward( args )... }; 20 | 21 | return InvokeVariadic( arguments ); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Source/Runtime/Impl/DestructorInvoker.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** DestructorInvoker.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "../Variant.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | template 16 | void DestructorInvoker::Invoke(const Variant& obj) 17 | { 18 | auto &instance = obj.GetValue( ); 19 | 20 | instance.~ClassType( ); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Source/Runtime/Impl/FieldGetter.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** FieldGetter.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | namespace ursine 10 | { 11 | namespace meta 12 | { 13 | /////////////////////////////////////////////////////////////////////// 14 | // Getter from Method 15 | /////////////////////////////////////////////////////////////////////// 16 | 17 | template 18 | class FieldGetter : public FieldGetterBase 19 | { 20 | public: 21 | typedef ReturnType (ClassType::*Signature)(void); 22 | typedef ReturnType (ClassType::*SignatureConst)(void) const; 23 | 24 | FieldGetter(Signature method) 25 | : m_method( reinterpret_cast( method ) ) { } 26 | 27 | FieldGetter(SignatureConst method) 28 | : m_method( method ) { } 29 | 30 | Variant GetValue(const Variant &obj) override 31 | { 32 | auto &instance = obj.GetValue( ); 33 | 34 | return (instance.*m_method)( ); 35 | } 36 | 37 | Variant GetValueReference(const Variant &obj) override 38 | { 39 | return getValueReference( obj ); 40 | } 41 | 42 | private: 43 | template 44 | Variant getValueReference( 45 | const Variant &obj, 46 | typename std::enable_if< 47 | std::is_lvalue_reference::value 48 | >::type* = nullptr 49 | ) 50 | { 51 | auto &instance = obj.GetValue( ); 52 | 53 | return Variant { (instance.*m_method)( ), variant_policy::NoCopy( ) }; 54 | } 55 | 56 | template 57 | Variant getValueReference( 58 | const Variant &obj, 59 | typename std::enable_if< 60 | !std::is_lvalue_reference::value 61 | >::type* = nullptr 62 | ) 63 | { 64 | // non l-value reference return types must return by value 65 | return GetValue( obj ); 66 | } 67 | 68 | SignatureConst m_method; 69 | }; 70 | 71 | /////////////////////////////////////////////////////////////////////// 72 | // Getter from Direct Field 73 | /////////////////////////////////////////////////////////////////////// 74 | 75 | template 76 | class FieldGetter : public FieldGetterBase 77 | { 78 | public: 79 | typedef FieldType (ClassType::*Signature); 80 | 81 | FieldGetter(Signature field) 82 | : m_field( field ) { } 83 | 84 | Variant GetValue(const Variant &obj) override 85 | { 86 | auto &instance = obj.GetValue( ); 87 | 88 | return instance.*m_field; 89 | } 90 | 91 | Variant GetValueReference(const Variant &obj) override 92 | { 93 | auto &instance = obj.GetValue( ); 94 | 95 | return Variant { instance.*m_field, variant_policy::NoCopy( ) }; 96 | } 97 | 98 | private: 99 | Signature m_field; 100 | }; 101 | } 102 | } -------------------------------------------------------------------------------- /Source/Runtime/Impl/FieldSetter.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** FieldSetter.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | namespace ursine 10 | { 11 | namespace meta 12 | { 13 | /////////////////////////////////////////////////////////////////////// 14 | // Setter from Method 15 | /////////////////////////////////////////////////////////////////////// 16 | 17 | template 18 | class FieldSetter : public FieldSetterBase 19 | { 20 | public: 21 | typedef typename std::remove_reference::type NonReferenceArgType; 22 | typedef void (ClassType::*Signature)(ArgumentType); 23 | typedef void (ClassType::*SignatureConst)(ArgumentType) const; 24 | 25 | FieldSetter(Signature method) 26 | : m_method( method ) { } 27 | 28 | FieldSetter(SignatureConst method) 29 | : m_method( reinterpret_cast( method ) ) { } 30 | 31 | void SetValue(Variant &obj, const Variant &value) override 32 | { 33 | UAssert( value.IsValid( ), "Setting invalid value." ); 34 | 35 | auto &instance = obj.GetValue( ); 36 | 37 | (instance.*m_method)( value.GetValue( ) ); 38 | } 39 | 40 | private: 41 | Signature m_method; 42 | }; 43 | 44 | /////////////////////////////////////////////////////////////////////// 45 | // Setter from Direct Field 46 | /////////////////////////////////////////////////////////////////////// 47 | 48 | template 49 | class FieldSetter : public FieldSetterBase 50 | { 51 | public: 52 | typedef FieldType (ClassType::*Signature); 53 | typedef typename std::remove_const::type NonConstFieldType; 54 | 55 | FieldSetter(Signature field) 56 | : m_field( field ) { } 57 | 58 | void SetValue(Variant &obj, const Variant &value) override 59 | { 60 | UAssert( value.IsValid( ), "Setting invalid value." ); 61 | 62 | auto &instance = obj.GetValue( ); 63 | 64 | const_cast( instance.*m_field ) = value.GetValue( ); 65 | } 66 | 67 | private: 68 | Signature m_field; 69 | }; 70 | } 71 | } -------------------------------------------------------------------------------- /Source/Runtime/Impl/Function.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Function.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | namespace ursine 10 | { 11 | namespace meta 12 | { 13 | template 14 | Function::Function( 15 | const std::string &name, 16 | ReturnType (*function)(ArgTypes...), 17 | Type parentType 18 | ) 19 | : Invokable( name ) 20 | , m_parentType( parentType ) 21 | , m_invoker( new FunctionInvoker( function ) ) 22 | { 23 | TypeUnpacker::Apply( m_signature ); 24 | } 25 | 26 | /////////////////////////////////////////////////////////////////////// 27 | 28 | template 29 | Variant Function::Invoke(Args &&...args) const 30 | { 31 | ArgumentList arguments { std::forward( args )... }; 32 | 33 | return InvokeVariadic( arguments ); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Source/Runtime/Impl/GlobalGetter.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** GlobalGetter.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | namespace ursine 10 | { 11 | namespace meta 12 | { 13 | /////////////////////////////////////////////////////////////////////// 14 | // Getter from Method 15 | /////////////////////////////////////////////////////////////////////// 16 | 17 | template 18 | class GlobalGetter : public GlobalGetterBase 19 | { 20 | public: 21 | typedef GlobalType (*Signature)(void); 22 | 23 | GlobalGetter(Signature function) 24 | : m_function( function ) { } 25 | 26 | Variant GetValue(void) override 27 | { 28 | return m_function( ); 29 | } 30 | 31 | private: 32 | Signature m_function; 33 | }; 34 | 35 | /////////////////////////////////////////////////////////////////////// 36 | // Getter from Direct Global 37 | /////////////////////////////////////////////////////////////////////// 38 | 39 | template 40 | class GlobalGetter : public GlobalGetterBase 41 | { 42 | public: 43 | GlobalGetter(GlobalType *global) 44 | : m_global( global ) { } 45 | 46 | Variant GetValue(void) override 47 | { 48 | return *m_global; 49 | } 50 | 51 | private: 52 | GlobalType *m_global; 53 | }; 54 | } 55 | } -------------------------------------------------------------------------------- /Source/Runtime/Impl/GlobalSetter.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** GlobalSetter.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | namespace ursine 10 | { 11 | namespace meta 12 | { 13 | /////////////////////////////////////////////////////////////////////// 14 | // Setter from Method 15 | /////////////////////////////////////////////////////////////////////// 16 | 17 | template 18 | class GlobalSetter : public GlobalSetterBase 19 | { 20 | public: 21 | typedef GlobalType(*Signature)(const GlobalType &); 22 | 23 | GlobalSetter(Signature function) 24 | : m_function( function ) { } 25 | 26 | void SetValue(const Argument &value) override 27 | { 28 | m_function( value.GetValue( ) ); 29 | } 30 | 31 | private: 32 | Signature m_function; 33 | }; 34 | 35 | /////////////////////////////////////////////////////////////////////// 36 | // Setter from Direct Field 37 | /////////////////////////////////////////////////////////////////////// 38 | 39 | template 40 | class GlobalSetter : public GlobalSetterBase 41 | { 42 | public: 43 | GlobalSetter(GlobalType *field) 44 | : m_field( field ) { } 45 | 46 | void SetValue(const Argument &value) override 47 | { 48 | const_cast( *m_field ) = value.GetValue( ); 49 | } 50 | 51 | private: 52 | GlobalType *m_field; 53 | }; 54 | } 55 | } -------------------------------------------------------------------------------- /Source/Runtime/Impl/Invokable.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Invokable.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "../Type.h" 10 | #include "TypeUnpacker.hpp" 11 | 12 | namespace std 13 | { 14 | template<> 15 | struct hash 16 | { 17 | size_t operator()( 18 | const ursine::meta::InvokableSignature &signature 19 | ) const 20 | { 21 | hash hasher; 22 | 23 | size_t seed = 0; 24 | 25 | // combine the hash of all type IDs in the signature 26 | for (auto &type : signature) 27 | seed ^= hasher( type.GetID( ) ) + 0x9e3779b9 + (seed << 6) + (seed >> 2); 28 | 29 | return seed; 30 | } 31 | }; 32 | } 33 | 34 | namespace ursine 35 | { 36 | namespace meta 37 | { 38 | template 39 | InvokableSignature Invokable::CreateSignature(void) 40 | { 41 | static InvokableSignature signature; 42 | 43 | static auto initial = true; 44 | 45 | if (initial) 46 | { 47 | TypeUnpacker::Apply( signature ); 48 | 49 | initial = false; 50 | } 51 | 52 | return signature; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Source/Runtime/Impl/MetaManager.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** MetaManager.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "../Type.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | template 16 | const PropertyType *MetaManager::GetProperty(void) const 17 | { 18 | static_assert( std::is_base_of::value, 19 | "Type must be a MetaProperty." 20 | ); 21 | 22 | static const auto type = typeof( PropertyType ); 23 | 24 | auto search = m_properties.find( type ); 25 | 26 | // doesn't exist 27 | if (search == m_properties.end( )) 28 | return nullptr; 29 | 30 | return static_cast( search->second ); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Source/Runtime/Impl/MetaProperty.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** MetaProperty.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | namespace ursine 10 | { 11 | namespace meta 12 | { 13 | template 14 | MetaProperty *MetaPropertyInitializer(Args&&... args) 15 | { 16 | static_assert( std::is_base_of::value, 17 | "Meta properties must inherit from MetaProperty" ); 18 | 19 | return new PropertyType( std::forward( args )... ); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Source/Runtime/Impl/Method.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Method.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "TypeUnpacker.hpp" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | template 16 | Method::Method( 17 | const std::string &name, 18 | ReturnType(ClassType::*method)(ArgTypes...) 19 | ) 20 | : Invokable( name ) 21 | , m_isConst( false ) 22 | , m_classType( typeof( ClassType ) ) 23 | , m_invoker( new MethodInvoker( method ) ) 24 | { 25 | TypeUnpacker::Apply( m_signature ); 26 | } 27 | 28 | template 29 | Method::Method( 30 | const std::string &name, 31 | ReturnType(ClassType::*method)(ArgTypes...) const 32 | ) 33 | : Invokable( name ) 34 | , m_isConst( true ) 35 | , m_classType( typeof( ClassType ) ) 36 | , m_invoker( new MethodInvoker( method ) ) 37 | { 38 | TypeUnpacker::Apply( m_signature ); 39 | } 40 | 41 | /////////////////////////////////////////////////////////////////////// 42 | 43 | template 44 | Variant Method::Invoke(Variant &instance, Args &&...args) const 45 | { 46 | ArgumentList arguments { std::forward( args )... }; 47 | 48 | return Invoke( instance, arguments ); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /Source/Runtime/Impl/Type.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Type.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "TypeUnpacker.hpp" 10 | 11 | #include "../Variant.h" 12 | //#include "../Constructor.h" 13 | 14 | #include "../Common/Logging.h" 15 | 16 | namespace std 17 | { 18 | template<> 19 | struct hash 20 | { 21 | size_t operator()(const ursine::meta::Type &type) const 22 | { 23 | return hash( )( type.GetID( ) ); 24 | } 25 | }; 26 | } 27 | 28 | namespace ursine 29 | { 30 | namespace meta 31 | { 32 | template 33 | Type Type::Get(T &&obj) 34 | { 35 | return { typeof( T ) }; 36 | } 37 | 38 | /////////////////////////////////////////////////////////////////////// 39 | 40 | template 41 | bool Type::DerivesFrom(void) const 42 | { 43 | return DerivesFrom( typeof( T ) ); 44 | } 45 | 46 | template 47 | Json Type::SerializeJson(const ClassType &instance, bool invokeHook) 48 | { 49 | auto type = typeof( ClassType ); 50 | 51 | UAssert( type.IsValid( ), 52 | "Invalid type serialized." 53 | ); 54 | 55 | Variant variant = instance; 56 | 57 | return type.SerializeJson( variant, invokeHook ); 58 | } 59 | 60 | template 61 | ClassType Type::DeserializeJson(const Json &value) 62 | { 63 | auto type = typeof( ClassType ); 64 | 65 | UAssert( type.IsValid( ), 66 | "Invalid type created." 67 | ); 68 | 69 | return type.DeserializeJson( value ).GetValue( ); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Source/Runtime/Impl/TypeCreator.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** TypeCreator.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "../Constructor.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | template 16 | Variant TypeCreator::Create(const Type &type, Args &&...args) 17 | { 18 | static InvokableSignature signature; 19 | 20 | static bool initial = true; 21 | 22 | if (initial) 23 | { 24 | TypeUnpacker::Apply( signature ); 25 | 26 | initial = false; 27 | } 28 | 29 | auto &constructor = type.GetConstructor( signature ); 30 | 31 | return constructor.Invoke( std::forward( args )... ); 32 | } 33 | 34 | template 35 | Variant TypeCreator::CreateDynamic(const Type &type, Args &&...args) 36 | { 37 | static InvokableSignature signature; 38 | 39 | static bool initial = true; 40 | 41 | if (initial) 42 | { 43 | TypeUnpacker::Apply( signature ); 44 | 45 | initial = false; 46 | } 47 | 48 | auto &constructor = type.GetDynamicConstructor( signature ); 49 | 50 | return constructor.Invoke( std::forward( args )... ); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /Source/Runtime/Impl/TypeInfo.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** TypeInfo.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "../Common/Compiler.h" 10 | #include "../TypeData.h" 11 | #include "../TypeID.h" 12 | 13 | #if defined(COMPILER_MSVC) 14 | 15 | #pragma warning(push) 16 | 17 | // unused template parameters 18 | #pragma warning(disable : 4544) 19 | 20 | #endif 21 | 22 | namespace ursine 23 | { 24 | namespace meta 25 | { 26 | template 27 | bool TypeInfo::Defined = false; 28 | 29 | template 30 | void TypeInfo::Register( 31 | TypeID id, 32 | TypeData &data, 33 | bool beingDefined 34 | ) 35 | { 36 | // already defined 37 | if (id == Type::Invalid( ).GetID( )) 38 | return; 39 | 40 | TypeIDs::ID = id; 41 | 42 | typedef typename std::remove_pointer< typename std::decay::type >::type Decayed; 43 | 44 | data.isClass = std::is_class< Decayed >::value; 45 | data.isEnum = std::is_enum< Decayed >::value; 46 | data.isPointer = std::is_pointer< T >::value; 47 | data.isPrimitive = std::is_arithmetic< Decayed >::value; 48 | data.isFloatingPoint = std::is_floating_point< Decayed >::value; 49 | data.isSigned = std::is_signed< Decayed >::value; 50 | 51 | if (beingDefined) 52 | { 53 | addDefaultConstructor( data ); 54 | 55 | applyTrivialAttributes( data ); 56 | } 57 | } 58 | 59 | template 60 | template 61 | void TypeInfo::addDefaultConstructor( 62 | TypeData &data, 63 | typename std::enable_if< 64 | !IsTriviallyDefaultConstructible(U) 65 | >::type* 66 | ) 67 | { 68 | // do nothing 69 | } 70 | 71 | template 72 | template 73 | void TypeInfo::addDefaultConstructor( 74 | TypeData &data, 75 | typename std::enable_if< 76 | IsTriviallyDefaultConstructible(U) 77 | >::type* 78 | ) 79 | { 80 | // add the good 'ol default constructor 81 | data.AddConstructor( { } ); 82 | 83 | // add the good 'ol dynamic default constructor 84 | data.AddConstructor( { } ); 85 | } 86 | 87 | template 88 | template 89 | void TypeInfo::applyTrivialAttributes( 90 | TypeData &data, 91 | typename std::enable_if< 92 | !std::is_trivial::value 93 | >::type* 94 | ) 95 | { 96 | // do nothing 97 | } 98 | 99 | template 100 | template 101 | void TypeInfo::applyTrivialAttributes( 102 | TypeData &data, 103 | typename std::enable_if< 104 | std::is_trivial::value 105 | >::type* 106 | ) 107 | { 108 | data.SetDestructor( ); 109 | } 110 | } 111 | } 112 | 113 | #if defined(COMPILER_MSVC) 114 | 115 | #pragma warning(pop) 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /Source/Runtime/Impl/TypeUnpacker.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** TypeUnpacker.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | namespace ursine 10 | { 11 | namespace meta 12 | { 13 | template 14 | struct TypeUnpacker { }; 15 | 16 | template<> 17 | struct TypeUnpacker<> 18 | { 19 | static void Apply(Type::List &types) { } 20 | }; 21 | 22 | template 23 | struct TypeUnpacker 24 | { 25 | static void Apply(Type::List &types) 26 | { 27 | types.emplace_back( typeof( First ) ); 28 | 29 | TypeUnpacker::Apply( types ); 30 | } 31 | }; 32 | } 33 | } -------------------------------------------------------------------------------- /Source/Runtime/Impl/VariantContainerStandardTypes.hpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** VariantConatinerStandardTypes.hpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #define DECLARE_STANDARD_VARIANT(type) \ 10 | template<> \ 11 | class VariantContainer : public VariantBase \ 12 | { \ 13 | public: \ 14 | VariantContainer(const type &value); \ 15 | VariantContainer(const type &&value); \ 16 | \ 17 | Type GetType(void) const override; \ 18 | void *GetPtr(void) const override; \ 19 | \ 20 | int ToInt(void) const override; \ 21 | bool ToBool(void) const override; \ 22 | float ToFloat(void) const override; \ 23 | double ToDouble(void) const override; \ 24 | std::string ToString(void) const override; \ 25 | \ 26 | VariantBase *Clone(void) const override; \ 27 | \ 28 | private: \ 29 | friend class Variant; \ 30 | \ 31 | VariantContainer &operator=(const VariantContainer &rhs) = delete; \ 32 | \ 33 | type m_value; \ 34 | }; \ 35 | 36 | namespace ursine 37 | { 38 | namespace meta 39 | { 40 | // void is a tricky 'ol fella, and must be defined manually 41 | template<> 42 | class VariantContainer : public VariantBase 43 | { 44 | public: 45 | VariantContainer(void); 46 | 47 | Type GetType(void) const override; 48 | void *GetPtr(void) const override; 49 | 50 | int ToInt(void) const override; 51 | bool ToBool(void) const override; 52 | float ToFloat(void) const override; 53 | double ToDouble(void) const override; 54 | std::string ToString(void) const override; 55 | 56 | VariantBase *Clone(void) const override; 57 | 58 | private: 59 | friend class Variant; 60 | 61 | VariantContainer &operator=(const VariantContainer &rhs) = delete; 62 | }; 63 | 64 | DECLARE_STANDARD_VARIANT( int ); 65 | DECLARE_STANDARD_VARIANT( unsigned int ); 66 | DECLARE_STANDARD_VARIANT( bool ); 67 | DECLARE_STANDARD_VARIANT( float ); 68 | DECLARE_STANDARD_VARIANT( double ); 69 | DECLARE_STANDARD_VARIANT( std::string ); 70 | } 71 | } 72 | 73 | #undef DECLARE_STANDARD_TYPE -------------------------------------------------------------------------------- /Source/Runtime/Invokable.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Invokable.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "Invokable.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | Invokable::Invokable(const std::string &name) 16 | : m_name( name ) { } 17 | 18 | const InvokableSignature &Invokable::GetSignature(void) const 19 | { 20 | return m_signature; 21 | } 22 | 23 | const std::string &Invokable::GetName(void) const 24 | { 25 | return m_name; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Source/Runtime/Invokable.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Invokable.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "InvokableConfig.h" 10 | #include "ArgumentConfig.h" 11 | 12 | #include 13 | 14 | namespace ursine 15 | { 16 | namespace meta 17 | { 18 | class Type; 19 | 20 | class Invokable 21 | { 22 | public: 23 | Invokable(const std::string &name = "INVALID"); 24 | 25 | template 26 | static InvokableSignature CreateSignature(void); 27 | 28 | const InvokableSignature &GetSignature(void) const; 29 | 30 | const std::string &GetName(void) const; 31 | 32 | protected: 33 | std::string m_name; 34 | 35 | InvokableSignature m_signature; 36 | }; 37 | } 38 | } 39 | 40 | #include "Impl/Invokable.hpp" -------------------------------------------------------------------------------- /Source/Runtime/InvokableConfig.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** InvokableConfig.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | // number of arguments within the usage of a dynamic method/function invoker 13 | #define THIS_ARG_COUNT sizeof...( ArgTypes ) 14 | 15 | namespace ursine 16 | { 17 | namespace meta 18 | { 19 | class Type; 20 | 21 | typedef std::vector InvokableSignature; 22 | 23 | template 24 | using InvokableOverloadMap = 25 | std::unordered_multimap; 26 | 27 | // maximum number of arguments supported 28 | const size_t MaxArgumentCount = 10; 29 | } 30 | } -------------------------------------------------------------------------------- /Source/Runtime/JsonConfig.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace ursine 6 | { 7 | using Json = json11::Json; 8 | } -------------------------------------------------------------------------------- /Source/Runtime/Macros.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Macros.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #if defined(__REFLECTION_PARSER__) 10 | 11 | #define Meta(...) __attribute__((annotate(#__VA_ARGS__))) 12 | 13 | #define __META_EXTERNAL(type, guid) \ 14 | typedef type __META_EXTERNAL__##guid; \ 15 | 16 | #define _META_EXTERNAL(type, guid) __META_EXTERNAL(type, guid) 17 | 18 | #define MetaExternal(type) _META_EXTERNAL(type, __COUNTER__) 19 | 20 | #define META_OBJECT 21 | 22 | #else 23 | 24 | #define Meta(...) 25 | 26 | #define MetaExternal(type) 27 | 28 | #define MetaInitialize(initializer) \ 29 | { \ 30 | auto &db = ursine::meta::ReflectionDatabase::Instance( ); \ 31 | initializer; \ 32 | } \ 33 | 34 | // Used in objects to preserve virtual inheritance functionality 35 | #define META_OBJECT \ 36 | ursine::meta::Type GetType(void) const override \ 37 | { \ 38 | return typeof( decltype( *this ) ); \ 39 | } \ 40 | ursine::meta::Object *Clone(void) const override \ 41 | { \ 42 | typedef \ 43 | std::remove_const< \ 44 | std::remove_reference< \ 45 | decltype( *this ) \ 46 | >::type \ 47 | >::type ClassType; \ 48 | return new ClassType( *this ); \ 49 | } \ 50 | 51 | #endif -------------------------------------------------------------------------------- /Source/Runtime/Meta.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Meta.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "Macros.h" 10 | 11 | #include "MetaProperty.h" 12 | 13 | #ifndef __REFLECTION_PARSER__ 14 | 15 | #include "Object.h" 16 | 17 | #include "Variant.h" 18 | 19 | #include "Type.h" 20 | 21 | #include "MetaManager.h" 22 | 23 | #include "Enum.h" 24 | #include "Constructor.h" 25 | #include "Destructor.h" 26 | #include "Field.h" 27 | #include "Method.h" 28 | #include "Function.h" 29 | #include "Global.h" 30 | 31 | #endif -------------------------------------------------------------------------------- /Source/Runtime/MetaContainer.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** MetaContainer.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "MetaContainer.h" 10 | #include "MetaManager.h" 11 | 12 | namespace ursine 13 | { 14 | namespace meta 15 | { 16 | const MetaManager &MetaContainer::GetMeta(void) const 17 | { 18 | return m_meta; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Source/Runtime/MetaContainer.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** MetaContainer.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "MetaManager.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | class MetaContainer 16 | { 17 | public: 18 | const MetaManager &GetMeta(void) const; 19 | 20 | private: 21 | MetaContainer &operator=(const MetaContainer &rhs) = delete; 22 | 23 | friend class ReflectionDatabase; 24 | friend struct TypeData; 25 | 26 | MetaManager m_meta; 27 | }; 28 | } 29 | } -------------------------------------------------------------------------------- /Source/Runtime/MetaManager.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** MetaManager.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "MetaProperty.h" 10 | 11 | #include "JsonConfig.h" 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace ursine 18 | { 19 | namespace meta 20 | { 21 | class Type; 22 | class Variant; 23 | 24 | class MetaManager 25 | { 26 | public: 27 | typedef std::initializer_list< 28 | std::pair 29 | > Initializer; 30 | 31 | typedef std::vector PropertyList; 32 | 33 | MetaManager(void); 34 | MetaManager(const MetaManager &rhs); 35 | MetaManager(const MetaManager &&rhs); 36 | 37 | const MetaManager &operator=(const MetaManager &rhs); 38 | 39 | MetaManager(const Initializer &properties); 40 | 41 | ~MetaManager(void); 42 | 43 | Variant GetProperty(Type type) const; 44 | 45 | template 46 | const PropertyType *GetProperty(void) const; 47 | 48 | // Sets the given property 49 | void SetProperty(Type type, const MetaProperty *value); 50 | 51 | // Gets all properties 52 | PropertyList GetProperties(void) const; 53 | 54 | Json SerializeJson(void) const; 55 | 56 | private: 57 | void copy(const MetaManager &rhs); 58 | 59 | std::map m_properties; 60 | }; 61 | } 62 | } 63 | 64 | #include "Impl/MetaManager.hpp" -------------------------------------------------------------------------------- /Source/Runtime/MetaTraits.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** MetaTraits.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "Array.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta_traits 14 | { 15 | template 16 | struct TypeOrEnumType 17 | { 18 | typedef T type; 19 | }; 20 | 21 | template 22 | struct TypeOrEnumType::value 25 | >::type 26 | > 27 | { 28 | typedef typename std::underlying_type::type type; 29 | }; 30 | 31 | /////////////////////////////////////////////////////////////////////////// 32 | 33 | template 34 | struct RemoveArray 35 | { 36 | typedef T type; 37 | }; 38 | 39 | template 40 | struct RemoveArray> 41 | { 42 | typedef T type; 43 | }; 44 | 45 | /////////////////////////////////////////////////////////////////////////// 46 | 47 | template 48 | struct IsArray 49 | { 50 | static const bool value = false; 51 | }; 52 | 53 | template 54 | struct IsArray> 55 | { 56 | static const bool value = true; 57 | }; 58 | 59 | /////////////////////////////////////////////////////////////////////////// 60 | 61 | template 62 | using ArrayByValue = Array; 63 | 64 | template 65 | using ArrayByReference = typename std::add_lvalue_reference>::type; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Source/Runtime/Method.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Method.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "Method.h" 10 | 11 | #include "Common/Logging.h" 12 | 13 | namespace ursine 14 | { 15 | namespace meta 16 | { 17 | Method::Method(void) 18 | : Invokable( ) 19 | , m_isConst( true ) 20 | , m_classType( Type::Invalid( ) ) 21 | , m_invoker( nullptr ) { } 22 | 23 | const Method &Method::Invalid(void) 24 | { 25 | static Method invalid; 26 | 27 | return invalid; 28 | } 29 | 30 | Type Method::GetClassType(void) const 31 | { 32 | return m_classType; 33 | } 34 | 35 | bool Method::IsValid(void) const 36 | { 37 | return m_invoker != nullptr; 38 | } 39 | 40 | bool Method::IsConst(void) const 41 | { 42 | return m_isConst; 43 | } 44 | 45 | Variant Method::Invoke( 46 | Variant &instance, 47 | ArgumentList &arguments 48 | ) const 49 | { 50 | #if defined(_DEBUG) 51 | 52 | UAssert( IsValid( ), 53 | "Invalid method invoked." 54 | ); 55 | 56 | UAssert( !(instance.IsConst( ) && !m_isConst), 57 | "Non-const method invoked on const object." 58 | ); 59 | 60 | UAssert( instance.GetType( ) == m_classType, 61 | "Incompatible method invoked with instance." 62 | ); 63 | 64 | #endif 65 | 66 | return m_invoker->Invoke( instance, arguments ); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Source/Runtime/Method.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Method.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "MetaContainer.h" 10 | 11 | #include "Invokable.h" 12 | 13 | #include "Variant.h" 14 | #include "Argument.h" 15 | 16 | #include "MethodInvoker.h" 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | namespace ursine 23 | { 24 | namespace meta 25 | { 26 | class Method 27 | : public MetaContainer 28 | , public Invokable 29 | { 30 | public: 31 | Method(void); 32 | 33 | template< 34 | class ClassType, 35 | typename ReturnType, 36 | typename ...ArgTypes 37 | > 38 | Method( 39 | const std::string &name, 40 | ReturnType(ClassType::*method)(ArgTypes...) 41 | ); 42 | 43 | // detect const-ness 44 | template< 45 | class ClassType, 46 | typename ReturnType, 47 | typename ...ArgTypes 48 | > 49 | Method( 50 | const std::string &name, 51 | ReturnType(ClassType::*method)(ArgTypes...) const 52 | ); 53 | 54 | static const Method &Invalid(void); 55 | 56 | Type GetClassType(void) const; 57 | 58 | bool IsValid(void) const; 59 | bool IsConst(void) const; 60 | 61 | Variant Invoke(Variant &instance, ArgumentList &arguments) const; 62 | 63 | template 64 | Variant Invoke(Variant &instance, Args &&...args) const; 65 | 66 | private: 67 | bool m_isConst; 68 | 69 | Type m_classType; 70 | 71 | std::shared_ptr m_invoker; 72 | }; 73 | } 74 | } 75 | 76 | #include "Impl/Method.hpp" -------------------------------------------------------------------------------- /Source/Runtime/MethodInvoker.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** MethodInvoker.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "MethodInvokerBase.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | template 16 | class MethodInvoker : public MethodInvokerBase 17 | { 18 | public: 19 | typedef ReturnType (ClassType::*Signature)(ArgTypes...); 20 | typedef ReturnType (ClassType::*ConstSignature)(ArgTypes...) const; 21 | 22 | static_assert( THIS_ARG_COUNT <= MaxArgumentCount, 23 | "Method has too many arguments. It's time to generate more overloads." 24 | ); 25 | 26 | MethodInvoker(Signature method); 27 | MethodInvoker(ConstSignature method); 28 | 29 | Variant Invoke(Variant &obj, const ArgumentList &arguments) override; 30 | 31 | private: 32 | template 33 | Variant invoke(Variant &obj, const ArgumentList &arguments); 34 | 35 | template 36 | Variant invoke(Variant &obj, const ArgumentList &arguments); 37 | 38 | template 39 | Variant invoke(Variant &obj, const ArgumentList &arguments); 40 | 41 | template 42 | Variant invoke(Variant &obj, const ArgumentList &arguments); 43 | 44 | template 45 | Variant invoke(Variant &obj, const ArgumentList &arguments); 46 | 47 | template 48 | Variant invoke(Variant &obj, const ArgumentList &arguments); 49 | 50 | template 51 | Variant invoke(Variant &obj, const ArgumentList &arguments); 52 | 53 | template 54 | Variant invoke(Variant &obj, const ArgumentList &arguments); 55 | 56 | template 57 | Variant invoke(Variant &obj, const ArgumentList &arguments); 58 | 59 | template 60 | Variant invoke(Variant &obj, const ArgumentList &arguments); 61 | 62 | template 63 | Variant invoke(Variant &obj, const ArgumentList &arguments); 64 | 65 | ConstSignature m_method; 66 | }; 67 | } 68 | } 69 | 70 | #include "Impl/MethodInvoker.hpp" 71 | #include "Impl/VoidMethodInvoker.hpp" -------------------------------------------------------------------------------- /Source/Runtime/MethodInvokerBase.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** MethodInvokerBase.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "InvokableConfig.h" 10 | #include "ArgumentConfig.h" 11 | 12 | namespace ursine 13 | { 14 | namespace meta 15 | { 16 | class Variant; 17 | 18 | class MethodInvokerBase 19 | { 20 | public: 21 | virtual ~MethodInvokerBase(void) { } 22 | 23 | virtual Variant Invoke(Variant &obj, const ArgumentList &arguments) = 0; 24 | }; 25 | } 26 | } -------------------------------------------------------------------------------- /Source/Runtime/Object.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Object.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "JsonConfig.h" 10 | 11 | // Constructs a variant that wraps an object 12 | #define ObjectVariant(object) ursine::meta::Variant { object, ursine::meta::variant_policy::WrapObject( ) } 13 | 14 | namespace ursine 15 | { 16 | namespace meta 17 | { 18 | class Type; 19 | 20 | class Object 21 | { 22 | public: 23 | virtual ~Object(void) { } 24 | 25 | virtual Type GetType(void) const = 0; 26 | virtual Object *Clone(void) const = 0; 27 | 28 | virtual void OnSerialize(Json::object &output) const { } 29 | virtual void OnDeserialize(const Json &input) { } 30 | }; 31 | } 32 | } -------------------------------------------------------------------------------- /Source/Runtime/ObjectWrapper.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** ObjectWrapper.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "ObjectWrapper.h" 10 | #include "Object.h" 11 | 12 | #include "Type.h" 13 | 14 | namespace ursine 15 | { 16 | namespace meta 17 | { 18 | ObjectWrapper::ObjectWrapper(Object *instance) 19 | : m_object( instance ) 20 | { 21 | } 22 | 23 | Type ObjectWrapper::GetType(void) const 24 | { 25 | return m_object->GetType( ); 26 | } 27 | 28 | void *ObjectWrapper::GetPtr(void) const 29 | { 30 | return m_object; 31 | } 32 | 33 | int ObjectWrapper::ToInt(void) const 34 | { 35 | return int( ); 36 | } 37 | 38 | bool ObjectWrapper::ToBool(void) const 39 | { 40 | return bool( ); 41 | } 42 | 43 | float ObjectWrapper::ToFloat(void) const 44 | { 45 | return float( ); 46 | } 47 | 48 | double ObjectWrapper::ToDouble(void) const 49 | { 50 | return double( ); 51 | } 52 | 53 | std::string ObjectWrapper::ToString(void) const 54 | { 55 | return std::string( ); 56 | } 57 | 58 | VariantBase *ObjectWrapper::Clone(void) const 59 | { 60 | return new ObjectWrapper( m_object ); 61 | } 62 | 63 | void ObjectWrapper::OnSerialize(Json::object &output) const 64 | { 65 | m_object->OnSerialize( output ); 66 | } 67 | 68 | void ObjectWrapper::OnDeserialize(const Json &input) 69 | { 70 | m_object->OnDeserialize( input ); 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /Source/Runtime/ObjectWrapper.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** ObjectWrapper.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "VariantBase.h" 10 | 11 | #include "JsonConfig.h" 12 | 13 | namespace ursine 14 | { 15 | namespace meta 16 | { 17 | class Object; 18 | 19 | class ObjectWrapper : public VariantBase 20 | { 21 | public: 22 | ObjectWrapper(Object *instance); 23 | 24 | Type GetType(void) const override; 25 | void *GetPtr(void) const override; 26 | 27 | int ToInt(void) const override; 28 | bool ToBool(void) const override; 29 | float ToFloat(void) const override; 30 | double ToDouble(void) const override; 31 | std::string ToString(void) const override; 32 | 33 | VariantBase *Clone(void) const override; 34 | 35 | void OnSerialize(Json::object &output) const override; 36 | void OnDeserialize(const Json &input) override; 37 | private: 38 | Object *m_object; 39 | }; 40 | } 41 | } -------------------------------------------------------------------------------- /Source/Runtime/Precompiled.cpp: -------------------------------------------------------------------------------- 1 | #include "Precompiled.h" 2 | 3 | // intentially empty -------------------------------------------------------------------------------- /Source/Runtime/Precompiled.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // standard library 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include -------------------------------------------------------------------------------- /Source/Runtime/ReflectionModule.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** ReflectionModule.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "ReflectionModule.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | ReflectionModule::ReflectionModule(ReflectionDatabase &db) 16 | : db( db ) { } 17 | } 18 | } -------------------------------------------------------------------------------- /Source/Runtime/ReflectionModule.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** ReflectionModule.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "ReflectionDatabase.h" 10 | 11 | #define DECLARE_REFLECTION_MODULE(module) \ 12 | namespace meta_generated \ 13 | { \ 14 | class Module##module : public ursine::meta::ReflectionModule \ 15 | { \ 16 | public: \ 17 | Module##module(ursine::meta::ReflectionDatabase &db); \ 18 | ~Module##module(void); \ 19 | }; \ 20 | } \ 21 | 22 | #define UsingModule(module) meta_generated::Module##module _##module( db ); 23 | 24 | namespace ursine 25 | { 26 | namespace meta 27 | { 28 | class ReflectionModule 29 | { 30 | public: 31 | ReflectionModule(ReflectionDatabase &db); 32 | 33 | protected: 34 | ReflectionDatabase &db; 35 | }; 36 | } 37 | } -------------------------------------------------------------------------------- /Source/Runtime/RuntimeMetaProperties.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** RuntimeMetaProperties.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "MetaProperty.h" 10 | #include "Type.h" 11 | 12 | /** @brief Ensures associative enum values are serialized as their literal value. 13 | */ 14 | class SerializeAsNumber : public ursine::meta::MetaProperty 15 | { 16 | META_OBJECT; 17 | }; -------------------------------------------------------------------------------- /Source/Runtime/TypeConfig.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** TypeConfig.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "TypeID.h" 10 | #include "MetaTraits.h" 11 | 12 | #include 13 | 14 | // Gets the type ID of a given expression 15 | #define typeidof(expr) \ 16 | ursine::meta::TypeIDs< \ 17 | ursine::meta::CleanedType< \ 18 | typename ursine::meta_traits::RemoveArray::type \ 19 | > \ 20 | >::ID \ 21 | 22 | // Converts the expression into a meta::Type instance 23 | #define typeof(expr) \ 24 | ursine::meta::Type( \ 25 | typeidof( expr ), \ 26 | ursine::meta_traits::IsArray::value \ 27 | ) \ 28 | 29 | // Converts the resulting type of the given expression to a meta::Type instance 30 | #define decltypeof(expr) typeof( decltype( expr ) ) 31 | 32 | namespace ursine 33 | { 34 | namespace meta 35 | { 36 | template 37 | using CleanedType = 38 | typename std::remove_cv< 39 | typename std::remove_reference< T >::type 40 | >::type; 41 | } 42 | } -------------------------------------------------------------------------------- /Source/Runtime/TypeCreator.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** TypeCreator.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "TypeCreator.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | Variant TypeCreator::CreateVariadic(const Type &type, const ArgumentList &arguments) 16 | { 17 | InvokableSignature signature; 18 | 19 | for (auto &argument : arguments) 20 | signature.emplace_back( argument.GetType( ) ); 21 | 22 | auto &constructor = type.GetConstructor( signature ); 23 | 24 | return constructor.InvokeVariadic( arguments ); 25 | } 26 | 27 | Variant TypeCreator::CreateDynamicVariadic(const Type &type, const ArgumentList &arguments) 28 | { 29 | InvokableSignature signature; 30 | 31 | for (auto &argument : arguments) 32 | signature.emplace_back( argument.GetType( ) ); 33 | 34 | auto &constructor = type.GetDynamicConstructor( signature ); 35 | 36 | return constructor.InvokeVariadic( arguments ); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Source/Runtime/TypeCreator.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** TypeCreator.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "Variant.h" 10 | 11 | namespace ursine 12 | { 13 | namespace meta 14 | { 15 | class TypeCreator 16 | { 17 | public: 18 | /** @brief Instantiates an instance of the given type with the given 19 | * constructor signature. NOTE: it is much faster to cache 20 | * the appropriate constructor first, then call 21 | * Invoke( ) manually. 22 | * @param arguments List of arguments to forward to the 23 | * type constructor. 24 | * @return Variant representing the newly created type instance. 25 | */ 26 | static Variant CreateVariadic(const Type &type, const ArgumentList &arguments); 27 | 28 | /** @brief Same as CreateVariadic( ), except it uses the dynamic 29 | * constructor and returns the class pointer type. 30 | * @param arguments List of arguments to forward to the 31 | * type constructor. 32 | * @return Variant representing a pointer to the newly 33 | * created type instance. NOTE: client is responsible for 34 | * memory management, either through type.Destroy( ) or 35 | * directly calling the underlying pointer's deconstructor 36 | */ 37 | static Variant CreateDynamicVariadic(const Type &type, const ArgumentList &arguments); 38 | 39 | /** @brief Instantiates an instance of the type with the given 40 | * constructor signature. NOTE: it is much faster to cache 41 | * the appropriate constructor first, then call 42 | * Invoke( ) manually. 43 | * @param args List of arguments to forward to the 44 | * type constructor. 45 | * @return Variant representing the newly created type instance. 46 | */ 47 | template 48 | static Variant Create(const Type &type, Args &&...args); 49 | 50 | /** @brief Same as Create( ), except it uses the dynamic 51 | * constructor and returns the class pointer type. 52 | * @param args List of arguments to forward to the 53 | * type constructor. 54 | * @return Variant representing a pointer to the newly 55 | * created type instance. NOTE: client is responsible for 56 | * memory management, either through type.Destroy( ) or 57 | * directly calling the underlying pointer's deconstructor 58 | */ 59 | template 60 | static Variant CreateDynamic(const Type &type, Args &&...args); 61 | }; 62 | } 63 | } 64 | 65 | #include "Impl/TypeCreator.hpp" -------------------------------------------------------------------------------- /Source/Runtime/TypeID.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** TypeData.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | namespace ursine 10 | { 11 | namespace meta 12 | { 13 | typedef unsigned TypeID; 14 | 15 | const TypeID InvalidTypeID = 0; 16 | 17 | template 18 | struct TypeIDs 19 | { 20 | static TypeID ID; 21 | }; 22 | 23 | template 24 | TypeID TypeIDs::ID = InvalidTypeID; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Source/Runtime/TypeInfo.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** TypeInfo.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include "TypeConfig.h" 10 | 11 | #include "../Common/Compiler.h" 12 | 13 | #include 14 | 15 | #if defined(COMPILER_CLANG) || defined(COMPILER_GNU) 16 | 17 | #define IsTriviallyDefaultConstructible(x) std::has_trivial_default_constructor::value 18 | 19 | #else 20 | 21 | #define IsTriviallyDefaultConstructible(x) std::is_trivially_default_constructible::value 22 | 23 | #endif 24 | 25 | namespace ursine 26 | { 27 | namespace meta 28 | { 29 | struct TypeData; 30 | 31 | template 32 | struct TypeInfo 33 | { 34 | static bool Defined; 35 | 36 | static void Register(TypeID id, TypeData &data, bool beingDefined); 37 | 38 | private: 39 | template 40 | static void addDefaultConstructor( 41 | TypeData &data, 42 | typename std::enable_if< 43 | !IsTriviallyDefaultConstructible(U) 44 | >::type* = nullptr 45 | ); 46 | 47 | template 48 | static void addDefaultConstructor( 49 | TypeData &data, 50 | typename std::enable_if< 51 | IsTriviallyDefaultConstructible(U) 52 | >::type* = nullptr 53 | ); 54 | 55 | template 56 | static void applyTrivialAttributes(TypeData &data, 57 | typename std::enable_if< 58 | !std::is_trivial::value 59 | >::type* = nullptr 60 | ); 61 | 62 | template 63 | static void applyTrivialAttributes(TypeData &data, 64 | typename std::enable_if< 65 | std::is_trivial::value 66 | >::type* = nullptr 67 | ); 68 | }; 69 | } 70 | } 71 | 72 | #include "Impl/TypeInfo.hpp" 73 | -------------------------------------------------------------------------------- /Source/Runtime/Variant.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** Variant.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "Variant.h" 10 | 11 | #include "Type.h" 12 | 13 | namespace ursine 14 | { 15 | namespace meta 16 | { 17 | Variant::Variant(void) 18 | : m_isConst( true ) 19 | , m_base( nullptr ) { } 20 | 21 | Variant::Variant(const Variant &rhs) 22 | : m_isConst( rhs.m_isConst ) 23 | , m_base( rhs.m_base ? rhs.m_base->Clone( ) : nullptr ) { } 24 | 25 | Variant::Variant(Variant &&rhs) 26 | : m_isConst( rhs.m_isConst ) 27 | , m_base( rhs.m_base ) 28 | { 29 | rhs.m_isConst = true; 30 | rhs.m_base = nullptr; 31 | } 32 | 33 | Variant::~Variant(void) 34 | { 35 | delete m_base; 36 | } 37 | 38 | Variant &Variant::operator=(const Variant &rhs) 39 | { 40 | Variant( rhs ).Swap( *this ); 41 | 42 | return *this; 43 | } 44 | 45 | Variant &Variant::operator=(Variant &&rhs) 46 | { 47 | rhs.Swap( *this ); 48 | 49 | Variant( ).Swap( rhs ); 50 | 51 | return *this; 52 | } 53 | 54 | Variant::operator bool(void) const 55 | { 56 | return m_base != nullptr; 57 | } 58 | 59 | Type Variant::GetType(void) const 60 | { 61 | return m_base ? m_base->GetType( ) : Type::Invalid( ); 62 | } 63 | 64 | ArrayWrapper Variant::GetArray(void) const 65 | { 66 | return m_base ? m_base->GetArray( ) : ArrayWrapper( ); 67 | } 68 | 69 | int Variant::ToInt(void) const 70 | { 71 | return m_base ? m_base->ToInt( ) : int( ); 72 | } 73 | 74 | bool Variant::ToBool(void) const 75 | { 76 | return m_base ? m_base->ToBool( ) : bool( ); 77 | } 78 | 79 | float Variant::ToFloat(void) const 80 | { 81 | return m_base ? m_base->ToFloat( ) : float( ); 82 | } 83 | 84 | double Variant::ToDouble(void) const 85 | { 86 | return m_base ? m_base->ToDouble( ) : double( ); 87 | } 88 | 89 | std::string Variant::ToString(void) const 90 | { 91 | return m_base ? m_base->ToString( ) : std::string( ); 92 | } 93 | 94 | Json Variant::SerializeJson(void) const 95 | { 96 | return GetType( ).SerializeJson( *this ); 97 | } 98 | 99 | void Variant::Swap(Variant &other) 100 | { 101 | std::swap( m_base, other.m_base ); 102 | } 103 | 104 | bool Variant::IsValid(void) const 105 | { 106 | return m_base != nullptr; 107 | } 108 | 109 | bool Variant::IsConst(void) const 110 | { 111 | return m_isConst; 112 | } 113 | 114 | bool Variant::IsArray(void) const 115 | { 116 | return m_base ? m_base->IsArray( ) : false; 117 | } 118 | 119 | void *Variant::getPtr(void) const 120 | { 121 | return m_base ? m_base->GetPtr( ) : nullptr; 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /Source/Runtime/VariantBase.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** VariantBase.cpp 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #include "Precompiled.h" 8 | 9 | #include "VariantBase.h" 10 | 11 | #include "ArrayWrapper.h" 12 | 13 | namespace ursine 14 | { 15 | namespace meta 16 | { 17 | bool VariantBase::IsArray(void) const 18 | { 19 | return false; 20 | } 21 | 22 | ArrayWrapper VariantBase::GetArray(void) const 23 | { 24 | // invalid wrapper 25 | return { }; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Source/Runtime/VariantBase.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** VariantBase.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include "JsonConfig.h" 12 | 13 | namespace ursine 14 | { 15 | namespace meta 16 | { 17 | class Type; 18 | class ArrayWrapper; 19 | 20 | class VariantBase 21 | { 22 | public: 23 | virtual ~VariantBase(void) { } 24 | 25 | virtual Type GetType(void) const = 0; 26 | 27 | virtual void *GetPtr(void) const = 0; 28 | 29 | virtual int ToInt(void) const = 0; 30 | virtual bool ToBool(void) const = 0; 31 | virtual float ToFloat(void) const = 0; 32 | virtual double ToDouble(void) const = 0; 33 | virtual std::string ToString(void) const = 0; 34 | 35 | virtual bool IsArray(void) const; 36 | virtual ArrayWrapper GetArray(void) const; 37 | 38 | virtual VariantBase *Clone(void) const = 0; 39 | 40 | virtual void OnSerialize(Json::object &output) const { } 41 | virtual void OnDeserialize(const Json &input) { } 42 | }; 43 | } 44 | } -------------------------------------------------------------------------------- /Source/Runtime/VariantPolicy.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | ** Copyright (c) 2016 Austin Brunkhorst, All Rights Reserved. 3 | ** 4 | ** VariantPolicy.h 5 | ** --------------------------------------------------------------------------*/ 6 | 7 | #pragma once 8 | 9 | namespace ursine 10 | { 11 | namespace meta 12 | { 13 | namespace variant_policy 14 | { 15 | /** @brief Wraps an Object pointer, rather than copying the value. 16 | * This also ensures base class pointers can resolve their inherited type 17 | */ 18 | struct WrapObject { }; 19 | 20 | /** @brief Uses a reference to a value rather than copying it 21 | */ 22 | struct NoCopy { }; 23 | } 24 | } 25 | } --------------------------------------------------------------------------------