Commit 149cfbec authored by Dominik Charousset's avatar Dominik Charousset

Replace C++ enum code generator with CMake script

parent 52914200
......@@ -25,7 +25,6 @@ option(CAF_ENABLE_CURL_EXAMPLES "Build examples with libcurl" OFF)
option(CAF_ENABLE_PROTOBUF_EXAMPLES "Build examples with Google Protobuf" OFF)
option(CAF_ENABLE_QT6_EXAMPLES "Build examples with the Qt6 framework" OFF)
option(CAF_ENABLE_RUNTIME_CHECKS "Build CAF with extra runtime assertions" OFF)
option(CAF_ENABLE_UTILITY_TARGETS "Include targets like consistency-check" OFF)
option(CAF_ENABLE_ACTOR_PROFILER "Enable experimental profiler API" OFF)
# -- CAF options that are on by default ----------------------------------------
......@@ -204,51 +203,24 @@ if(NOT TARGET uninstall)
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake)
endif()
# -- utility targets -----------------------------------------------------------
if(CAF_ENABLE_UTILITY_TARGETS)
add_executable(caf-generate-enum-strings
EXCLUDE_FROM_ALL
cmake/caf-generate-enum-strings.cpp)
target_link_libraries(caf-generate-enum-strings PRIVATE CAF::internal)
add_custom_target(consistency-check)
add_custom_target(update-enum-strings)
# adds a consistency check that verifies that `cpp_file` is still valid by
# re-generating the file and comparing it to the existing file
function(caf_add_enum_consistency_check hpp_file cpp_file)
set(input "${CMAKE_CURRENT_SOURCE_DIR}/${hpp_file}")
set(file_under_test "${CMAKE_CURRENT_SOURCE_DIR}/${cpp_file}")
set(output "${CMAKE_CURRENT_BINARY_DIR}/check/${cpp_file}")
get_filename_component(output_dir "${output}" DIRECTORY)
file(MAKE_DIRECTORY "${output_dir}")
add_custom_command(OUTPUT "${output}"
COMMAND caf-generate-enum-strings "${input}" "${output}"
DEPENDS caf-generate-enum-strings "${input}")
get_filename_component(target_name "${input}" NAME_WE)
add_custom_target("${target_name}"
COMMAND
"${CMAKE_COMMAND}"
"-Dfile_under_test=${file_under_test}"
"-Dgenerated_file=${output}"
-P "${PROJECT_SOURCE_DIR}/cmake/check-consistency.cmake"
DEPENDS "${output}")
add_dependencies(consistency-check "${target_name}")
add_custom_target("${target_name}-update"
COMMAND
caf-generate-enum-strings
"${input}"
"${file_under_test}"
DEPENDS caf-generate-enum-strings "${input}")
add_dependencies(update-enum-strings "${target_name}-update")
endfunction()
else()
function(caf_add_enum_consistency_check hpp_file cpp_file)
# nop
endfunction()
endif()
# -- utility functions ---------------------------------------------------------
# adds a consistency check that verifies that `cpp_file` is still valid by
# re-generating the file and comparing it to the existing file
function(caf_add_enum_type target enum_name)
string(REPLACE "." "/" path "${enum_name}")
set(hpp_file "${CMAKE_CURRENT_SOURCE_DIR}/caf/${path}.hpp")
set(cpp_file "${CMAKE_CURRENT_BINARY_DIR}/src/${path}_strings.cpp")
add_custom_command(OUTPUT "${cpp_file}"
COMMAND ${CMAKE_COMMAND}
"-DINPUT_FILE=${hpp_file}"
"-DOUTPUT_FILE=${cpp_file}"
-P "${PROJECT_SOURCE_DIR}/cmake/caf-generate-enum-strings.cmake"
DEPENDS "${hpp_file}")
get_filename_component(target_name "${input}" NAME_WE)
target_sources(${target} PRIVATE "${cpp_file}")
endfunction()
function(caf_export_and_install_lib component)
add_library(CAF::${component} ALIAS libcaf_${component})
string(TOUPPER "CAF_${component}_EXPORT" export_macro_name)
......@@ -328,8 +300,7 @@ endfunction()
# ...
# )
function(caf_add_component name)
set(varargs DEPENDENCIES HEADERS SOURCES TEST_SOURCES TEST_SUITES
ENUM_CONSISTENCY_CHECKS)
set(varargs DEPENDENCIES HEADERS SOURCES TEST_SOURCES TEST_SUITES ENUM_TYPES)
cmake_parse_arguments(CAF_ADD_COMPONENT "" "" "${varargs}" ${ARGN})
if(NOT CAF_ADD_COMPONENT_HEADERS)
message(FATAL_ERROR "Cannot add CAF component without at least one header.")
......@@ -372,6 +343,11 @@ function(caf_add_component name)
set_property(TARGET ${pub_lib_target} PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()
target_link_libraries(${pub_lib_target} ${CAF_ADD_COMPONENT_DEPENDENCIES})
if(CAF_ADD_COMPONENT_ENUM_TYPES)
foreach(enum_name ${CAF_ADD_COMPONENT_ENUM_TYPES})
caf_add_enum_type(${obj_lib_target} ${enum_name})
endforeach()
endif()
foreach(target ${targets})
target_compile_definitions(${target} PRIVATE "libcaf_${name}_EXPORTS")
target_include_directories(${target} PRIVATE
......@@ -384,13 +360,6 @@ function(caf_add_component name)
endif()
endforeach()
caf_export_and_install_lib(${name})
if(CAF_ADD_COMPONENT_ENUM_CONSISTENCY_CHECKS)
foreach(enum_name ${CAF_ADD_COMPONENT_ENUM_CONSISTENCY_CHECKS})
string(REPLACE "." "/" path "${enum_name}")
caf_add_enum_consistency_check("caf/${path}.hpp"
"src/${path}_strings.cpp")
endforeach()
endif()
endfunction()
# -- build all components the user asked for -----------------------------------
......
......@@ -167,26 +167,6 @@ pipeline {
runClangFormat(config)
}
}
stage('Check Consistency') {
agent { label 'unix' }
steps {
deleteDir()
unstash('sources')
dir('sources') {
cmakeBuild([
buildDir: 'build',
installation: 'cmake in search path',
sourceDir: '.',
cmakeArgs: '-DCAF_ENABLE_IO_MODULE:BOOL=OFF ' +
'-DCAF_ENABLE_UTILITY_TARGETS:BOOL=ON',
steps: [[
args: '--target consistency-check',
withCmake: true,
]],
])
}
}
}
stage('Build') {
steps {
buildParallel(config)
......
# seeks the beginning of the enum while also keeping track of namespaces
macro(seek_mode)
if(line MATCHES "^namespace ")
string(REGEX REPLACE "^namespace ([a-zA-Z0-9:_]+).*$" "\\1" tmp "${line}")
list(APPEND namespaces "${tmp}")
elseif(line MATCHES "^enum ")
if(NOT namespaces)
message(FATAL_ERROR "enum found outside of a namespace")
endif()
if(line MATCHES "^enum class ")
set(is_enum_class TRUE)
endif()
string(REGEX REPLACE "^enum (class )?([0-9a-zA-Z_]+).*$" "\\2" enum_name "${line}")
set(mode "scan")
endif()
endmacro()
# scans the input for case labels
macro(scan_mode)
if(line MATCHES "^}")
set(mode "generate")
elseif(line MATCHES "^[0-9a-zA-Z_]+")
string(REGEX REPLACE "^([0-9a-zA-Z_]+).*$" "\\1" tmp "${line}")
list(APPEND enum_values "${tmp}")
endif()
endmacro()
macro(write_enum_file)
if(is_enum_class)
set(label_prefix "${enum_name}::")
else()
set(label_prefix "")
endif()
string(REPLACE ";" "::" namespace_str "${namespaces}")
string(REPLACE "::" "/" namespace_path "${namespace_str}")
set(out "")
# File header and includes.
list(APPEND out
"#include \"caf/config.hpp\"\n"
"#include \"caf/string_view.hpp\"\n"
"\n"
"CAF_PUSH_DEPRECATED_WARNING\n"
"\n"
"#include \"${namespace_path}/${enum_name}.hpp\"\n"
"\n"
"#include <string>\n"
"\n"
"namespace ${namespace_str} {\n"
"\n")
# Generate to_string implementation.
list(APPEND out
"std::string to_string(${enum_name} x) {\n"
" switch (x) {\n"
" default:\n"
" return \"???\"\;\n")
foreach(label IN LISTS enum_values)
list(APPEND out
" case ${label_prefix}${label}:\n"
" return \"${namespace_str}::${enum_name}::${label}\"\;\n")
endforeach()
list(APPEND out
" }\n"
"}\n"
"\n")
# Generate from_string implementation.
list(APPEND out
"bool from_string(string_view in, ${enum_name}& out) {\n")
foreach(label IN LISTS enum_values)
list(APPEND out
" if (in == \"${namespace_str}::${enum_name}::${label}\") {\n"
" out = ${label_prefix}${label}\;\n"
" return true\;\n"
" }\n")
endforeach()
list(APPEND out
" return false\;\n"
"}\n"
"\n")
# Generate from_integer implementation.
list(APPEND out
"bool from_integer(std::underlying_type_t<${enum_name}> in,\n"
" ${enum_name}& out) {\n"
" auto result = static_cast<${enum_name}>(in)\;\n"
" switch (result) {\n"
" default:\n"
" return false\;\n")
foreach(label IN LISTS enum_values)
list(APPEND out
" case ${label_prefix}${label}:\n")
endforeach()
list(APPEND out
" out = result\;\n"
" return true\;\n"
" }\n"
"}\n"
"\n")
# File footer.
list(APPEND out
"} // namespace ${namespace_str}\n"
"\n")
file(WRITE "${OUTPUT_FILE}" ${out})
endmacro()
function(main)
set(namespaces "")
set(enum_name "")
set(enum_values "")
set(is_enum_class FALSE)
file(STRINGS "${INPUT_FILE}" lines)
set(mode "seek")
foreach(line IN LISTS lines)
string(REGEX REPLACE "^(.+)(//.*)?" "\\1" line "${line}")
string(STRIP "${line}" line)
if(mode STREQUAL seek)
seek_mode()
elseif(mode STREQUAL scan)
scan_mode()
else()
# reached the end
if(NOT enum_name)
message(FATAL_ERROR "No enum found in input file")
endif()
if(NOT enum_values)
message(FATAL_ERROR "No enum values found for ${enum_name}")
endif()
write_enum_file()
return()
endif()
endforeach()
endfunction()
# - check parameters and run ---------------------------------------------------
if(NOT INPUT_FILE)
message(FATAL_ERROR "Variable INPUT_FILE undefined")
endif()
if(NOT OUTPUT_FILE)
message(FATAL_ERROR "Variable OUTPUT_FILE undefined")
endif()
main()
// This file is part of CAF, the C++ Actor Framework. See the file LICENSE in
// the main distribution directory for license terms and copyright or visit
// https://github.com/actor-framework/actor-framework/blob/master/LICENSE.
#include <algorithm>
#include <cstring>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using std::cerr;
using std::find;
using std::find_if;
using std::string;
using std::vector;
void split(const string& str, const string& separator, vector<string>& dest) {
size_t current, previous = 0;
current = str.find(separator);
while (current != std::string::npos) {
dest.emplace_back(str.substr(previous, current - previous));
previous = current + separator.size();
current = str.find(separator, previous);
}
dest.push_back(str.substr(previous, current - previous));
}
void trim(string& str) {
auto not_space = [](char c) { return isspace(c) == 0; };
str.erase(str.begin(), find_if(str.begin(), str.end(), not_space));
str.erase(find_if(str.rbegin(), str.rend(), not_space).base(), str.end());
}
template <size_t N>
bool starts_with(const string& str, const char (&prefix)[N]) {
return str.compare(0, N - 1, prefix) == 0;
}
template <size_t N>
void drop_prefix(string& str, const char (&prefix)[N]) {
if (str.compare(0, N - 1, prefix) == 0)
str.erase(str.begin(), str.begin() + (N - 1));
}
void keep_alnum(string& str) {
auto not_alnum = [](char c) { return isalnum(c) == 0 && c != '_'; };
str.erase(find_if(str.begin(), str.end(), not_alnum), str.end());
}
int main(int argc, char** argv) {
if (argc != 3) {
cerr << "wrong number of arguments.\n"
<< "usage: " << argv[0] << " input-file output-file\n";
return EXIT_FAILURE;
}
std::ifstream in{argv[1]};
if (!in) {
cerr << "unable to open input file: " << argv[1] << '\n';
return EXIT_FAILURE;
}
vector<string> namespaces;
string enum_name;
string line;
bool is_enum_class = false;
// Locate the beginning of the enum.
for (;;) {
if (!getline(in, line)) {
cerr << "unable to locate enum in file: " << argv[1] << '\n';
return EXIT_FAILURE;
}
trim(line);
if (starts_with(line, "enum ")) {
drop_prefix(line, "enum ");
if (starts_with(line, "class ")) {
is_enum_class = true;
drop_prefix(line, "class ");
}
trim(line);
keep_alnum(line);
enum_name = line;
break;
}
if (starts_with(line, "namespace ")) {
if (line.back() == '{')
line.pop_back();
line.erase(line.begin(), find(line.begin(), line.end(), ' '));
trim(line);
split(line, "::", namespaces);
}
}
// Sanity checking.
if (namespaces.empty()) {
cerr << "enum found outside of a namespace\n";
return EXIT_FAILURE;
}
auto full_namespace = namespaces[0];
for (size_t index = 1; index < namespaces.size(); ++index) {
full_namespace += "::";
full_namespace += namespaces[index];
}
auto full_namespace_prefix = full_namespace + "::";
if (enum_name.empty()) {
cerr << "empty enum name found\n";
return EXIT_FAILURE;
}
std::string case_label_prefix;
if (is_enum_class)
case_label_prefix = enum_name + "::";
// Read until hitting the closing '}'.
std::vector<std::string> enum_values;
for (;;) {
if (!getline(in, line)) {
cerr << "unable to read enum values\n";
return EXIT_FAILURE;
}
trim(line);
if (line.empty())
continue;
if (line[0] == '}')
break;
if (line[0] != '/') {
keep_alnum(line);
enum_values.emplace_back(enum_name + "::" + line);
}
}
// Generate output file.
std::ofstream out{argv[2]};
if (!out) {
cerr << "unable to open output file: " << argv[2] << '\n';
return EXIT_FAILURE;
}
// Print file header.
out << "// clang-format off\n"
<< "// DO NOT EDIT: "
"this file is auto-generated by caf-generate-enum-strings.\n"
"// Run the target update-enum-strings if this file is out of sync.\n"
"#include \"caf/config.hpp\"\n"
"#include \"caf/string_view.hpp\"\n\n"
"CAF_PUSH_DEPRECATED_WARNING\n\n"
<< "#include \"" << namespaces[0];
for (size_t i = 1; i < namespaces.size(); ++i)
out << '/' << namespaces[i];
out << '/' << enum_name << ".hpp\"\n\n"
<< "#include <string>\n\n"
<< "namespace " << full_namespace << " {\n";
out << '\n';
// Generate to_string implementation.
out << "std::string to_string(" << enum_name << " x) {\n"
<< " switch(x) {\n"
<< " default:\n"
<< " return \"???\";\n";
for (auto& val : enum_values)
out << " case " << val << ":\n"
<< " return \"" << full_namespace_prefix << val << "\";\n";
out << " };\n"
<< "}\n\n";
// Generate from_string implementation.
out << "bool from_string(string_view in, " << enum_name << "& out) {\n ";
for (auto& val : enum_values)
out << "if (in == \"" << full_namespace_prefix << val << "\") {\n"
<< " out = " << val << ";\n"
<< " return true;\n"
<< " } else ";
out << "{\n"
<< " return false;\n"
<< " }\n"
<< "}\n\n";
// Generate from_integer implementation.
out << "bool from_integer(std::underlying_type_t<" << enum_name << "> in,\n"
<< " " << enum_name << "& out) {\n"
<< " auto result = static_cast<" << enum_name << ">(in);\n"
<< " switch(result) {\n"
<< " default:\n"
<< " return false;\n";
for (auto& val : enum_values)
out << " case " << val << ":\n";
out << " out = result;\n"
<< " return true;\n"
<< " };\n"
<< "}\n\n";
// Done. Print file footer and exit.
out << "} // namespace " << full_namespace << '\n';
out << "\nCAF_POP_WARNINGS\n";
return EXIT_SUCCESS;
}
......@@ -52,7 +52,7 @@ caf_add_component(
${LIBCAF_CORE_OPTIONAL_DEPENDENCIES}
PRIVATE
CAF::internal
ENUM_CONSISTENCY_CHECKS
ENUM_TYPES
exit_reason
intrusive.inbox_result
intrusive.task_result
......@@ -140,7 +140,6 @@ caf_add_component(
src/error.cpp
src/event_based_actor.cpp
src/execution_unit.cpp
src/exit_reason_strings.cpp
src/forwarding_actor_proxy.cpp
src/group.cpp
src/group_manager.cpp
......@@ -148,9 +147,6 @@ caf_add_component(
src/hash/sha1.cpp
src/inbound_path.cpp
src/init_global_meta_objects.cpp
src/intrusive/inbox_result_strings.cpp
src/intrusive/task_result_strings.cpp
src/invoke_message_result_strings.cpp
src/ipv4_address.cpp
src/ipv4_endpoint.cpp
src/ipv4_subnet.cpp
......@@ -168,11 +164,9 @@ caf_add_component(
src/message.cpp
src/message_builder.cpp
src/message_handler.cpp
src/message_priority_strings.cpp
src/monitorable_actor.cpp
src/node_id.cpp
src/outbound_path.cpp
src/pec_strings.cpp
src/policy/downstream_messages.cpp
src/policy/unprofiled.cpp
src/policy/work_sharing.cpp
......@@ -189,13 +183,11 @@ caf_add_component(
src/scheduler/test_coordinator.cpp
src/scoped_actor.cpp
src/scoped_execution_unit.cpp
src/sec_strings.cpp
src/serializer.cpp
src/settings.cpp
src/skip.cpp
src/stream_aborter.cpp
src/stream_manager.cpp
src/stream_priority_strings.cpp
src/string_algorithms.cpp
src/string_view.cpp
src/telemetry/collector/prometheus.cpp
......
// clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
#include "caf/string_view.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/exit_reason.hpp"
#include <string>
namespace caf {
std::string to_string(exit_reason x) {
switch(x) {
default:
return "???";
case exit_reason::normal:
return "caf::exit_reason::normal";
case exit_reason::unhandled_exception:
return "caf::exit_reason::unhandled_exception";
case exit_reason::unknown:
return "caf::exit_reason::unknown";
case exit_reason::out_of_workers:
return "caf::exit_reason::out_of_workers";
case exit_reason::user_shutdown:
return "caf::exit_reason::user_shutdown";
case exit_reason::kill:
return "caf::exit_reason::kill";
case exit_reason::remote_link_unreachable:
return "caf::exit_reason::remote_link_unreachable";
case exit_reason::unreachable:
return "caf::exit_reason::unreachable";
};
}
bool from_string(string_view in, exit_reason& out) {
if (in == "caf::exit_reason::normal") {
out = exit_reason::normal;
return true;
} else if (in == "caf::exit_reason::unhandled_exception") {
out = exit_reason::unhandled_exception;
return true;
} else if (in == "caf::exit_reason::unknown") {
out = exit_reason::unknown;
return true;
} else if (in == "caf::exit_reason::out_of_workers") {
out = exit_reason::out_of_workers;
return true;
} else if (in == "caf::exit_reason::user_shutdown") {
out = exit_reason::user_shutdown;
return true;
} else if (in == "caf::exit_reason::kill") {
out = exit_reason::kill;
return true;
} else if (in == "caf::exit_reason::remote_link_unreachable") {
out = exit_reason::remote_link_unreachable;
return true;
} else if (in == "caf::exit_reason::unreachable") {
out = exit_reason::unreachable;
return true;
} else {
return false;
}
}
bool from_integer(std::underlying_type_t<exit_reason> in,
exit_reason& out) {
auto result = static_cast<exit_reason>(in);
switch(result) {
default:
return false;
case exit_reason::normal:
case exit_reason::unhandled_exception:
case exit_reason::unknown:
case exit_reason::out_of_workers:
case exit_reason::user_shutdown:
case exit_reason::kill:
case exit_reason::remote_link_unreachable:
case exit_reason::unreachable:
out = result;
return true;
};
}
} // namespace caf
CAF_POP_WARNINGS
// clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
#include "caf/string_view.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/intrusive/inbox_result.hpp"
#include <string>
namespace caf::intrusive {
std::string to_string(inbox_result x) {
switch(x) {
default:
return "???";
case inbox_result::success:
return "caf::intrusive::inbox_result::success";
case inbox_result::unblocked_reader:
return "caf::intrusive::inbox_result::unblocked_reader";
case inbox_result::queue_closed:
return "caf::intrusive::inbox_result::queue_closed";
};
}
bool from_string(string_view in, inbox_result& out) {
if (in == "caf::intrusive::inbox_result::success") {
out = inbox_result::success;
return true;
} else if (in == "caf::intrusive::inbox_result::unblocked_reader") {
out = inbox_result::unblocked_reader;
return true;
} else if (in == "caf::intrusive::inbox_result::queue_closed") {
out = inbox_result::queue_closed;
return true;
} else {
return false;
}
}
bool from_integer(std::underlying_type_t<inbox_result> in,
inbox_result& out) {
auto result = static_cast<inbox_result>(in);
switch(result) {
default:
return false;
case inbox_result::success:
case inbox_result::unblocked_reader:
case inbox_result::queue_closed:
out = result;
return true;
};
}
} // namespace caf::intrusive
CAF_POP_WARNINGS
// clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
#include "caf/string_view.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/intrusive/task_result.hpp"
#include <string>
namespace caf::intrusive {
std::string to_string(task_result x) {
switch(x) {
default:
return "???";
case task_result::resume:
return "caf::intrusive::task_result::resume";
case task_result::skip:
return "caf::intrusive::task_result::skip";
case task_result::stop:
return "caf::intrusive::task_result::stop";
case task_result::stop_all:
return "caf::intrusive::task_result::stop_all";
};
}
bool from_string(string_view in, task_result& out) {
if (in == "caf::intrusive::task_result::resume") {
out = task_result::resume;
return true;
} else if (in == "caf::intrusive::task_result::skip") {
out = task_result::skip;
return true;
} else if (in == "caf::intrusive::task_result::stop") {
out = task_result::stop;
return true;
} else if (in == "caf::intrusive::task_result::stop_all") {
out = task_result::stop_all;
return true;
} else {
return false;
}
}
bool from_integer(std::underlying_type_t<task_result> in,
task_result& out) {
auto result = static_cast<task_result>(in);
switch(result) {
default:
return false;
case task_result::resume:
case task_result::skip:
case task_result::stop:
case task_result::stop_all:
out = result;
return true;
};
}
} // namespace caf::intrusive
CAF_POP_WARNINGS
// clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
#include "caf/string_view.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/invoke_message_result.hpp"
#include <string>
namespace caf {
std::string to_string(invoke_message_result x) {
switch(x) {
default:
return "???";
case invoke_message_result::consumed:
return "caf::invoke_message_result::consumed";
case invoke_message_result::skipped:
return "caf::invoke_message_result::skipped";
case invoke_message_result::dropped:
return "caf::invoke_message_result::dropped";
};
}
bool from_string(string_view in, invoke_message_result& out) {
if (in == "caf::invoke_message_result::consumed") {
out = invoke_message_result::consumed;
return true;
} else if (in == "caf::invoke_message_result::skipped") {
out = invoke_message_result::skipped;
return true;
} else if (in == "caf::invoke_message_result::dropped") {
out = invoke_message_result::dropped;
return true;
} else {
return false;
}
}
bool from_integer(std::underlying_type_t<invoke_message_result> in,
invoke_message_result& out) {
auto result = static_cast<invoke_message_result>(in);
switch(result) {
default:
return false;
case invoke_message_result::consumed:
case invoke_message_result::skipped:
case invoke_message_result::dropped:
out = result;
return true;
};
}
} // namespace caf
CAF_POP_WARNINGS
// clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
#include "caf/string_view.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/message_priority.hpp"
#include <string>
namespace caf {
std::string to_string(message_priority x) {
switch(x) {
default:
return "???";
case message_priority::high:
return "caf::message_priority::high";
case message_priority::normal:
return "caf::message_priority::normal";
};
}
bool from_string(string_view in, message_priority& out) {
if (in == "caf::message_priority::high") {
out = message_priority::high;
return true;
} else if (in == "caf::message_priority::normal") {
out = message_priority::normal;
return true;
} else {
return false;
}
}
bool from_integer(std::underlying_type_t<message_priority> in,
message_priority& out) {
auto result = static_cast<message_priority>(in);
switch(result) {
default:
return false;
case message_priority::high:
case message_priority::normal:
out = result;
return true;
};
}
} // namespace caf
CAF_POP_WARNINGS
// clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
#include "caf/string_view.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/pec.hpp"
#include <string>
namespace caf {
std::string to_string(pec x) {
switch(x) {
default:
return "???";
case pec::success:
return "caf::pec::success";
case pec::trailing_character:
return "caf::pec::trailing_character";
case pec::unexpected_eof:
return "caf::pec::unexpected_eof";
case pec::unexpected_character:
return "caf::pec::unexpected_character";
case pec::timespan_overflow:
return "caf::pec::timespan_overflow";
case pec::fractional_timespan:
return "caf::pec::fractional_timespan";
case pec::too_many_characters:
return "caf::pec::too_many_characters";
case pec::invalid_escape_sequence:
return "caf::pec::invalid_escape_sequence";
case pec::unexpected_newline:
return "caf::pec::unexpected_newline";
case pec::integer_overflow:
return "caf::pec::integer_overflow";
case pec::integer_underflow:
return "caf::pec::integer_underflow";
case pec::exponent_underflow:
return "caf::pec::exponent_underflow";
case pec::exponent_overflow:
return "caf::pec::exponent_overflow";
case pec::type_mismatch:
return "caf::pec::type_mismatch";
case pec::not_an_option:
return "caf::pec::not_an_option";
case pec::invalid_argument:
return "caf::pec::invalid_argument";
case pec::missing_argument:
return "caf::pec::missing_argument";
case pec::invalid_category:
return "caf::pec::invalid_category";
case pec::invalid_field_name:
return "caf::pec::invalid_field_name";
case pec::repeated_field_name:
return "caf::pec::repeated_field_name";
case pec::missing_field:
return "caf::pec::missing_field";
case pec::invalid_range_expression:
return "caf::pec::invalid_range_expression";
case pec::invalid_state:
return "caf::pec::invalid_state";
};
}
bool from_string(string_view in, pec& out) {
if (in == "caf::pec::success") {
out = pec::success;
return true;
} else if (in == "caf::pec::trailing_character") {
out = pec::trailing_character;
return true;
} else if (in == "caf::pec::unexpected_eof") {
out = pec::unexpected_eof;
return true;
} else if (in == "caf::pec::unexpected_character") {
out = pec::unexpected_character;
return true;
} else if (in == "caf::pec::timespan_overflow") {
out = pec::timespan_overflow;
return true;
} else if (in == "caf::pec::fractional_timespan") {
out = pec::fractional_timespan;
return true;
} else if (in == "caf::pec::too_many_characters") {
out = pec::too_many_characters;
return true;
} else if (in == "caf::pec::invalid_escape_sequence") {
out = pec::invalid_escape_sequence;
return true;
} else if (in == "caf::pec::unexpected_newline") {
out = pec::unexpected_newline;
return true;
} else if (in == "caf::pec::integer_overflow") {
out = pec::integer_overflow;
return true;
} else if (in == "caf::pec::integer_underflow") {
out = pec::integer_underflow;
return true;
} else if (in == "caf::pec::exponent_underflow") {
out = pec::exponent_underflow;
return true;
} else if (in == "caf::pec::exponent_overflow") {
out = pec::exponent_overflow;
return true;
} else if (in == "caf::pec::type_mismatch") {
out = pec::type_mismatch;
return true;
} else if (in == "caf::pec::not_an_option") {
out = pec::not_an_option;
return true;
} else if (in == "caf::pec::invalid_argument") {
out = pec::invalid_argument;
return true;
} else if (in == "caf::pec::missing_argument") {
out = pec::missing_argument;
return true;
} else if (in == "caf::pec::invalid_category") {
out = pec::invalid_category;
return true;
} else if (in == "caf::pec::invalid_field_name") {
out = pec::invalid_field_name;
return true;
} else if (in == "caf::pec::repeated_field_name") {
out = pec::repeated_field_name;
return true;
} else if (in == "caf::pec::missing_field") {
out = pec::missing_field;
return true;
} else if (in == "caf::pec::invalid_range_expression") {
out = pec::invalid_range_expression;
return true;
} else if (in == "caf::pec::invalid_state") {
out = pec::invalid_state;
return true;
} else {
return false;
}
}
bool from_integer(std::underlying_type_t<pec> in,
pec& out) {
auto result = static_cast<pec>(in);
switch(result) {
default:
return false;
case pec::success:
case pec::trailing_character:
case pec::unexpected_eof:
case pec::unexpected_character:
case pec::timespan_overflow:
case pec::fractional_timespan:
case pec::too_many_characters:
case pec::invalid_escape_sequence:
case pec::unexpected_newline:
case pec::integer_overflow:
case pec::integer_underflow:
case pec::exponent_underflow:
case pec::exponent_overflow:
case pec::type_mismatch:
case pec::not_an_option:
case pec::invalid_argument:
case pec::missing_argument:
case pec::invalid_category:
case pec::invalid_field_name:
case pec::repeated_field_name:
case pec::missing_field:
case pec::invalid_range_expression:
case pec::invalid_state:
out = result;
return true;
};
}
} // namespace caf
CAF_POP_WARNINGS
This diff is collapsed.
// clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
#include "caf/string_view.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/stream_priority.hpp"
#include <string>
namespace caf {
std::string to_string(stream_priority x) {
switch(x) {
default:
return "???";
case stream_priority::very_high:
return "caf::stream_priority::very_high";
case stream_priority::high:
return "caf::stream_priority::high";
case stream_priority::normal:
return "caf::stream_priority::normal";
case stream_priority::low:
return "caf::stream_priority::low";
case stream_priority::very_low:
return "caf::stream_priority::very_low";
};
}
bool from_string(string_view in, stream_priority& out) {
if (in == "caf::stream_priority::very_high") {
out = stream_priority::very_high;
return true;
} else if (in == "caf::stream_priority::high") {
out = stream_priority::high;
return true;
} else if (in == "caf::stream_priority::normal") {
out = stream_priority::normal;
return true;
} else if (in == "caf::stream_priority::low") {
out = stream_priority::low;
return true;
} else if (in == "caf::stream_priority::very_low") {
out = stream_priority::very_low;
return true;
} else {
return false;
}
}
bool from_integer(std::underlying_type_t<stream_priority> in,
stream_priority& out) {
auto result = static_cast<stream_priority>(in);
switch(result) {
default:
return false;
case stream_priority::very_high:
case stream_priority::high:
case stream_priority::normal:
case stream_priority::low:
case stream_priority::very_low:
out = result;
return true;
};
}
} // namespace caf
CAF_POP_WARNINGS
......@@ -12,7 +12,7 @@ caf_add_component(
$<$<CXX_COMPILER_ID:MSVC>:ws2_32>
PRIVATE
CAF::internal
ENUM_CONSISTENCY_CHECKS
ENUM_TYPES
io.basp.message_type
io.network.operation
HEADERS
......@@ -25,7 +25,6 @@ caf_add_component(
src/io/basp/header.cpp
src/io/basp/instance.cpp
src/io/basp/message_queue.cpp
src/io/basp/message_type_strings.cpp
src/io/basp/routing_table.cpp
src/io/basp/worker.cpp
src/io/basp_broker.cpp
......@@ -49,7 +48,6 @@ caf_add_component(
src/io/network/manager.cpp
src/io/network/multiplexer.cpp
src/io/network/native_socket.cpp
src/io/network/operation_strings.cpp
src/io/network/pipe_reader.cpp
src/io/network/protocol.cpp
src/io/network/receive_buffer.cpp
......
// clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
#include "caf/string_view.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/io/basp/message_type.hpp"
#include <string>
namespace caf::io::basp {
std::string to_string(message_type x) {
switch(x) {
default:
return "???";
case message_type::server_handshake:
return "caf::io::basp::message_type::server_handshake";
case message_type::client_handshake:
return "caf::io::basp::message_type::client_handshake";
case message_type::direct_message:
return "caf::io::basp::message_type::direct_message";
case message_type::routed_message:
return "caf::io::basp::message_type::routed_message";
case message_type::monitor_message:
return "caf::io::basp::message_type::monitor_message";
case message_type::down_message:
return "caf::io::basp::message_type::down_message";
case message_type::heartbeat:
return "caf::io::basp::message_type::heartbeat";
};
}
bool from_string(string_view in, message_type& out) {
if (in == "caf::io::basp::message_type::server_handshake") {
out = message_type::server_handshake;
return true;
} else if (in == "caf::io::basp::message_type::client_handshake") {
out = message_type::client_handshake;
return true;
} else if (in == "caf::io::basp::message_type::direct_message") {
out = message_type::direct_message;
return true;
} else if (in == "caf::io::basp::message_type::routed_message") {
out = message_type::routed_message;
return true;
} else if (in == "caf::io::basp::message_type::monitor_message") {
out = message_type::monitor_message;
return true;
} else if (in == "caf::io::basp::message_type::down_message") {
out = message_type::down_message;
return true;
} else if (in == "caf::io::basp::message_type::heartbeat") {
out = message_type::heartbeat;
return true;
} else {
return false;
}
}
bool from_integer(std::underlying_type_t<message_type> in,
message_type& out) {
auto result = static_cast<message_type>(in);
switch(result) {
default:
return false;
case message_type::server_handshake:
case message_type::client_handshake:
case message_type::direct_message:
case message_type::routed_message:
case message_type::monitor_message:
case message_type::down_message:
case message_type::heartbeat:
out = result;
return true;
};
}
} // namespace caf::io::basp
CAF_POP_WARNINGS
// clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
#include "caf/string_view.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/io/network/operation.hpp"
#include <string>
namespace caf::io::network {
std::string to_string(operation x) {
switch(x) {
default:
return "???";
case operation::read:
return "caf::io::network::operation::read";
case operation::write:
return "caf::io::network::operation::write";
case operation::propagate_error:
return "caf::io::network::operation::propagate_error";
};
}
bool from_string(string_view in, operation& out) {
if (in == "caf::io::network::operation::read") {
out = operation::read;
return true;
} else if (in == "caf::io::network::operation::write") {
out = operation::write;
return true;
} else if (in == "caf::io::network::operation::propagate_error") {
out = operation::propagate_error;
return true;
} else {
return false;
}
}
bool from_integer(std::underlying_type_t<operation> in,
operation& out) {
auto result = static_cast<operation>(in);
switch(result) {
default:
return false;
case operation::read:
case operation::write:
case operation::propagate_error:
out = result;
return true;
};
}
} // namespace caf::io::network
CAF_POP_WARNINGS
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment