OpenWalnut  1.4.0
WLoggerWrapper.h
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WLOGGERWRAPPER_H
00026 #define WLOGGERWRAPPER_H
00027 
00028 #include <string>
00029 #include <vector>
00030 
00031 #include <boost/shared_ptr.hpp>
00032 #include <boost/tuple/tuple.hpp>
00033 
00034 
00035 #include "core/common/WLogger.h"
00036 #include "core/common/WLogStream.h"
00037 
00038 /**
00039  * \class WLoggerWrapper
00040  *
00041  * A wrapper for WLogger. This is used to expose a part of the WLogger functionality
00042  * to script interpreters.
00043  */
00044 class WLoggerWrapper
00045 {
00046     /**
00047      * A helper class for storing information about file streams that we added to
00048      * the logger.
00049      */
00050     struct FileStreamEntry
00051     {
00052         //! The name of the log file.
00053         std::string m_filename;
00054 
00055         //! The actual stream.
00056         boost::shared_ptr< std::ofstream > m_fileStream;
00057 
00058         //! The logstream instance.
00059         WLogStream::SharedPtr m_WLogStream;
00060     };
00061 
00062 public:
00063     /**
00064      * Constructor. Creates an empty wrapper.
00065      */
00066     WLoggerWrapper();
00067 
00068     /**
00069      * Constructor.
00070      *
00071      * \param logger A pointer to a logger instance.
00072      */
00073     explicit WLoggerWrapper( WLogger* logger );
00074 
00075     /**
00076      * Destructor.
00077      */
00078     ~WLoggerWrapper();
00079 
00080     /**
00081      * Add a file to which the logger output will be written.
00082      *
00083      * \param filename The name of the file to write logging stuff into.
00084      *
00085      * \return true, if a stream to that file could be created and added successfully.
00086      */
00087     bool addFileStream( std::string filename );
00088 
00089     /**
00090      * Remove a file to which the logger writes.
00091      *
00092      * \param filename The name of the file to remove.
00093      *
00094      * \return true, if a stream to that file existed and was removed successfully.
00095      */
00096     bool removeFileStream( std::string filename );
00097 
00098     /**
00099      * Remove all files to which the logger writes (and which were added by this wrapper).
00100      */
00101     void removeAllFileStreams();
00102 
00103 private:
00104     /**
00105      * Helper function that removes the file stream with the given index.
00106      *
00107      * \param i The index of the stream to remove.
00108      */
00109     void removeFileStreamNumber( size_t i );
00110 
00111     //! A pointer to the logger.
00112     WLogger* m_logger;
00113 
00114     //! List of file streams.
00115     std::vector< FileStreamEntry > m_fileStreamList;
00116 };
00117 
00118 #endif  // WLOGGERWRAPPER_H