Skip to content

Commit

Permalink
Small cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinH committed Feb 28, 2024
1 parent 1f5675c commit 32bd765
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 54 deletions.
4 changes: 2 additions & 2 deletions include/tao/config/internal/argument_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
#define TAO_CONFIG_INTERNAL_ARGUMENT_TRAITS_HPP

#include <optional>
#include <stdexcept>
#include <string>
#include <string_view>
#include <utility>

#include "forward.hpp"
#include "inner_extensions.hpp"
Expand All @@ -18,8 +20,6 @@

namespace tao::config::internal
{
inline json_t do_inner_extension( state&, pegtl_input_t&, const extension_maps& );

template< typename T >
struct argument_traits
{
Expand Down
8 changes: 4 additions & 4 deletions include/tao/config/internal/extension_maps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace tao::config::internal
{
extension_maps() = delete;

extension_maps( value_extension_map&& inner, member_extension_map&& member, member_extension_map&& value )
extension_maps( inner_extension_map&& inner, outer_extension_map&& member, outer_extension_map&& value )
: inner( std::move( inner ) ),
member( std::move( member ) ),
value( std::move( value ) )
Expand All @@ -28,9 +28,9 @@ namespace tao::config::internal
void operator=( extension_maps&& ) = delete;
void operator=( const extension_maps& ) = delete;

value_extension_map inner;
member_extension_map member;
member_extension_map value;
inner_extension_map inner;
outer_extension_map member;
outer_extension_map value;
};

} // namespace tao::config::internal
Expand Down
8 changes: 4 additions & 4 deletions include/tao/config/internal/extension_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

namespace tao::config::internal
{
using value_extension = std::function< json_t( pegtl_input_t&, state&, const extension_maps& ) >;
using value_extension_map = std::map< std::string, value_extension >;
using inner_extension = std::function< json_t( pegtl_input_t&, state&, const extension_maps& ) >;
using inner_extension_map = std::map< std::string, inner_extension >;

using member_extension = std::function< void( pegtl_input_t&, state&, const extension_maps& ) >;
using member_extension_map = std::map< std::string, member_extension >;
using outer_extension = std::function< void( pegtl_input_t&, state&, const extension_maps& ) >;
using outer_extension_map = std::map< std::string, outer_extension >;

} // namespace tao::config::internal

Expand Down
47 changes: 9 additions & 38 deletions include/tao/config/internal/extension_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ namespace tao::config::internal
return result_traits< std::decay_t< R > >::convert( p, std::forward< R >( r ) );
}

// NOTE: We can't just make wrap() variadic the straightforward way because that would look like
// return convert_result( p, f( argument_traits< std::decay_t< As > >( in, st, em ).convert()... ) );
// and with the order of function parameter evaluation not being defined in C++ that doesn't work.

template< typename R, typename A >
[[nodiscard]] value_extension wrap( R ( *f )( A ) )
[[nodiscard]] inner_extension wrap( R ( *f )( A ) )
{
static_assert( !std::is_pointer_v< R > );
static_assert( !std::is_reference_v< R > );
Expand All @@ -39,7 +43,7 @@ namespace tao::config::internal
}

template< typename R, typename A, typename B >
[[nodiscard]] value_extension wrap( R ( *f )( A, B ) )
[[nodiscard]] inner_extension wrap( R ( *f )( A, B ) )
{
static_assert( !std::is_pointer_v< R > );
static_assert( !std::is_reference_v< R > );
Expand All @@ -53,41 +57,8 @@ namespace tao::config::internal
};
}

template< typename R, typename A, typename B, typename C >
[[nodiscard]] value_extension wrap( R ( *f )( A, B, C ) )
{
static_assert( !std::is_pointer_v< R > );
static_assert( !std::is_reference_v< R > );
static_assert( !std::is_same_v< R, void > );

return [ = ]( pegtl_input_t& in, state& st, const extension_maps& em ) {
const auto p = in.position();
const argument_traits< std::decay_t< A > > a( in, st, em );
const argument_traits< std::decay_t< B > > b( in, st, em );
const argument_traits< std::decay_t< C > > c( in, st, em );
return convert_result( p, f( a.convert(), b.convert(), c.convert() ) );
};
}

template< typename R, typename A, typename B, typename C, typename D >
[[nodiscard]] value_extension wrap( R ( *f )( A, B, C, D ) )
{
static_assert( !std::is_pointer_v< R > );
static_assert( !std::is_reference_v< R > );
static_assert( !std::is_same_v< R, void > );

return [ = ]( pegtl_input_t& in, state& st, const extension_maps& em ) {
const auto p = in.position();
const argument_traits< std::decay_t< A > > a( in, st, em );
const argument_traits< std::decay_t< B > > b( in, st, em );
const argument_traits< std::decay_t< C > > c( in, st, em );
const argument_traits< std::decay_t< D > > d( in, st, em );
return convert_result( p, f( a.convert(), b.convert(), c.convert(), d.convert() ) );
};
}

template< typename A, typename B >
[[nodiscard]] member_extension wrap( void ( *f )( A, B ) )
[[nodiscard]] outer_extension wrap( void ( *f )( A, B ) )
{
return [ = ]( pegtl_input_t& in, state& st, const extension_maps& em ) {
const argument_traits< std::decay_t< A > > a( in, st, em );
Expand All @@ -97,7 +68,7 @@ namespace tao::config::internal
}

template< typename A, typename B, typename C >
[[nodiscard]] member_extension wrap( void ( *f )( A, B, C ) )
[[nodiscard]] outer_extension wrap( void ( *f )( A, B, C ) )
{
return [ = ]( pegtl_input_t& in, state& st, const extension_maps& em ) {
const argument_traits< std::decay_t< A > > a( in, st, em );
Expand All @@ -108,7 +79,7 @@ namespace tao::config::internal
}

template< typename A, typename B, typename C, typename D >
[[nodiscard]] member_extension wrap( void ( *f )( A, B, C, D ) )
[[nodiscard]] outer_extension wrap( void ( *f )( A, B, C, D ) )
{
return [ = ]( pegtl_input_t& in, state& st, const extension_maps& em ) {
const argument_traits< std::decay_t< A > > a( in, st, em );
Expand Down
2 changes: 0 additions & 2 deletions include/tao/config/internal/inner_extensions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

namespace tao::config::internal
{
[[nodiscard]] inline const value_extension_map& the_inner_extension_map();

[[nodiscard]] inline json_t do_inner_extension( pegtl_input_t& in, state& st, const extension_maps& em )
{
if( parse_open( in ) ) {
Expand Down
2 changes: 0 additions & 2 deletions include/tao/config/internal/member_extensions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace tao::config::internal
{
[[nodiscard]] inline const member_extension_map& the_member_extension_map();

[[nodiscard]] inline bool do_member_extension( pegtl_input_t& in, state& st, const extension_maps& em )
{
const std::string name = parse_extension( in );
Expand Down
2 changes: 1 addition & 1 deletion include/tao/config/internal/member_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace tao::config::internal
}
catch( const std::system_error& e ) {
if( e.code().value() != ENOENT ) {
throw pegtl::parse_error( "include error -- file not found", p );
throw pegtl::parse_error( "include error", p );
// throw pegtl::parse_error( format( __FILE__, __LINE__, "include failed", { { "filename", f }, { "error", e.what() }, { "errno", e.code().value() } } ), pos );
}
}
Expand Down
1 change: 1 addition & 0 deletions include/tao/config/internal/reference2_part.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace tao::config::internal
{
struct reference2_part;

[[nodiscard]] inline std::string to_string( const std::vector< reference2_part >& );

struct reference2_part
Expand Down
2 changes: 1 addition & 1 deletion include/tao/config/internal/value_extensions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#ifndef TAO_CONFIG_INTERNAL_VALUE_EXTENSIONS_HPP
#define TAO_CONFIG_INTERNAL_VALUE_EXTENSIONS_HPP

#include <sstream>
#include <string>

#include "concat.hpp"
#include "config_action.hpp"
Expand Down

0 comments on commit 32bd765

Please sign in to comment.