//-----------------------------------------------------------------------------
// NastDumpContextFile.cpp
//-----------------------------------------------------------------------------

#include "NastDumpContextFile.h"
#include "NastDebug.h"

#include <iostream.h>

//-----------------------------------------------------------------------------
//                    Construktor + Destruktor
//-----------------------------------------------------------------------------

//  Defaultconstr.
CNastDumpContextFile::CNastDumpContextFile( ostream &stream )
    :m_streamOut( stream )
{
}

//  Destruktor
CNastDumpContextFile::~CNastDumpContextFile()
{
    // bevor das Objekt zertoert wird auf jedem Fall alles rausschreiben
    flush();
}


//-----------------------------------------------------------------------------
//                         Memberfunktionen
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
//  bool
//-----------------------------------------------------------------------------
CNastDumpContext&
CNastDumpContextFile::operator<<( bool b )
{
    if( b ) 
        m_streamOut << "true";
    else
        m_streamOut << "false";
    return *this;
}

//-----------------------------------------------------------------------------
//  integer
//-----------------------------------------------------------------------------
CNastDumpContext&
CNastDumpContextFile::operator<<( int n )
{
    m_streamOut << n;
    return *this;
}

CNastDumpContext&
CNastDumpContextFile::operator<<( long int n )
{
    m_streamOut << n;
    return *this;
}

//-----------------------------------------------------------------------------
//  floats
//  werden in wiss. Formatierung ausgegeben
//-----------------------------------------------------------------------------
CNastDumpContext&
CNastDumpContextFile::operator<<( float f )
{
    m_streamOut.setf( ios::scientific);
    m_streamOut << f;
    return *this;
}

CNastDumpContext&
CNastDumpContextFile::operator<<( double f )
{
    m_streamOut.setf( ios::scientific);
    m_streamOut << f;
    return *this;
}

CNastDumpContext&
CNastDumpContextFile::operator<<( long double f )
{
    m_streamOut.setf( ios::scientific);
    m_streamOut << f;
    return *this;
}

//-----------------------------------------------------------------------------
// strings
//-----------------------------------------------------------------------------
CNastDumpContext&
CNastDumpContextFile::operator<<( char ch)
{
    m_streamOut << ch;
    return *this;
}

CNastDumpContext&
CNastDumpContextFile::operator<<( const char *pch)
{
    m_streamOut << pch;
    return *this;
}

CNastDumpContext&
CNastDumpContextFile::operator<<( const unsigned char *pch)
{
    m_streamOut << pch;
    return *this;
}


//-----------------------------------------------------------------------------
//  CNastObjects
//  bei CNastObjects wird deren DebugDumpfunktion aufgerufen
//-----------------------------------------------------------------------------
CNastDumpContext&
CNastDumpContextFile::operator<<( const CNastObject *pObject)
{
    NAST_ASSERT( pObject != NULL );
    pObject->debugDump( *this );
    return *this;
}

CNastDumpContext&
CNastDumpContextFile::operator<<( const CNastObject &rObject)
{
    CNastDumpContextFile::operator<<( &rObject );
    return *this;
}

//-----------------------------------------------------------------------------
// Flush sollte alles so rausschreiben, dass auch bei einem Absturz
// des Programms keine Daten verloren gehen
//-----------------------------------------------------------------------------
void 
CNastDumpContextFile::flush()
{
    m_streamOut.flush();
}



