Extract Helper for Single Table Record Construction
Use case is table copy for PVTW.
This commit is contained in:
parent
531803eb0a
commit
4d9387ee23
@ -1489,21 +1489,36 @@ struct flat_props {
|
|||||||
static constexpr const char* errmsg() { return ""; }
|
static constexpr const char* errmsg() { return ""; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename T, std::size_t N >
|
template <typename T, std::size_t N>
|
||||||
double flat_get( const DeckRecord& rec ) {
|
double flat_get(const DeckRecord& rec)
|
||||||
if( !flat_props< T, N >::can_default()
|
{
|
||||||
&& rec.getItem( N ).defaultApplied( 0 ) ) {
|
const auto& item = rec.getItem(N);
|
||||||
throw std::invalid_argument( flat_props< T, N >::errmsg() );
|
|
||||||
|
if (item.defaultApplied(0) && !flat_props<T, N>::can_default()) {
|
||||||
|
throw std::invalid_argument {
|
||||||
|
flat_props<T, N>::errmsg()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return rec.getItem( N ).getSIDouble( 0 );
|
return item.getSIDouble(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
template< typename T, std::size_t... Is >
|
template <typename T, std::size_t... Is>
|
||||||
std::vector< T > flat_records( const DeckKeyword& kw, seq< Is... > ) {
|
T flat_get(const DeckRecord& record, seq<Is...>)
|
||||||
std::vector< T > xs;
|
{
|
||||||
for( const auto& record : kw )
|
return { flat_get<T, Is>(record)... };
|
||||||
xs.emplace_back( T { flat_get< T, Is >( record )... } );
|
}
|
||||||
|
|
||||||
|
template <typename T, std::size_t... Is>
|
||||||
|
std::vector<T>
|
||||||
|
flat_records(const DeckKeyword& kw, seq<Is...> s)
|
||||||
|
{
|
||||||
|
auto xs = std::vector<T>{};
|
||||||
|
xs.reserve(kw.size());
|
||||||
|
|
||||||
|
for (const auto& record : kw) {
|
||||||
|
xs.push_back(flat_get<T>(record, s));
|
||||||
|
}
|
||||||
|
|
||||||
return xs;
|
return xs;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user