- Basic RTTI type data with inheritance.
This commit is contained in:
@@ -5,12 +5,17 @@ set(CMAKE_CXX_STANDARD 23)
|
||||
|
||||
add_executable(fennec-metaprogramming main.cpp
|
||||
float.h
|
||||
integer.h)
|
||||
integer.h
|
||||
type_name.h)
|
||||
|
||||
target_compile_definitions(fennec-metaprogramming PUBLIC
|
||||
${FENNEC_COMPILE_DEFINITIONS}
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT .metaprogramming
|
||||
COMMAND fennec-metaprogramming
|
||||
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/../include/fennec/lang"
|
||||
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/../include/"
|
||||
COMMENT "Generating intrinsics"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
inline void float_h()
|
||||
{
|
||||
std::ofstream out("float.h");
|
||||
std::ofstream out("fennec/langcpp/float.h");
|
||||
|
||||
out << "// =====================================================================================================================" << std::endl;
|
||||
out << "// fennec, a free and open source game engine" << std::endl;
|
||||
@@ -64,7 +64,7 @@ inline void float_h()
|
||||
|
||||
out << "" << std::endl;
|
||||
|
||||
out << "#include <fennec/lang/bits.h>" << std::endl;
|
||||
out << "#include <fennec/langcpp/bits.h>" << std::endl;
|
||||
|
||||
out << "" << std::endl;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
inline void integer_h()
|
||||
{
|
||||
|
||||
std::ofstream out("integer.h");
|
||||
std::ofstream out("fennec/langcpp/integer.h");
|
||||
|
||||
out << "// =====================================================================================================================" << std::endl;
|
||||
out << "// fennec, a free and open source game engine" << std::endl;
|
||||
|
||||
@@ -21,9 +21,11 @@
|
||||
|
||||
#include "float.h"
|
||||
#include "integer.h"
|
||||
#include "type_name.h"
|
||||
|
||||
int main(int, const char**)
|
||||
{
|
||||
float_h();
|
||||
integer_h();
|
||||
type_name_h();
|
||||
}
|
||||
|
||||
107
metaprogramming/type_name.h
Normal file
107
metaprogramming/type_name.h
Normal file
@@ -0,0 +1,107 @@
|
||||
// =====================================================================================================================
|
||||
// fennec, a free and open source game engine
|
||||
// Copyright © 2025 Medusa Slockbower
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
///
|
||||
/// \file type_name.h
|
||||
/// \brief
|
||||
///
|
||||
///
|
||||
/// \details
|
||||
/// \author Medusa Slockbower
|
||||
///
|
||||
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
|
||||
///
|
||||
///
|
||||
|
||||
#ifndef FENNEC_METAPROGRAMMING_TYPE_NAME_H
|
||||
#define FENNEC_METAPROGRAMMING_TYPE_NAME_H
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace fennec::detail
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
inline static const char* f() {
|
||||
return __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inline void type_name_h()
|
||||
{
|
||||
|
||||
std::ofstream out("fennec/rtti/detail/_constants.h");
|
||||
|
||||
out << "// =====================================================================================================================" << std::endl;
|
||||
out << "// fennec, a free and open source game engine" << std::endl;
|
||||
out << "// Copyright © 2025 Medusa Slockbower" << std::endl;
|
||||
out << "//" << std::endl;
|
||||
out << "// This program is free software: you can redistribute it and/or modify" << std::endl;
|
||||
out << "// it under the terms of the GNU General Public License as published by" << std::endl;
|
||||
out << "// the Free Software Foundation, either version 3 of the License, or" << std::endl;
|
||||
out << "// (at your option) any later version." << std::endl;
|
||||
out << "//" << std::endl;
|
||||
out << "// This program is distributed in the hope that it will be useful," << std::endl;
|
||||
out << "// but WITHOUT ANY WARRANTY; without even the implied warranty of" << std::endl;
|
||||
out << "// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" << std::endl;
|
||||
out << "// GNU General Public License for more details." << std::endl;
|
||||
out << "//" << std::endl;
|
||||
out << "// You should have received a copy of the GNU General Public License" << std::endl;
|
||||
out << "// along with this program. If not, see <https://www.gnu.org/licenses/>." << std::endl;
|
||||
out << "// =====================================================================================================================" << std::endl;
|
||||
|
||||
out << "" << std::endl;
|
||||
|
||||
out << "#ifndef FENNEC_RTTI_DETAIL_CONSTANTS_H" << std::endl;
|
||||
out << "#define FENNEC_RTTI_DETAIL_CONSTANTS_H" << std::endl;
|
||||
|
||||
out << "" << std::endl;
|
||||
|
||||
out << "#include <fennec/langcpp/types.h>" << std::endl;
|
||||
|
||||
out << "" << std::endl;
|
||||
|
||||
out << "namespace fennec::detail" << std::endl;
|
||||
out << "{" << std::endl;
|
||||
out << "" << std::endl;
|
||||
|
||||
|
||||
std::string str = fennec::detail::f<void>();
|
||||
size_t heading = str.find("void");
|
||||
size_t footing = str.size() - (heading + 4);
|
||||
|
||||
out << "// " << str << std::endl;
|
||||
out << "inline static constexpr size_t type_name_f_heading = " << heading << ";" << std::endl;
|
||||
out << "inline static constexpr size_t type_name_f_footing = " << footing << ";" << std::endl;
|
||||
|
||||
|
||||
out << "" << std::endl;
|
||||
out << "}" << std::endl;
|
||||
|
||||
out << "" << std::endl;
|
||||
|
||||
out << "#endif // FENNEC_RTTI_DETAIL_CONSTANTS_H" << std::endl;
|
||||
|
||||
out.close();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#endif // FENNEC_METAPROGRAMMING_TYPE_NAME_H
|
||||
Reference in New Issue
Block a user