2017-11-01 20:14:23 +01:00
|
|
|
/******************************************************************************/
|
|
|
|
/* SRD - INPUT AND OUTPUT *****************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2017-11-01 23:21:01 +01:00
|
|
|
#ifndef _H_EBCL_SRDIO
|
|
|
|
#define _H_EBCL_SRDIO
|
|
|
|
#include <ebcl/SRDData.hh>
|
2017-12-27 19:00:56 +01:00
|
|
|
#include <ebcl/Streams.hh>
|
2017-11-01 23:21:01 +01:00
|
|
|
namespace ebcl {
|
2017-11-01 20:14:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*= INPUT / OUTPUT ABSTRACTIONS ==============================================*/
|
|
|
|
|
|
|
|
// A_SRDWriter - Abstract SRD writer
|
|
|
|
class A_SRDWriter
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
A_SRDWriter( ) = default;
|
|
|
|
|
|
|
|
public:
|
|
|
|
A_SRDWriter( A_SRDWriter const& ) = delete;
|
|
|
|
A_SRDWriter( A_SRDWriter&& ) = delete;
|
|
|
|
|
|
|
|
virtual ~A_SRDWriter( ) = 0;
|
|
|
|
|
|
|
|
virtual A_SRDWriter& start( ) = 0;
|
|
|
|
|
|
|
|
virtual A_SRDWriter& startList( ) = 0;
|
|
|
|
virtual A_SRDWriter& endList( ) = 0;
|
|
|
|
|
|
|
|
A_SRDWriter& putList( T_SRDList const& list );
|
|
|
|
A_SRDWriter& putToken( T_SRDToken const& token );
|
|
|
|
|
|
|
|
virtual A_SRDWriter& putText( T_String const& text ) = 0;
|
|
|
|
virtual A_SRDWriter& putWord( T_String const& word ) = 0;
|
|
|
|
virtual A_SRDWriter& putString( T_String const& string ) = 0;
|
|
|
|
|
|
|
|
virtual A_SRDWriter& putComment( T_String const& comment ) = 0;
|
|
|
|
|
|
|
|
virtual A_SRDWriter& putVariable( T_String const& var ) = 0;
|
|
|
|
|
|
|
|
virtual A_SRDWriter& putBinary( T_Buffer< uint8_t > const& binary ) = 0;
|
|
|
|
|
|
|
|
virtual A_SRDWriter& putInteger( int64_t value ) = 0;
|
|
|
|
virtual A_SRDWriter& putInt32( int32_t value ) = 0;
|
|
|
|
virtual A_SRDWriter& putInt64( int64_t value ) = 0;
|
|
|
|
|
|
|
|
virtual A_SRDWriter& putFloat( double value ) = 0;
|
|
|
|
|
|
|
|
virtual A_SRDWriter& end( ) = 0;
|
|
|
|
};
|
|
|
|
M_ABSTRACT_POINTERS( SRDWriter );
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
// A_SRDReaderTarget - Abstract token receiver for SRD readers
|
|
|
|
class A_SRDReaderTarget
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~A_SRDReaderTarget( ) = 0;
|
|
|
|
virtual void start( T_SRDErrors& errors ) = 0;
|
|
|
|
virtual void push( T_SRDErrors& errors , T_SRDToken&& token ) = 0;
|
|
|
|
virtual void end( T_SRDErrors& errors ) = 0;
|
|
|
|
};
|
|
|
|
M_ABSTRACT_POINTERS( SRDReaderTarget );
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
// A_SRDReader - Abstract token reader
|
|
|
|
class A_SRDReader
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
A_SRDReaderTarget& target_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
A_SRDReader( A_SRDReaderTarget& target );
|
|
|
|
|
|
|
|
virtual ~A_SRDReader( ) = 0;
|
|
|
|
virtual void read( T_String const& name , A_InputStream& input ) = 0;
|
|
|
|
};
|
|
|
|
M_ABSTRACT_POINTERS( SRDReader );
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
// X_SRDWriterError - SRD writer exception
|
|
|
|
class X_SRDWriterError : public std::exception
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
char const* msg_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
X_SRDWriterError( char const* msg ) noexcept;
|
|
|
|
|
|
|
|
X_SRDWriterError( ) = delete;
|
|
|
|
X_SRDWriterError( X_SRDWriterError const& ) = default;
|
|
|
|
X_SRDWriterError( X_SRDWriterError&& ) = default;
|
|
|
|
|
|
|
|
char const * what( ) const noexcept override;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*= HELPERS ==================================================================*/
|
|
|
|
|
|
|
|
// T_SRDReaderTargetHelper - Calls start() and end() using RAII
|
|
|
|
class T_SRDReaderTargetHelper
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
A_SRDReaderTarget& target_;
|
|
|
|
T_SRDErrors& errors_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
T_SRDReaderTargetHelper( A_SRDReaderTarget& target , T_SRDErrors& errors );
|
|
|
|
~T_SRDReaderTargetHelper( );
|
|
|
|
};
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
// T_SRDListFixer - A stage that adds missing EOL's and discards extraneous
|
|
|
|
// EOL's, emitting errors as it does so.
|
|
|
|
class T_SRDListFixer final : public A_SRDReaderTarget
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
A_SRDReaderTarget& output_;
|
|
|
|
T_AutoArray< T_SRDLocation , 32 > listStarts_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit T_SRDListFixer( A_SRDReaderTarget& output ) noexcept;
|
|
|
|
|
|
|
|
void start( T_SRDErrors& errors ) override;
|
|
|
|
void push( T_SRDErrors& errors ,
|
|
|
|
T_SRDToken&& token ) override;
|
|
|
|
void end( T_SRDErrors& errors ) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
// T_SRDMemoryTarget - Stores the reader's output as a T_SRDList
|
|
|
|
class T_SRDMemoryTarget : public A_SRDReaderTarget
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
const bool structured_;
|
|
|
|
bool clearFlushToken_;
|
2017-11-06 10:53:54 +01:00
|
|
|
bool clearComments_;
|
2017-11-01 20:14:23 +01:00
|
|
|
T_SRDToken list_;
|
|
|
|
RP_SRDToken current_;
|
|
|
|
T_Array< RP_SRDToken > stack_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// If structured is set, the generated token list will include sub-lists
|
|
|
|
// as E_SRDTokenType::LIST tokens; if it isn't, the list will feature
|
|
|
|
// only start and end of list tokens.
|
|
|
|
explicit T_SRDMemoryTarget( bool structured = true );
|
|
|
|
|
|
|
|
// Set/get flush token handling
|
2017-11-06 10:53:54 +01:00
|
|
|
T_SRDMemoryTarget& clearFlushToken( bool clear ) noexcept;
|
2017-11-01 20:14:23 +01:00
|
|
|
bool clearFlushToken( ) const noexcept;
|
|
|
|
|
2017-11-06 10:53:54 +01:00
|
|
|
// Set/get comment handling
|
|
|
|
T_SRDMemoryTarget& clearComments( bool clear ) noexcept;
|
|
|
|
bool clearComments( ) const noexcept;
|
|
|
|
|
2017-11-01 20:14:23 +01:00
|
|
|
void start( T_SRDErrors& errors ) override;
|
|
|
|
void push( T_SRDErrors& errors , T_SRDToken&& token ) override;
|
|
|
|
void end( T_SRDErrors& errors ) override;
|
|
|
|
|
|
|
|
// Get the list
|
|
|
|
T_SRDList const& list( ) const;
|
|
|
|
// Does the list only contains complete items?
|
|
|
|
bool complete( ) const;
|
|
|
|
};
|
|
|
|
M_CLASS_POINTERS( SRDMemoryTarget );
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
// T_SRDWriterTarget - Forwards token that are read to a writer
|
|
|
|
class T_SRDWriterTarget : public A_SRDReaderTarget
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
A_SRDWriter& writer_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit T_SRDWriterTarget( A_SRDWriter& writer );
|
|
|
|
|
|
|
|
void start( T_SRDErrors& errors ) override;
|
|
|
|
void push( T_SRDErrors& errors , T_SRDToken&& token ) override;
|
|
|
|
void end( T_SRDErrors& errors ) override;
|
|
|
|
};
|
|
|
|
M_CLASS_POINTERS( SRDWriterTarget );
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|
2017-11-01 23:21:01 +01:00
|
|
|
#include <ebcl/inline/SRDIO.hh>
|
|
|
|
#endif // _H_EBCL_SRDIO
|