├── .gitmodules ├── docs ├── faq.md ├── customization.md ├── extending.md ├── ci │ ├── test.md │ └── benchmark.md ├── example.dox ├── github-corner.css └── templates │ └── footer.html ├── examples ├── test.cpp └── simple.cpp ├── tools ├── __init__.py ├── requirements.txt ├── pyproject.toml ├── diagnostics.py ├── codegen.py ├── docs.py └── amalgamate.py ├── test ├── unittest │ ├── name │ │ ├── rtti.cpp │ │ ├── CMakeLists.txt │ │ ├── member_names.cpp │ │ └── demangle.cpp │ ├── visitors │ │ ├── cpp.cpp │ │ ├── layout.cpp │ │ ├── python.cpp │ │ ├── CMakeLists.txt │ │ └── repr.cpp │ ├── reflection │ │ ├── CMakeLists.txt │ │ └── arity.cpp │ ├── ctvi │ │ ├── CMakeLists.txt │ │ └── ctvi.cpp │ ├── util │ │ ├── CMakeLists.txt │ │ ├── reftuple.cpp │ │ └── tuple.cpp │ ├── enum │ │ ├── CMakeLists.txt │ │ ├── range_list.cpp │ │ ├── util.cpp │ │ ├── range.cpp │ │ ├── reflect.cpp │ │ ├── search.cpp │ │ ├── rangify.cpp │ │ ├── search_range.cpp │ │ └── test_enums.h │ ├── layout │ │ ├── CMakeLists.txt │ │ ├── fallback.cpp │ │ ├── pair.cpp │ │ ├── enum.cpp │ │ ├── pointer.cpp │ │ ├── initializer_list.cpp │ │ ├── aggregate.cpp │ │ └── fundamental.cpp │ ├── repr │ │ ├── CMakeLists.txt │ │ ├── fallback.cpp │ │ ├── enum.cpp │ │ ├── variant.cpp │ │ ├── pair.cpp │ │ ├── initializer_list.cpp │ │ ├── pointer.cpp │ │ ├── aggregate.cpp │ │ ├── customization.cpp │ │ └── fundamental.cpp │ ├── main.cpp │ ├── CMakeLists.txt │ └── warnings.cmake ├── diagnostics │ ├── eval.h │ ├── settings.em │ └── ctei │ │ └── enum_conversion.cpp └── packaging │ ├── CMakeLists.txt │ ├── src │ └── example.cpp │ └── conanfile.py ├── benchmark ├── runtime │ ├── util │ │ ├── CMakeLists.txt │ │ └── string_buffer.cpp │ ├── CMakeLists.txt │ └── main.cpp └── compiletime │ └── enum │ ├── names.cpp │ └── profiles.toml ├── .gitattributes ├── include ├── librepr │ ├── feature.h │ ├── repr │ │ ├── all.h │ │ ├── ctvi.h │ │ ├── fallback.h │ │ ├── pointer.h │ │ ├── enum.h │ │ └── fundamental.h │ ├── util │ │ ├── overload.h │ │ ├── string │ │ │ ├── util.h │ │ │ ├── const_string.h │ │ │ └── buffer.h │ │ ├── collections │ │ │ ├── pack_generated.h.in │ │ │ ├── tuple.h │ │ │ ├── reftuple.h │ │ │ ├── pack.h │ │ │ └── list.h │ │ ├── util.h │ │ └── concepts.h │ ├── customization.h │ ├── reflection │ │ ├── detail │ │ │ ├── to_reftuple.h │ │ │ ├── visit_aggregate.h.in │ │ │ ├── to_tuple.h │ │ │ └── arity.h │ │ ├── enum.h │ │ ├── reflect.h │ │ ├── init_list.h │ │ ├── pair.h │ │ ├── custom.h │ │ ├── array.h │ │ ├── variant.h │ │ ├── aggregate.h │ │ └── category.h │ ├── visit.h │ ├── macro │ │ ├── format.h │ │ ├── warning.h │ │ ├── default.h │ │ ├── platform.h │ │ ├── assert.h │ │ └── util.h │ ├── options.h │ ├── name │ │ ├── rtti.h │ │ ├── ctti.h │ │ ├── demangle.h │ │ ├── detail │ │ │ ├── undecorate.h │ │ │ └── undname.h │ │ ├── type.h │ │ └── member.h │ ├── terminal.h │ ├── literal.h │ ├── customization │ │ ├── enum.h │ │ ├── reflection.h │ │ └── members.h │ ├── type_info.h │ ├── enum │ │ ├── reflect.h │ │ ├── range.h │ │ ├── range_list.h │ │ ├── accessor.h │ │ └── util.h │ ├── ctvi │ │ └── ctvi.h │ └── visitors │ │ ├── layout.h │ │ ├── repr.h │ │ ├── cpp.h │ │ └── python.h └── repr ├── .project ├── .gitignore ├── sonar-project.properties ├── .clang-format ├── .editorconfig ├── .clang-tidy ├── palgen.toml ├── LICENSE ├── conanfile.py ├── CMakeLists.txt └── README.md /.gitmodules: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/faq.md: -------------------------------------------------------------------------------- 1 | # FAQ -------------------------------------------------------------------------------- /examples/test.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tools/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/unittest/name/rtti.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/unittest/visitors/cpp.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/unittest/visitors/layout.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/unittest/visitors/python.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/customization.md: -------------------------------------------------------------------------------- 1 | # Customization -------------------------------------------------------------------------------- /docs/extending.md: -------------------------------------------------------------------------------- 1 | # Extending 2 | 3 | -------------------------------------------------------------------------------- /docs/ci/test.md: -------------------------------------------------------------------------------- 1 | # Test Results {#CI_Test} 2 | 3 | TODO -------------------------------------------------------------------------------- /test/unittest/reflection/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(repr_test PRIVATE arity.cpp) -------------------------------------------------------------------------------- /test/unittest/visitors/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(repr_test PRIVATE repr.cpp) -------------------------------------------------------------------------------- /test/unittest/ctvi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(repr_test PRIVATE 2 | ctvi.cpp 3 | ) -------------------------------------------------------------------------------- /tools/requirements.txt: -------------------------------------------------------------------------------- 1 | jmespath>=1.0.1 2 | empy>=4.0.1 3 | GitPython>=3.1.41 4 | diagtest>=0.1 -------------------------------------------------------------------------------- /benchmark/runtime/util/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(repr_benchmark PRIVATE 2 | string_buffer.cpp 3 | ) -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.h linguist-language=cpp 2 | include/repr linguist-language=cpp 3 | 4 | * text=auto eol=lf 5 | -------------------------------------------------------------------------------- /benchmark/runtime/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(repr_benchmark PRIVATE main.cpp) 2 | add_subdirectory(util) 3 | -------------------------------------------------------------------------------- /include/librepr/feature.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #define USING($operation) ((1 $operation 1) != 0) 3 | 4 | #define ON + 5 | #define OFF - 6 | 7 | -------------------------------------------------------------------------------- /test/unittest/name/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(repr_test PRIVATE 2 | demangle.cpp 3 | rtti.cpp 4 | member_names.cpp 5 | ) -------------------------------------------------------------------------------- /test/unittest/util/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(repr_test PRIVATE 2 | type_list.cpp 3 | tuple.cpp 4 | reftuple.cpp 5 | ) -------------------------------------------------------------------------------- /docs/example.dox: -------------------------------------------------------------------------------- 1 | /** 2 | @example simple.cpp 3 | @section simple_example Simple Example 4 | 5 | Simple example showcasing type and value serialization. 6 | */ -------------------------------------------------------------------------------- /include/librepr/repr/all.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "fundamental.h" 4 | #include "pointer.h" 5 | #include "enum.h" 6 | #include "fallback.h" 7 | #include "ctvi.h" -------------------------------------------------------------------------------- /docs/github-corner.css: -------------------------------------------------------------------------------- 1 | .github-corner svg { 2 | fill: var(--primary-light-color); 3 | color: var(--page-background-color); 4 | width: 72px; 5 | height: 72px; 6 | } 7 | -------------------------------------------------------------------------------- /test/diagnostics/eval.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | template 4 | void eval(); 5 | 6 | template 7 | void eval(); 8 | 9 | #define $eval(...) static_assert(&eval<__VA_ARGS__>) -------------------------------------------------------------------------------- /include/librepr/repr/ctvi.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace librepr { 5 | 6 | template 7 | constexpr inline auto reprof = ctvi::value; 8 | 9 | } // namespace librepr -------------------------------------------------------------------------------- /benchmark/compiletime/enum/names.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | enum class Foo : unsigned { a = 10, c = 11, b = 100 }; 4 | 5 | int main() { 6 | (void)librepr::enum_names().size(); 7 | (void)librepr::enum_name(Foo{10}); 8 | } -------------------------------------------------------------------------------- /test/unittest/enum/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(repr_test PRIVATE 2 | range_list.cpp 3 | range.cpp 4 | rangify.cpp 5 | reflect.cpp 6 | search_range.cpp 7 | search.cpp 8 | util.cpp 9 | ) -------------------------------------------------------------------------------- /test/packaging/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | project(PackageTest CXX) 3 | 4 | find_package(repr CONFIG REQUIRED) 5 | 6 | add_executable(example src/example.cpp) 7 | 8 | target_link_libraries(example PRIVATE repr::repr) -------------------------------------------------------------------------------- /test/unittest/layout/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(repr_test PRIVATE 2 | fallback.cpp 3 | fundamental.cpp 4 | pointer.cpp 5 | initializer_list.cpp 6 | pair.cpp 7 | aggregate.cpp 8 | enum.cpp 9 | ) -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | repr 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/unittest/repr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(repr_test PRIVATE 2 | fallback.cpp 3 | fundamental.cpp 4 | pointer.cpp 5 | initializer_list.cpp 6 | pair.cpp 7 | #customization.cpp 8 | aggregate.cpp 9 | enum.cpp 10 | variant.cpp 11 | ) -------------------------------------------------------------------------------- /test/packaging/src/example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() { 6 | auto str = repr(nullptr); 7 | std::cout << "repr(nullptr) = " << str << '\n'; 8 | std::cout << std::boolalpha << "Using fmt: " << USING(REPR_FORMAT_FMT); 9 | } -------------------------------------------------------------------------------- /test/unittest/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | TEST(Dummy, AlwaysPasses) { 6 | EXPECT_TRUE(true); 7 | } 8 | 9 | int main(int argc, char** argv) { 10 | testing::InitGoogleTest(&argc, argv); 11 | return RUN_ALL_TESTS(); 12 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/build/ 2 | venv/ 3 | .venv/ 4 | .vscode/ 5 | .vsconan/ 6 | .vs/ 7 | .cache/ 8 | .trunk/ 9 | **/.idea 10 | **/CMakeUserPresets.json 11 | compile_commands.json 12 | **.pyc 13 | benchmark/output 14 | benchmark/**/*.json 15 | **.o 16 | **.out 17 | **/scratchpad.* 18 | -------------------------------------------------------------------------------- /test/unittest/ctvi/ctvi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | TEST(ctvi, fundamental) { 5 | EXPECT_EQ(librepr::ctvi::value<1>.to_sv(), "1"); 6 | EXPECT_EQ(librepr::ctvi::value.to_sv(), "nullptr"); 7 | EXPECT_EQ(librepr::ctvi::value<'c'>.to_sv(), "'c'"); 8 | } -------------------------------------------------------------------------------- /include/librepr/util/overload.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace librepr::detail { 4 | 5 | template 6 | struct Overload : Fs... { 7 | using Fs::operator()...; 8 | }; 9 | 10 | template 11 | Overload(Fs...) -> Overload; 12 | 13 | } // namespace librepr::detail -------------------------------------------------------------------------------- /test/diagnostics/settings.em: -------------------------------------------------------------------------------- 1 | @include_path(".") 2 | @include_path("../../include") 3 | 4 | @# finalize - load the compilers 5 | @load_defaults('c++') 6 | 7 | @{ 8 | gcc = GCC(version='>=10.0', dialect='>=20') 9 | clang = Clang(dialect='>=20') 10 | clang16 = Clang(dialect='>=20', version='>=16') 11 | }@ -------------------------------------------------------------------------------- /test/unittest/layout/fallback.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct Unreprable{ 6 | explicit Unreprable() = default; 7 | }; 8 | 9 | TEST(layout, fallback) { 10 | EXPECT_EQ(librepr::layout_of(), "Unreprable"); 11 | } -------------------------------------------------------------------------------- /benchmark/runtime/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char** argv) { 4 | ::benchmark::Initialize(&argc, argv); 5 | if (::benchmark::ReportUnrecognizedArguments(argc, argv)) return 1; 6 | ::benchmark::RunSpecifiedBenchmarks(); 7 | ::benchmark::Shutdown(); 8 | return 0; 9 | } -------------------------------------------------------------------------------- /test/unittest/repr/fallback.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct Unreprable{ 6 | explicit Unreprable() = default; 7 | }; 8 | 9 | TEST(fallback, unreprable) { 10 | using ::testing::StartsWith; 11 | EXPECT_THAT(repr(Unreprable{}), StartsWith("Unreprable object at")); 12 | } -------------------------------------------------------------------------------- /include/librepr/repr/fallback.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace librepr { 6 | 7 | template 8 | std::string repr(T const& obj){ 9 | // Fallback for when we couldn't find a suitable repr 10 | return REPR_FORMAT(" object at {:p}", static_cast(&obj)); 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /test/unittest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(repr_test PRIVATE main.cpp) 2 | 3 | add_subdirectory(util) 4 | add_subdirectory(repr) 5 | add_subdirectory(name) 6 | add_subdirectory(layout) 7 | add_subdirectory(reflection) 8 | add_subdirectory(visitors) 9 | add_subdirectory(enum) 10 | add_subdirectory(ctvi) 11 | 12 | include(warnings.cmake) 13 | #enable_warnings(repr_test) -------------------------------------------------------------------------------- /test/unittest/repr/enum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | enum UnscopedEnum { 5 | FIRST = 1, 6 | SECOND = 2 7 | }; 8 | 9 | enum class ScopedEnum { 10 | FIRST = 1, 11 | SECOND = 2 12 | }; 13 | 14 | TEST(repr, enum) { 15 | EXPECT_EQ(repr(UnscopedEnum::FIRST), "FIRST"); 16 | EXPECT_EQ(repr(ScopedEnum::FIRST), "ScopedEnum::FIRST"); 17 | } -------------------------------------------------------------------------------- /test/unittest/layout/pair.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | TEST(layout, pair) { 5 | using pair = std::pair; 6 | using pair_of_pairs = std::pair, std::pair>; 7 | EXPECT_EQ(librepr::layout_of(), "{int, int}"); 8 | EXPECT_EQ(librepr::layout_of(), "{{int, int}, {int, int}}"); 9 | } 10 | -------------------------------------------------------------------------------- /test/unittest/repr/variant.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | TEST(repr, variant) { 6 | auto fundamental = std::variant{42U}; 7 | EXPECT_EQ(repr(fundamental), "std::variant{42U}"); 8 | fundamental = 4.21F; 9 | EXPECT_EQ(repr(fundamental), "std::variant{4.21F}"); 10 | } -------------------------------------------------------------------------------- /test/unittest/layout/enum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | enum UnscopedEnum { 5 | FIRST = 1, 6 | SECOND = 2 7 | }; 8 | 9 | enum class ScopedEnum { 10 | FIRST = 1, 11 | SECOND = 2 12 | }; 13 | 14 | TEST(layout, enum) { 15 | EXPECT_EQ(librepr::layout_of(), "FIRST | SECOND"); 16 | EXPECT_EQ(librepr::layout_of(), "ScopedEnum::FIRST | ScopedEnum::SECOND"); 17 | } -------------------------------------------------------------------------------- /include/librepr/repr/pointer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | 6 | namespace librepr { 7 | inline std::string repr(std::nullptr_t) { 8 | return "nullptr"; 9 | } 10 | 11 | inline std::string repr(char const* obj) { 12 | return REPR_FORMAT("\"{}\"", obj); 13 | } 14 | 15 | inline std::string repr(void const* obj){ 16 | return REPR_FORMAT("{}", obj); 17 | } 18 | 19 | } // namespace librepr 20 | -------------------------------------------------------------------------------- /test/unittest/layout/pointer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | TEST(layout, nullptr){ 5 | // TODO this is not nice 6 | EXPECT_EQ(librepr::layout_of(), "decltype(nullptr)"); 7 | } 8 | 9 | struct Test {}; 10 | TEST(layout, pointer) { 11 | EXPECT_EQ(librepr::layout_of(), "int*"); 12 | EXPECT_EQ(librepr::layout_of(), "void*"); 13 | EXPECT_EQ(librepr::layout_of(), "testing::Test*"); 14 | } -------------------------------------------------------------------------------- /include/librepr/customization.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace librepr { 6 | 7 | /** This class is used to control a lot of librepr's behavior. 8 | * Please refer to @ref md_docs_2customization for an overview of how this can be used. 9 | * @tparam T Type to control behavior for. 10 | */ 11 | template 12 | struct Settings; 13 | 14 | } // namespace librepr 15 | -------------------------------------------------------------------------------- /include/librepr/reflection/detail/to_reftuple.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include "visit_aggregate.h" 8 | 9 | namespace librepr::detail { 10 | template 11 | requires(std::is_aggregate_v> && !std::is_array_v>) 12 | auto to_reftuple(T&& object){ 13 | return visit_aggregate(make_reftuple, std::forward(object)); 14 | } 15 | } -------------------------------------------------------------------------------- /include/librepr/visit.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | namespace librepr { 8 | template 9 | void visit(V&& visitor) { 10 | visitor(Reflect{}); 11 | } 12 | 13 | template 14 | void visit(V&& visitor, T&& obj) { 15 | using descend = Reflect>; 16 | visitor(category::Value{obj}); 17 | } 18 | } // namespace librepr -------------------------------------------------------------------------------- /examples/simple.cpp: -------------------------------------------------------------------------------- 1 | //* c++ gsnapshot -std=c++20 -O3 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | struct CustomType { 8 | char foo; 9 | unsigned bar; 10 | std::variant oof; 11 | std::unordered_map zoinks; 12 | }; 13 | 14 | int main() { 15 | auto object = CustomType{'f', 42U, true, {{1, 2}, {3, 4}}}; 16 | std::cout << "Object: " << repr(object) << '\n'; 17 | std::cout << "Type: " << librepr::code_for(); 18 | } 19 | -------------------------------------------------------------------------------- /test/unittest/layout/initializer_list.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | TEST(layout, containers) { 5 | EXPECT_EQ(librepr::layout_of(), "str[5]"); 6 | EXPECT_EQ(librepr::layout_of(), "int[5]"); 7 | // EXPECT_EQ(librepr::layout_of(), "str []"); //! TODO 8 | EXPECT_EQ(librepr::layout_of(), "int []"); 9 | EXPECT_EQ(librepr::layout_of>(), "[int]"); 10 | EXPECT_EQ((librepr::layout_of>()), "[int -> int]"); 11 | } 12 | -------------------------------------------------------------------------------- /test/unittest/repr/pair.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | TEST(pair, pair) { 5 | EXPECT_EQ(repr(std::pair{1, 2}), "std::pair{1, 2}"); 6 | auto const foo = std::pair{1, 2}; 7 | EXPECT_EQ(repr(foo), "std::pair{1, 2}"); 8 | } 9 | 10 | TEST(pair, pair_of_pairs) { 11 | auto obj = std::pair, std::pair>{{1, '2'}, {'3', 4}}; 12 | EXPECT_EQ(repr(obj), "std::pair, std::pair>{{1, '2'}, {'3', 4}}"); 13 | } -------------------------------------------------------------------------------- /sonar-project.properties: -------------------------------------------------------------------------------- 1 | sonar.projectKey=Tsche_repr 2 | sonar.organization=tsche 3 | sonar.sources=include/, test/ 4 | 5 | sonar.issue.ignore.allfile=a1,a2 6 | sonar.issue.ignore.allfile.a1.fileRegexp='^#include.*gtest\.h[>"]$' 7 | sonar.issue.ignore.allfile.a2.fileRegexp='^#include.*gmock\.h[>"]$' 8 | 9 | sonar.coverage.exclusions=test/** 10 | sonar.exclusions=**.py,**/detail/to_tuple.h 11 | 12 | sonar.c.file.suffixes=- 13 | sonar.cpp.file.suffixes=.cc,.cpp,.cxx,.c++,.hh,.hpp,.hxx,.h++,.ipp,.h 14 | sonar.cfamily.cpp23.enabled=true -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | ColumnLimit: 120 2 | BasedOnStyle: Chromium 3 | IndentWidth: 2 4 | AccessModifierOffset: -2 5 | 6 | AlignConsecutiveAssignments: true 7 | 8 | AllowAllConstructorInitializersOnNextLine: false 9 | AllowAllParametersOfDeclarationOnNextLine: false 10 | AllowAllArgumentsOnNextLine: false 11 | 12 | ConstructorInitializerAllOnOneLineOrOnePerLine: true 13 | 14 | AllowShortBlocksOnASingleLine: true 15 | 16 | SortIncludes: false 17 | 18 | # Available starting from clang_format 18 19 | # AllowShortCompoundRequirementOnASingleLine: true 20 | -------------------------------------------------------------------------------- /include/librepr/macro/format.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "util.h" 4 | 5 | #ifndef REPR_FORMAT_FMT 6 | #define REPR_FORMAT_FMT OFF 7 | #endif 8 | 9 | #if !__has_include() || __has_include() 10 | #undef REPR_FORMAT_FMT 11 | #define REPR_FORMAT_FMT ON 12 | #endif 13 | 14 | #if USING(REPR_FORMAT_FMT) 15 | #include 16 | #define REPR_FORMAT_RNS fmt 17 | #else 18 | #include 19 | #define REPR_FORMAT_RNS std 20 | #endif 21 | 22 | #define REPR_FORMAT_NS ::REPR_FORMAT_RNS 23 | #define REPR_FORMAT(...) ::REPR_FORMAT_RNS::format(__VA_ARGS__) -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Rules in this file were initially inferred by Visual Studio IntelliCode from the Y:\che\palliate codebase based on best match to current usage at 16/01/2022 2 | # You can modify the rules from these initially generated values to suit your own policies 3 | # You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference 4 | 5 | root = true 6 | 7 | [*] 8 | indent_style = space 9 | indent_size = 2 10 | charset = utf-8 11 | end_of_line = lf 12 | 13 | [*.py] 14 | indent_style = space 15 | indent_size = 4 16 | charset = utf-8 17 | end_of_line = lf -------------------------------------------------------------------------------- /include/librepr/options.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include 5 | 6 | namespace librepr { 7 | struct Options { 8 | enum Source { RTTI, CTTI, SOURCE_LOCATION }; 9 | 10 | bool print_type = true; 11 | bool explicit_types = false; 12 | Source name_source = RTTI; 13 | std::size_t indent = 0; 14 | std::size_t max_width = librepr::get_terminal_width(); 15 | 16 | [[nodiscard]] bool should_print_type(std::size_t level) const { 17 | if (level == 0) { 18 | return print_type; 19 | } 20 | return explicit_types; 21 | } 22 | }; 23 | } // namespace librepr -------------------------------------------------------------------------------- /test/unittest/repr/initializer_list.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | TEST(initializer_list, array) { 5 | int integers[] = {1, 2, 3}; //NOLINT 6 | char const* strings[] = {"1", "2", "3"}; //NOLINT 7 | 8 | EXPECT_EQ(repr(integers), "{1, 2, 3}"); 9 | EXPECT_EQ(repr(strings), R"({"1", "2", "3"})"); 10 | } 11 | 12 | TEST(initializer_list, vector) { 13 | EXPECT_EQ(repr(std::vector{1, 2, 3}), "std::vector{1, 2, 3}"); 14 | } 15 | 16 | TEST(initializer_list, map) { 17 | EXPECT_EQ(repr(std::map{{1, 6}, {2, 5}, {3, 4}}), "std::map{{1, 6}, {2, 5}, {3, 4}}"); 18 | } 19 | -------------------------------------------------------------------------------- /include/librepr/name/rtti.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include "demangle.h" 9 | 10 | namespace librepr:: 11 | 12 | #if USING(REPR_RTTI) 13 | inline 14 | #endif 15 | rtti { 16 | 17 | template 18 | std::string get_name_raw() { 19 | #if USING(LIBREPR_PLATFORM_WINDOWS) 20 | auto name = typeid(T).name(); 21 | return librepr::detail::denoise_name(name); 22 | #else 23 | return librepr::demangle(typeid(T).name()); 24 | #endif 25 | } 26 | 27 | } // namespace librepr::rtti 28 | -------------------------------------------------------------------------------- /include/librepr/util/string/util.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace librepr::detail { 7 | template 8 | concept string_like = requires(T& t) { 9 | t.size(); 10 | { t.data() } -> std::convertible_to; 11 | }; 12 | 13 | template 14 | constexpr std::size_t strsize(const char(&)[N]) { 15 | return (N - 1U); 16 | } 17 | 18 | constexpr std::size_t strsize(const char* str) { 19 | return std::char_traits::length(str); 20 | } 21 | 22 | template 23 | constexpr std::size_t strsize(T&& t) { 24 | return t.size(); 25 | } 26 | } // namespace librepr::detail -------------------------------------------------------------------------------- /include/librepr/util/collections/pack_generated.h.in: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | @%max 16 5 | @{ 6 | def type_list(maximum, with_typename = False): 7 | return ', '.join(f"{'typename ' if with_typename else ''}T{idx}" for idx in range(maximum + 1)) 8 | }@ 9 | 10 | namespace librepr::pack { 11 | 12 | template 13 | struct Split; 14 | 15 | @[for N in range(__max__)] 16 | template