Updating the changelog in the VERSION file, and version_sync
[shapes.git] / source / debuglog.cc
blob33802cf69d4ac17f0ed69e9433a1167abfd83eab
1 /* This file is part of Shapes.
3 * Shapes is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * any later version.
8 * Shapes is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with Shapes. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright 2008 Henrik Tidefelt
19 #include "debuglog.h"
20 #include "shapesexceptions.h"
22 using namespace Shapes;
24 Kernel::DebugLog::DebugLog( )
25 : os_( 0 )
26 { }
28 Kernel::DebugLog::~DebugLog( )
29 { }
31 bool
32 Kernel::DebugLog::initialized( ) const
34 return os_ != 0 || ! filename_.empty( );
37 void
38 Kernel::DebugLog::setStream( std::ostream * os )
40 if( initialized( ) )
42 throw "Multiply specified debug log";
44 os_ = os;
47 void
48 Kernel::DebugLog::setFilename( const std::string & filename )
50 if( initialized( ) )
52 throw "Multiply specified debug log";
54 filename_ = filename;
57 std::ostream &
58 Kernel::DebugLog::os( )
60 if( os_ == 0 )
62 if( filename_.empty( ) )
64 throw Exceptions::InternalError( "The debug log filename was not initialized before it was needed." );
66 myFile_.open( filename_.c_str( ) );
67 if( ! myFile_.is_open( ) )
69 throw Exceptions::FileWriteOpenError( Ast::THE_UNKNOWN_LOCATION, strrefdup( filename_ ), "(debug log)" );
71 os_ = & myFile_;
73 return *os_;