Improving data logging

parent bac897cf
......@@ -40,7 +40,7 @@ public:
//! Hook: Ausgabe der Beschreibung des Datums (z.B. Felder) in einen Stream
// Dies wird fr den Header in der Datei verwendet
// Zum Beispiel so: [0] Index, [1] Time, ...
virtual std::ostream& outputDesc( std::ostream& os ) const = 0;
static std::ostream& outputDesc( std::ostream& os );
//! Hook: Ausgabe eines konkreten Datums in einen Stream (Formattierer)
virtual std::ostream& outputData( std::ostream& os ) const = 0;
......@@ -50,12 +50,15 @@ public:
template <class T> class ITABufferedDataLogger
{
public:
ITABufferedDataLogger( int iNumItems = 100, bool bMatlab = true );
ITABufferedDataLogger( int iNumItems = 100, bool bHeaderIncluded = true );
ITABufferedDataLogger( const std::string& sOutputFilePath, int iNumItems, bool bMatlab = true );
ITABufferedDataLogger( const std::string& sOutputFilePath, int iNumItems, bool bHeaderIncluded = true );
virtual ~ITABufferedDataLogger();
//! Include header in exported file
void SetIncludeHeader( bool bEnabled );
//! Setzt die Ausgabedatei
/**
* Falls diese angegeben wird, so werden alle geloggten Daten
......@@ -80,55 +83,58 @@ public:
private:
std::vector<T> m_vLogItems;
std::string m_sOutputFile;
bool m_bMatlab;
bool m_bIncludeHeader;
};
// Header impl to avoid explicit definitions
template< class T > ITABufferedDataLogger< T >::ITABufferedDataLogger( int iNumItems, bool bMatlab )
: m_bMatlab( bMatlab )
template< class T > ITABufferedDataLogger< T >::ITABufferedDataLogger( int iNumItems, bool bIncludeHeader )
: m_bIncludeHeader( bIncludeHeader )
{
m_vLogItems.reserve( iNumItems );
}
};
template< class T > ITABufferedDataLogger< T >::ITABufferedDataLogger( const std::string& sOutputFile, int iNumItems, bool bMatlab )
template< class T > ITABufferedDataLogger< T >::ITABufferedDataLogger( const std::string& sOutputFile, int iNumItems, bool bIncludeHeader )
: m_sOutputFile( sOutputFile )
, m_bMatlab( bMatlab )
, m_bIncludeHeader( bIncludeHeader )
{
m_vLogItems.reserve( iNumItems );
}
};
template< class T > ITABufferedDataLogger< T >::~ITABufferedDataLogger()
{
if( !m_sOutputFile.empty() )
store( m_sOutputFile );
}
};
template< class T > std::string ITABufferedDataLogger< T >::GetOutputFileName() const
{
return m_sOutputFile;
}
};
template< class T > void ITABufferedDataLogger< T >::SetIncludeHeader( bool bEnabled )
{
m_bIncludeHeader = bEnabled;
};
template< class T > void ITABufferedDataLogger< T >::setOutputFile( const std::string& sFilename )
{
m_sOutputFile = sFilename;
}
};
template< class T > void ITABufferedDataLogger< T >::clear() {
m_vLogItems.clear();
}
};
template< class T > void ITABufferedDataLogger< T >::reserve( int iNumItems )
{
m_vLogItems.reserve( iNumItems );
}
};
template< class T > void ITABufferedDataLogger< T >::log( const T& oLogItem )
{
m_vLogItems.push_back( oLogItem );
}
};
template< class T > void ITABufferedDataLogger< T >::store( const std::string& sFilename )
{
......@@ -137,16 +143,16 @@ template< class T > void ITABufferedDataLogger< T >::store( const std::string& s
if( !os.is_open() )
ITA_EXCEPT1( IO_ERROR, std::string( "Could not create log output file \"" ) + sFilename + std::string( "\"" ) );
if( m_bIncludeHeader )
T::outputDesc( os );
for( int i = 0; i < ( int ) m_vLogItems.size(); i++ )
{
T& oItem = m_vLogItems[ i ];
if( i == 0 && !m_bMatlab )
oItem.outputDesc( os );
else
oItem.outputData( os );
oItem.outputData( os );
}
os.close();
}
};
#endif // INCLUDE_WATCHER_ITA_DATA_LOG
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment