Skip to content

Commit

Permalink
Merge pull request #17 from fix8mt/dev
Browse files Browse the repository at this point in the history
Dev to Master updating to v1.1.0
  • Loading branch information
dakka authored Sep 10, 2024
2 parents 4f71363 + 871b388 commit f7b22f4
Show file tree
Hide file tree
Showing 12 changed files with 1,751 additions and 772 deletions.
12 changes: 7 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,30 @@ project (conjure_enum
LANGUAGES CXX
HOMEPAGE_URL https://github.com/fix8mt/conjure_enum
DESCRIPTION "Lightweight C++20 enum and typename reflection"
VERSION 1.0.0)
VERSION 1.1.0)

message("${CMAKE_PROJECT_NAME} version ${CMAKE_PROJECT_VERSION}")

# to disable strip:
# cmake -DBUILD_STRIP_EXE=false ..
option(BUILD_STRIP_EXE "enable stripping of non-unittest executables" true)
message("-- Build strip exes: ${BUILD_STRIP_EXE}")
message("-- Build: strip exes ${BUILD_STRIP_EXE}")

# to disable warnings:
# cmake -DBUILD_ALL_WARNINGS=false ..
option(BUILD_ALL_WARNINGS "enable building with all warnings" true)
message("-- Build with all warnings : ${BUILD_ALL_WARNINGS}")
message("-- Build: with all warnings ${BUILD_ALL_WARNINGS}")

# to disable building unit tests:
# cmake -DBUILD_UNITTESTS=false ..
option(BUILD_UNITTESTS "enable building unit tests" true)
message("-- Build unit tests: ${BUILD_UNITTESTS}")
message("-- Build: unit tests ${BUILD_UNITTESTS}")

# to enable clang build profiler:
# cmake -DBUILD_CLANG_PROFILER=true ..
# see examples/cbenchmark.sh
option(BUILD_CLANG_PROFILER "enable clang build profiler" false)
message("-- Build clang profiler: ${BUILD_CLANG_PROFILER}")
message("-- Build: clang profiler ${BUILD_CLANG_PROFILER}")
if(BUILD_CLANG_PROFILER)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-ftime-trace)
Expand Down
733 changes: 611 additions & 122 deletions README.md

Large diffs are not rendered by default.

29 changes: 24 additions & 5 deletions examples/cbenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,35 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//----------------------------------------------------------------------------------------
#include <system_error>
#define FIX8_CONJURE_ENUM_MINIMAL
// CLI msvc build benchmark from your build dir
// call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
// cl /nologo /MD /std:c++latest /Bt+ /I ..\include ..\examples\cbenchmark.cpp|find "c1xx.dll"
//----------------------------------------------------------------------------------------
#define FIX8_CONJURE_ENUM_ALL_OPTIMIZATIONS
#include <fix8/conjure_enum.hpp>

//-----------------------------------------------------------------------------------------
FIX8_CONJURE_ENUM_SET_RANGE_INTS(std::errc, 0, 71)
enum class numbers
{
zero, one, two, three, four,
five, six, seven, eight, nine,
ten, eleven, twelve, thirteen, fourteen,
fifteen, sixteen, seventeen, eighteen, nineteen,
twenty, twenty_one, twenty_two, twenty_three, twenty_four,
twenty_five, twenty_six, twenty_seven, twenty_eight, twenty_nine,
thirty, thirty_one, thirty_two, thirty_three, thirty_four,
thirty_five, thirty_six, thirty_seven, thirty_eight, thirty_nine,
forty, forty_one, forty_two, forty_three, forty_four,
forty_five, forty_six, forty_seven, forty_eight, forty_nine,
fifty, fifty_one, fifty_two, fifty_three, fifty_four,
fifty_five, fifty_six, fifty_seven, fifty_eight, fifty_nine,
sixty, sixty_one, sixty_two, sixty_three
};
FIX8_CONJURE_ENUM_SET_RANGE(numbers::zero, numbers::sixty_three);

int test_conjure_enum(std::errc err)
auto test_conjure_enum(numbers num)
{
return FIX8::conjure_enum<std::errc>::enum_to_string(err).size();
return FIX8::conjure_enum<numbers>::enum_to_string(num).size();
}

int main(void)
Expand Down
31 changes: 31 additions & 0 deletions examples/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#endif

#include <fix8/conjure_enum.hpp>
#include <fix8/conjure_enum_bitset.hpp>
#include <fix8/conjure_type.hpp>

//-----------------------------------------------------------------------------------------
using namespace std::literals::string_view_literals;
Expand All @@ -52,6 +54,24 @@ enum component1 : int { scheme, authority, userinfo, user, password, host, port,
enum class numbers : int { zero, one, two, three, four, five, six, seven, eight, nine };
enum class numbers1 : int { zero1=4, one1=3, two1=2, three1, four1, five1, six1, seven1, eight1, nine1 };

//-----------------------------------------------------------------------------------------
struct foo1
{
int process(component val, int aint) const
{
return aint * static_cast<int>(val);
}
static constexpr auto dd2a
{
std::to_array<std::tuple<component, int (foo1::*)(component, int) const>>
({
{ component::scheme, &foo1::process },
{ component::port, &foo1::process },
{ component::fragment, &foo1::process },
})
};
};

//-----------------------------------------------------------------------------------------
template<typename T>
const std::string demangle() noexcept
Expand All @@ -71,6 +91,7 @@ const std::string demangle() noexcept
return typeid(T).name();
}

//-----------------------------------------------------------------------------------------
int main(void)
{
conjure_enum<component>::for_each_n(3, [](component val, int other) { std::cout << static_cast<int>(val) << ' ' << other << '\n'; }, 200);
Expand Down Expand Up @@ -226,5 +247,15 @@ int main(void)
std::cout << '"' << component::host << '"' << '\n';
std::cout << '"' << component1::host << '"' << '\n';
std::cout << '"' << static_cast<component>(100) << '"' << '\n';

std::cout << std::hash<enum_bitset<numbers>>{}(er) << '\n';

foo1 bar1;
std::cout << conjure_enum<component>::dispatch(component::port, -1, foo1::dd2a, &bar1, 1000) << '\n';

using en = conjure_enum<numbers>;
for (const auto& [ev,str] : {en::front(), en::back()})
std::cout << static_cast<int>(ev) << ' ' << str << '\n';

return 0;
}
6 changes: 3 additions & 3 deletions examples/srcloctest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ int main(int argc, char **argv)
};

bool mkd{}, cpl{true}, hlp{};
std::map<std::string_view, bool&> opts { {"-m",mkd},{"-c",cpl},{"-h",hlp} };
for (int ii{1}; ii < argc; ++ii)
if (auto result{opts.find(std::string_view(argv[ii]))}; result != opts.cend())
const std::map<std::string_view, bool&> opts { {"-m",mkd},{"-c",cpl},{"-h",hlp} };
for (const std::vector<std::string_view> args{argv + 1, argv + argc}; const auto pp : args)
if (auto result{opts.find(pp)}; result != opts.cend())
result->second ^= true;
if (hlp)
{
Expand Down
2 changes: 0 additions & 2 deletions examples/statictest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ int main(void)
{
for(const auto& [a, b] : conjure_enum<component>::entries)
std::cout << conjure_enum<component>::enum_to_int(a) << ' ' << b << '\n';
for(const auto& a : conjure_enum<component>::names)
std::cout << a << '\n';
std::cout << static_cast<int>(conjure_enum<component>::string_to_enum("component::path").value()) << '\n';
std::cout << conjure_enum<component>::get_enum_min_value() << '/' << conjure_enum<component>::get_enum_max_value() << '\n';
return 0;
Expand Down
Loading

0 comments on commit f7b22f4

Please sign in to comment.