Skip to content

Commit

Permalink
fix naming issues in exceptions, fix gcc build
Browse files Browse the repository at this point in the history
  • Loading branch information
deqyra committed Dec 11, 2024
1 parent 89f0393 commit 987ae25
Show file tree
Hide file tree
Showing 16 changed files with 325 additions and 250 deletions.
10 changes: 4 additions & 6 deletions cpptools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set( CPPTOOLS_HEADERS
container/tree/traversal.hpp
container/tree/unsafe_tree.hpp
exception/arg_parse_exception.hpp
exception/error_category.hpp
exception/error_category_t.hpp
exception/exception.hpp
exception/internal_exception.hpp
exception/io_exception.hpp
Expand All @@ -29,6 +29,7 @@ set( CPPTOOLS_HEADERS
math/sine_generator.hpp
thread/interruptible.hpp
thread/worker.hpp
utility/attributes.hpp
utility/bitwise_enum_ops.hpp
utility/clamped_value.hpp
utility/concepts.hpp
Expand Down Expand Up @@ -85,7 +86,8 @@ target_compile_definitions( cpptools_objects
)

target_compile_options( cpptools_objects
INTERFACE $<$<CXX_COMPILER_ID:MSVC>:/wd4068;>
PRIVATE
$<$<CXX_COMPILER_ID:GNU>:-fPIC> # required for the shared lib build on gcc
)

# Usage interface
Expand All @@ -101,10 +103,6 @@ target_compile_definitions( cpptools_interface
INTERFACE CPPTOOLS_ENABLE_DEBUG_MASTER_SWITCH=${CPPTOOLS_ENABLE_DEBUG}
)

target_compile_options( cpptools_interface
INTERFACE $<$<CXX_COMPILER_ID:MSVC>:/wd4068;>
)

# Static library
add_library( cpptools_static STATIC
$<TARGET_OBJECTS:cpptools_objects>
Expand Down
2 changes: 1 addition & 1 deletion cpptools/cli/argument_parsing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct basic_argument {
/// @brief Name of the argument, in short or long form, or both forms
basic_argument_name<Char> name;
/// @brief Whether the argument is required or not
necessity necessity;
cli::necessity necessity;
/// @brief The number of values to be provided immediately after the argument. -1 consumes the rest of the arguments
int value_count;
};
Expand Down
14 changes: 3 additions & 11 deletions cpptools/container/tree/unsafe_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <cpptools/exception/internal_exception.hpp>
#include <cpptools/exception/parameter_exception.hpp>
#include <cpptools/exception/iterator_exception.hpp>
#include <cpptools/utility/attributes.hpp>
#include <cpptools/utility/heterogenous_lookup.hpp>
#include <cpptools/utility/merge_strategy.hpp>
#include <cpptools/utility/detail/allocator.hpp>
Expand Down Expand Up @@ -49,12 +50,8 @@ class unsafe_tree {
using _al_traits = std::allocator_traits<_al_node>;

struct _deleter_t {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-attributes"
/// @brief Allocator
[[no_unique_address]] [[msvc::no_unique_address]]
mutable _al_node _alloc;
#pragma clang diagnostic pop
NO_UNIQUE_ADDR mutable _al_node _alloc;

void operator()(node_t* node) const {
_al_traits::destroy(_alloc, node);
Expand Down Expand Up @@ -151,12 +148,7 @@ class unsafe_tree {
/// @brief View over the const values of the nodes
value_view_t _values;

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-attributes"
/// @brief Allocator for nodes
[[no_unique_address]] [[msvc::no_unique_address]]
_al_node _alloc;
#pragma clang diagnostic pop
NO_UNIQUE_ADDR _al_node _alloc;

/// @brief Deleter
_deleter_t _deleter;
Expand Down
51 changes: 29 additions & 22 deletions cpptools/exception/arg_parse_exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

namespace tools::exception {

class arg_parse_exception : public base_exception {
class arg_parse_exception : public base_exception<error_category_t> {
public:
static constexpr enum error_category error_category = error_category::arg_parse;
enum class ecode {
using error_category_t = tools::exception::error_category_t;
static constexpr error_category_t error_category = error_category_t::arg_parse;

enum class error_code_t {
multiple_params_consume_remaining_args = 0,
multiple_params_with_same_name = 1,
param_with_no_name = 2,
Expand Down Expand Up @@ -53,17 +55,19 @@ class arg_parse_exception : public base_exception {
};

template<>
constexpr std::string_view default_error_message<arg_parse_exception::ecode>(const arg_parse_exception::ecode& code) {
constexpr std::string_view default_error_message<arg_parse_exception::error_code_t>(const arg_parse_exception::error_code_t& code) {
using enum arg_parse_exception::error_code_t;

switch (code) {
case arg_parse_exception::ecode::multiple_params_consume_remaining_args:
case multiple_params_consume_remaining_args:
return "Multiple parameters were specified to consume all remaining arguments";
case arg_parse_exception::ecode::multiple_params_with_same_name:
case multiple_params_with_same_name:
return "Multiple parameters were specified with the same name";
case arg_parse_exception::ecode::param_with_no_name:
case param_with_no_name:
return "A parameter was specified with no name";
case arg_parse_exception::ecode::not_enough_args_supplied:
case not_enough_args_supplied:
return "Not enough arguments were supplied to satisfy a parameter";
case arg_parse_exception::ecode::required_arg_missing:
case required_arg_missing:
return "No argument was found for a parameter specified as required";

default:
Expand All @@ -72,35 +76,38 @@ constexpr std::string_view default_error_message<arg_parse_exception::ecode>(con
}

template<>
constexpr std::string_view to_string<arg_parse_exception::ecode>(const arg_parse_exception::ecode& code) {
constexpr std::string_view to_string<arg_parse_exception::error_code_t>(const arg_parse_exception::error_code_t& code) {
using enum arg_parse_exception::error_code_t;

switch (code) {
case arg_parse_exception::ecode::multiple_params_consume_remaining_args:
case multiple_params_consume_remaining_args:
return "multiple_consume_remaining_args";
case arg_parse_exception::ecode::multiple_params_with_same_name:
case multiple_params_with_same_name:
return "multiple_params_with_same_name";
case arg_parse_exception::ecode::param_with_no_name:
case param_with_no_name:
return "param_with_no_name";
case arg_parse_exception::ecode::not_enough_args_supplied:
case not_enough_args_supplied:
return "not_enough_arguments_supplied";
case arg_parse_exception::ecode::required_arg_missing:
case required_arg_missing:
return "required_arg_missing";

default:
return "???";
}
}

static_assert(concrete_exception<arg_parse_exception>);

namespace arg_parse {
using e = arg_parse_exception::ecode;
using enum arg_parse_exception::error_code_t;

using multiple_consume_remaining_args_error = exception<arg_parse_exception, e::multiple_params_consume_remaining_args>;
using multiple_params_with_same_name_error = exception<arg_parse_exception, e::multiple_params_with_same_name>;
using param_with_no_name_error = exception<arg_parse_exception, e::param_with_no_name>;
using not_enough_arguments_supplied_error = exception<arg_parse_exception, e::not_enough_args_supplied>;
using required_arg_missing_error = exception<arg_parse_exception, e::required_arg_missing>;
using multiple_consume_remaining_args_error = exception<arg_parse_exception, multiple_params_consume_remaining_args>;
using multiple_params_with_same_name_error = exception<arg_parse_exception, multiple_params_with_same_name>;
using param_with_no_name_error = exception<arg_parse_exception, param_with_no_name>;
using not_enough_arguments_supplied_error = exception<arg_parse_exception, not_enough_args_supplied>;
using required_arg_missing_error = exception<arg_parse_exception, required_arg_missing>;
}


} // namespace tools::exception

#endif//CPPTOOLS_EXCEPTION_ARG_PARSE_EXCEPTION_HPP
37 changes: 0 additions & 37 deletions cpptools/exception/error_category.hpp

This file was deleted.

37 changes: 37 additions & 0 deletions cpptools/exception/error_category_t.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef CPPTOOLS_EXCEPTION_ERROR_CATEGORY_T_HPP
#define CPPTOOLS_EXCEPTION_ERROR_CATEGORY_T_HPP

#include <string_view>

#include <cpptools/api.hpp>

namespace tools::exception {

/// @brief cpptools error categories
enum class error_category_t {
unknown = 0,
internal = 1,
parameter = 2,
lookup = 3,
iterator = 4,
io = 5,
arg_parse = 6
};

CPPTOOLS_API inline std::string_view to_string(error_category_t cat) noexcept {
switch (cat) {
case error_category_t::unknown: return "unknown";
case error_category_t::internal: return "internal";
case error_category_t::parameter: return "parameter";
case error_category_t::lookup: return "lookup";
case error_category_t::iterator: return "iterator";
case error_category_t::io: return "io";
case error_category_t::arg_parse: return "arg_parse";

default: return "???";
}
}

} // namespace tools::exception

#endif//CPPTOOLS_EXCEPTION_ERROR_CATEGORY_T_HPP
Loading

0 comments on commit 987ae25

Please sign in to comment.