Skip to content

Commit 1fbe9a1

Browse files
committed
Cleanup.
1 parent 3be84cc commit 1fbe9a1

File tree

7 files changed

+46
-53
lines changed

7 files changed

+46
-53
lines changed

include/tao/config/internal/config_action.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "key1_guard.hpp"
1717
#include "pegtl.hpp"
1818
#include "phase1_append.hpp"
19-
#include "phase1_stuff.hpp"
2019

2120
namespace tao::config::internal
2221
{
@@ -32,7 +31,7 @@ namespace tao::config::internal
3231
static void apply0( State& st, const extension_maps& )
3332
{
3433
const auto f = []( concat& c ) { c.temporary = false; };
35-
phase1_append( st.root, st.prefix + st.suffix, f, true );
34+
phase1_append( st.root, st.prefix + st.suffix, f, phase1_mode::implicit );
3635
}
3736
};
3837

@@ -43,7 +42,7 @@ namespace tao::config::internal
4342
static void apply0( State& st, const extension_maps& )
4443
{
4544
const auto f = []( concat& c ) { c.temporary = true; };
46-
phase1_append( st.root, st.prefix + st.suffix, f, true );
45+
phase1_append( st.root, st.prefix + st.suffix, f, phase1_mode::implicit );
4746
}
4847
};
4948

@@ -54,7 +53,7 @@ namespace tao::config::internal
5453
static void apply0( State& st, const extension_maps& )
5554
{
5655
const auto f = []( concat& c ) { c.concat.clear(); c.remove = true; c.temporary = false; };
57-
phase1_append( st.root, st.prefix + st.suffix, f, true );
56+
phase1_append( st.root, st.prefix + st.suffix, f, phase1_mode::implicit );
5857
}
5958
};
6059

@@ -66,7 +65,7 @@ namespace tao::config::internal
6665
{
6766
const auto p = in.position();
6867
const auto f = [ & ]( concat& c ) { c.back_ensure_kind( entry_kind::array, p ); };
69-
phase1_append( st.root, st.prefix + st.suffix, f, false );
68+
phase1_append( st.root, st.prefix + st.suffix, f, phase1_mode::manifest );
7069
}
7170
};
7271

@@ -78,7 +77,7 @@ namespace tao::config::internal
7877
{
7978
const auto p = in.position();
8079
const auto f = [ & ]( concat& c ) { c.back_ensure_kind( entry_kind::object, p ); };
81-
phase1_append( st.root, st.prefix + st.suffix, f, false );
80+
phase1_append( st.root, st.prefix + st.suffix, f, phase1_mode::manifest );
8281
}
8382
};
8483

include/tao/config/internal/config_grammar.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace tao::config::internal::rules
3535
{
3636
const auto r = parse_reference2( in );
3737
const auto f = [ & ]( concat& c ) { c.concat.emplace_back( r ); };
38-
phase1_append( st.root, st.prefix + st.suffix, f, false );
38+
phase1_append( st.root, st.prefix + st.suffix, f, phase1_mode::manifest );
3939
return true;
4040
}
4141
};
@@ -56,7 +56,7 @@ namespace tao::config::internal::rules
5656
{
5757
const auto j = parse_jaxn( in );
5858
const auto f = [ & ]( concat& c ) { c.concat.emplace_back( j ); };
59-
phase1_append( st.root, st.prefix + st.suffix, f, false );
59+
phase1_append( st.root, st.prefix + st.suffix, f, phase1_mode::manifest );
6060
return true;
6161
}
6262
};

include/tao/config/internal/member_functions.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace tao::config::internal
6262
}
6363
else {
6464
const auto f = [ & ]( concat& c ) { c.schema = s ? ( *s ) : std::string(); };
65-
phase1_append( st.root, st.prefix, f, !s.has_value() );
65+
phase1_append( st.root, st.prefix, f, phase1_mode( !s.has_value() ) );
6666
}
6767
}
6868

include/tao/config/internal/phase1_append.hpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,33 @@
2020
#include "json_traits.hpp"
2121
#include "key1.hpp"
2222
#include "object.hpp"
23-
#include "phase1_stuff.hpp"
23+
#include "phase1_mode.hpp"
2424
#include "reference2.hpp"
2525
#include "reverse.hpp"
2626

2727
namespace tao::config::internal
2828
{
2929
template< typename T >
30-
bool phase1_append( concat& c, const key1& path, const T& thing, const bool implicit );
30+
bool phase1_append( concat& c, const key1& path, const T& thing, const phase1_mode mode );
3131

3232
template< typename T >
33-
bool phase1_append_star( concat& c, const pegtl::position& p, const key1& path, const T& thing, const bool implicit )
33+
bool phase1_append_star( concat& c, const pegtl::position& p, const key1& path, const T& thing, const phase1_mode mode )
3434
{
3535
c.back_ensure_kind( entry_kind::concat, p );
36-
return phase1_append( c.concat.back().get_concat(), path, thing, implicit );
36+
return phase1_append( c.concat.back().get_concat(), path, thing, mode );
3737
}
3838

3939
template< typename T >
40-
bool phase1_append_name( concat& c, const pegtl::position& p, const std::string& name, const key1& path, const T& thing, const bool implicit )
40+
bool phase1_append_name( concat& c, const pegtl::position& p, const std::string& name, const key1& path, const T& thing, const phase1_mode mode )
4141
{
4242
c.back_ensure_kind( entry_kind::object, p );
4343
const auto pair = c.concat.back().get_object().object.try_emplace( name, p );
44-
pair.first->second.implicit = implicit && ( pair.second || pair.first->second.implicit );
45-
return phase1_append( pair.first->second, path, thing, implicit );
44+
pair.first->second.implicit = ( mode == phase1_mode::implicit ) && ( pair.second || pair.first->second.implicit );
45+
return phase1_append( pair.first->second, path, thing, mode );
4646
}
4747

4848
template< typename T >
49-
bool phase1_append_index( concat& c, const pegtl::position& p, const std::size_t index, const key1& path, const T& thing, const bool implicit )
49+
bool phase1_append_index( concat& c, const pegtl::position& p, const std::size_t index, const key1& path, const T& thing, const phase1_mode mode )
5050
{
5151
std::size_t n = index;
5252

@@ -58,7 +58,7 @@ namespace tao::config::internal
5858
throw pegtl::parse_error( "cannot index (across) reference", p );
5959
case entry_kind::array:
6060
if( e.get_array().array.size() > n ) {
61-
return phase1_append( *std::next( e.get_array().array.begin(), n ), path, thing, implicit );
61+
return phase1_append( *std::next( e.get_array().array.begin(), n ), path, thing, mode );
6262
}
6363
n -= e.get_array().array.size();
6464
continue;
@@ -72,23 +72,23 @@ namespace tao::config::internal
7272
}
7373

7474
template< typename T >
75-
bool phase1_append_append( concat& c, const pegtl::position& p, const std::uint64_t g, const key1& path, const T& thing, const bool implicit )
75+
bool phase1_append_append( concat& c, const pegtl::position& p, const std::uint64_t g, const key1& path, const T& thing, const phase1_mode mode )
7676
{
7777
c.back_ensure_kind( entry_kind::array, p );
7878
auto& a = c.concat.back().get_array();
7979
if( g > c.generation ) {
8080
c.generation = g;
8181
concat& d = a.array.emplace_back( p );
8282
d.remove = false; // TODO: Make consistent with entry::expand()?
83-
return phase1_append( d, path, thing, implicit );
83+
return phase1_append( d, path, thing, mode );
8484
}
8585
assert( !a.array.empty() );
8686

87-
return phase1_append( a.array.back(), path, thing, implicit );
87+
return phase1_append( a.array.back(), path, thing, mode );
8888
}
8989

9090
template< typename T >
91-
bool phase1_append( concat& c, const key1& path, const T& thing, const bool implicit )
91+
bool phase1_append( concat& c, const key1& path, const T& thing, const phase1_mode mode )
9292
{
9393
if( path.empty() ) {
9494
thing( c );
@@ -98,26 +98,26 @@ namespace tao::config::internal
9898

9999
switch( part.kind() ) {
100100
case key1_kind::star:
101-
return phase1_append_star( c, part.position, pop_front( path ), thing, implicit );
101+
return phase1_append_star( c, part.position, pop_front( path ), thing, mode );
102102
case key1_kind::name:
103-
return phase1_append_name( c, part.position, part.get_name(), pop_front( path ), thing, implicit );
103+
return phase1_append_name( c, part.position, part.get_name(), pop_front( path ), thing, mode );
104104
case key1_kind::index:
105-
return phase1_append_index( c, part.position, part.get_index(), pop_front( path ), thing, implicit );
105+
return phase1_append_index( c, part.position, part.get_index(), pop_front( path ), thing, mode );
106106
case key1_kind::append:
107-
return phase1_append_append( c, part.position, part.get_generation(), pop_front( path ), thing, implicit );
107+
return phase1_append_append( c, part.position, part.get_generation(), pop_front( path ), thing, mode );
108108
}
109109
throw std::logic_error( "code should be unreachable" ); // LCOV_EXCL_LINE
110110
}
111111

112112
template< typename T >
113-
void phase1_append( object& o, const key1& path, const T& thing, const bool implicit )
113+
void phase1_append( object& o, const key1& path, const T& thing, const phase1_mode mode )
114114
{
115115
assert( !path.empty() );
116116

117117
const std::string& name = path.front().get_name(); // TODO: Error message if other type.
118118
const auto pair = o.object.try_emplace( name, path.front().position );
119-
pair.first->second.implicit = implicit && ( pair.second || pair.first->second.implicit );
120-
phase1_append( pair.first->second, pop_front( path ), thing, implicit );
119+
pair.first->second.implicit = ( mode == phase1_mode::implicit ) && ( pair.second || pair.first->second.implicit );
120+
phase1_append( pair.first->second, pop_front( path ), thing, mode );
121121
}
122122

123123
} // namespace tao::config::internal
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) 2021 Dr. Colin Hirsch and Daniel Frey
2+
// Please see LICENSE for license or visit https://github.com/taocpp/config/
3+
4+
#ifndef TAO_CONFIG_INTERNAL_PHASE1_MODE_HPP
5+
#define TAO_CONFIG_INTERNAL_PHASE1_MODE_HPP
6+
7+
namespace tao::config::internal
8+
{
9+
enum class phase1_mode : bool
10+
{
11+
implicit = true,
12+
manifest = false // Can't use explicit as enum label.
13+
};
14+
15+
} // namespace tao::config::internal
16+
17+
#endif

include/tao/config/internal/phase1_stuff.hpp

Lines changed: 0 additions & 23 deletions
This file was deleted.

include/tao/config/internal/value_extensions.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace tao::config::internal
3636
if( i != em.inner.end() ) {
3737
const auto j = i->second( in, st, em );
3838
const auto f = [ & ]( concat& c ) { c.concat.emplace_back( j ); };
39-
phase1_append( st.root, st.prefix + st.suffix, f, false );
39+
phase1_append( st.root, st.prefix + st.suffix, f, phase1_mode::manifest );
4040
return true;
4141
}
4242
}

0 commit comments

Comments
 (0)