SRD parser - Access value as a RW reference

This commit is contained in:
Emmanuel BENOîT 2017-11-17 15:44:49 +01:00
parent 1ce16d63cb
commit 5db261909a
2 changed files with 26 additions and 6 deletions

View file

@ -72,11 +72,12 @@ public:
void handleFlushToken( bool handleIt ) noexcept; void handleFlushToken( bool handleIt ) noexcept;
bool handleFlushToken( ) const noexcept; bool handleFlushToken( ) const noexcept;
template< typename T > template< typename T > T const& getData( ) const;
T const& getData( ) const; template< typename T > T& getData( );
private: private:
T_Variant const& getExecStackTop( ) const; T_Variant const& getExecStackTop( ) const noexcept;
T_Variant& getExecStackTop( ) noexcept;
}; };
M_CLASS_POINTERS( SRDParser ); M_CLASS_POINTERS( SRDParser );
@ -87,6 +88,12 @@ inline T const& T_SRDParser::getData( ) const
return getExecStackTop( ).value< T >( ); return getExecStackTop( ).value< T >( );
} }
template< typename T >
inline T& T_SRDParser::getData( )
{
return getExecStackTop( ).value< T >( );
}
} // namespace } // namespace
#endif // _H_EBCL_SRDPARSER #endif // _H_EBCL_SRDPARSER

View file

@ -129,7 +129,8 @@ struct T_SRDParserPrivate_
uint32_t eid ); uint32_t eid );
// Get the data at the top of the execution stack // Get the data at the top of the execution stack
T_Variant const& getExecStackTop( ) const; T_Variant const& getExecStackTop( ) const noexcept;
T_Variant& getExecStackTop( ) noexcept;
// Public methods // Public methods
void start( T_SRDErrors & errors ); void start( T_SRDErrors & errors );
@ -434,7 +435,14 @@ bool T_SRDParserPrivate_::checkRuleEnd( T_SRDErrors& errors , T_SRDToken const&
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
inline T_Variant const& T_SRDParserPrivate_::getExecStackTop( ) const inline T_Variant const& T_SRDParserPrivate_::getExecStackTop( ) const noexcept
{
assert( execStack_.size( ) != 0 );
const auto stackLast( execStack_.size( ) - 1 );
return execStack_[ stackLast ];
}
inline T_Variant& T_SRDParserPrivate_::getExecStackTop( ) noexcept
{ {
assert( execStack_.size( ) != 0 ); assert( execStack_.size( ) != 0 );
const auto stackLast( execStack_.size( ) - 1 ); const auto stackLast( execStack_.size( ) - 1 );
@ -680,7 +688,12 @@ bool T_SRDParser::handleFlushToken( ) const noexcept
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
T_Variant const& T_SRDParser::getExecStackTop( ) const T_Variant const& T_SRDParser::getExecStackTop( ) const noexcept
{
return p< T_SRDParserPrivate_ >( ).getExecStackTop( );
}
T_Variant& T_SRDParser::getExecStackTop( ) noexcept
{ {
return p< T_SRDParserPrivate_ >( ).getExecStackTop( ); return p< T_SRDParserPrivate_ >( ).getExecStackTop( );
} }