OpenWalnut  1.4.0
WLoggerWrapper.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <iostream>
26 #include <fstream>
27 #include <string>
28 
29 #include "core/common/WAssert.h"
30 #include "core/common/WLogger.h"
31 #include "core/common/WLogStream.h"
32 
33 #include "WLoggerWrapper.h"
34 
36 {
37 }
38 
40 {
41  WAssert( logger, "Null pointer" );
42  m_logger = logger;
43 }
44 
46 {
48 }
49 
51 {
52  m_logger->removeStream( m_fileStreamList[ i ].m_WLogStream );
53  m_fileStreamList.erase( m_fileStreamList.begin() + i );
54 }
55 
56 bool WLoggerWrapper::addFileStream( std::string filename )
57 {
58  boost::shared_ptr< std::ofstream > fileStream( new std::ofstream( filename.c_str() ) );
59  if( !fileStream )
60  {
61  return false;
62  }
63  FileStreamEntry newEntry;
64  newEntry.m_filename = filename;
65  newEntry.m_fileStream = fileStream;
66  newEntry.m_WLogStream = WLogStream::SharedPtr( new WLogStream( *fileStream ) );
67  m_fileStreamList.push_back( newEntry );
68  m_logger->addStream( newEntry.m_WLogStream );
69  return true;
70 }
71 
72 bool WLoggerWrapper::removeFileStream( std::string filename )
73 {
74  for( size_t i = 0; i < m_fileStreamList.size(); ++i )
75  {
76  if( filename == m_fileStreamList[ i ].m_filename )
77  {
79  return true;
80  }
81  }
82  return false;
83 }
84 
86 {
87  for( size_t i = 0; i < m_fileStreamList.size(); ++i )
88  {
90  }
91 }