Skip to content

Commit

Permalink
refactor, changed file directories, changed namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
RedSkittleFox committed Jan 1, 2024
1 parent 0a57aad commit ef11d10
Show file tree
Hide file tree
Showing 9 changed files with 563 additions and 1,124 deletions.
53 changes: 38 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,45 @@
cmake_minimum_required(VERSION 3.21)

set(MODULE_NAME ruby-reflexpr) # change me

project(${MODULE_NAME} LANGUAGES CXX)
project(reflexpr)

if (PROJECT_IS_TOP_LEVEL)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

set(CMAKE_SYSTEM_VERSION 10.0.19041.0)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin-etc")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# set(CMAKE_SYSTEM_VERSION 10.0.22000.0)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin-lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin-etc")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED)
endif()

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
enable_testing()

include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_SUPPORTED OUTPUT IPO_NOT_SUPPORTED_ERROR LANGUAGES CXX)

if(NOT ${IPO_SUPPORTED})
message(STATUS "IPO / LTO not supported: <${IPO_NOT_SUPPORTED_ERROR}>")
else()
message(STATUS "IPO / LTO supported.")
endif()

include(FetchContent)

add_subdirectory("include")

add_library(fox::reflexpr ALIAS reflexpr)

option(sample ON)
# option(test ON)

if (sample)
add_subdirectory("sample")
endif()

add_subdirectory(src)
add_subdirectory(examples)
# if (test)
# add_subdirectory("test")
# endif()
43 changes: 21 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# ruby-reflexpr
is a c++20 compile and runtime Struct Reflections header only library. It allows you to iterate over aggregate type's member variables.
is a c++20 compile and runtime aggregate reflections header only library. It allows you to iterate over aggregate type's member variables.

# Example Usage
```cpp
// demo.cpp
#include <iostream>
#include <string_view>
#include <algorithm>
#include <string>

#include "ruby_reflexpr.hpp"
#include <fox/reflexpr.hpp>

struct aggregate_type
{
Expand All @@ -31,7 +33,7 @@ struct functor
void operator()() const
{
std::cout << "Type: " << typeid(T).name() << '\n';
};
}
};

struct functor_reflected
Expand All @@ -40,12 +42,12 @@ struct functor_reflected
void operator()(const std::string& name) const
{
std::cout << "Name: " << name << " Type: " << typeid(T).name() << '\n';
};
}
};

int main()
{
// DEMO: reflexpr::for_each_member_variable
// DEMO: fox::reflexpr::for_each_member_variable
{
std::cout << "For each member variable:\n";
auto func = []<class T>(T & v)
Expand All @@ -54,20 +56,21 @@ int main()
};

aggregate_type at{ 1 , 3.5f, "Foxes are great!" };
reflexpr::for_each_member_variable(at, func);

static_assert(fox::reflexpr::aggregate<aggregate_type>, "sus");
fox::reflexpr::for_each_member_variable(at, func);
std::cout << '\n';
}

// DEMO: reflexpr::for_each_member_type
// DEMO: fox::reflexpr::for_each_member_type
{
std::cout << "For each member type:\n";

reflexpr::for_each_member_type<aggregate_type, functor>(functor{});
fox::reflexpr::for_each_member_type<aggregate_type, functor>(functor{});
std::cout << '\n';
}

// DEMO: reflexpr::for_each_reflected_member_variable
// DEMO: fox::reflexpr::for_each_reflected_member_variable
{
std::cout << "For each member variable reflected:\n";
auto func = []<class T>(T & v, const std::string& name)
Expand All @@ -77,29 +80,25 @@ int main()

aggregate_type_reflected at{ 1 , 3.5f, "Foxes are great!" };

reflexpr::for_each_reflected_member_variable(at, func);
fox::reflexpr::for_each_reflected_member_variable(at, func);
std::cout << '\n';
}

// DEMO: reflexpr::for_each_reflected_member_type
// DEMO: fox::reflexpr::for_each_reflected_member_type
{
std::cout << "For each member type reflected:\n";

reflexpr::for_each_reflected_member_type<aggregate_type_reflected, functor_reflected>(functor_reflected{});
fox::reflexpr::for_each_reflected_member_type<aggregate_type_reflected, functor_reflected>(functor_reflected{});
std::cout << '\n';
}

return 0;
return 1;
}
```

# Planned Improvements
* Increasing member variable limit to 30
* Introducting `noreflect` specifier.
* Improving member variable names parsing.

* Improving member variable names parsing.
* Write unit tests.

# Limitation
Right now it supports only up to 20 member variables and introduces small runtime overhead when registering member variable names.

# Extra Notice
This library is part of Ruby ecosystem created and managed by RedSkittleFox. Not all headers are avialable. This header is standalone.
Right now it supports only up to 40 member variables and introduces small runtime overhead when registering member variable names.
34 changes: 0 additions & 34 deletions examples/CMakeLists.txt

This file was deleted.

23 changes: 23 additions & 0 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.21)

set(sources
"${CMAKE_CURRENT_SOURCE_DIR}/fox/reflexpr.hpp"
)

source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${sources})

add_library(
reflexpr
INTERFACE
${sources}
)

if(${IPO_SUPPORTED})
set_target_properties(reflexpr PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()

target_include_directories(
reflexpr
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}
)
Loading

0 comments on commit ef11d10

Please sign in to comment.