Shellp

fileptriosystem.h

00001 /*
00002     
00003   This file is a part of Shellp, a 'shell helper' library.
00004   
00005   Copyright (C) 2011-2012 Jori Liesenborgs
00006   
00007   Contact: jori.liesenborgs@gmail.com
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  
00022   USA
00023 
00024 */
00025 
00026 #ifndef SHELLP_FILEPTRIOSYSTEM_H
00027 
00028 #define SHELLP_FILEPTRIOSYSTEM_H
00029 
00030 #include "shellconfig.h"
00031 #include "iosystem.h"
00032 #include <stdio.h>
00033 
00034 namespace shellp
00035 {
00036  
00037 class SHELLP_IMPORTEXPORT FilePtrIOSystem : public IOSystem
00038 {
00039 public:
00040         FilePtrIOSystem();
00041         FilePtrIOSystem(FILE *pInput, FILE *pOutput);
00042         ~FilePtrIOSystem();
00043 
00044         void writeOutputLine(const std::string &line, bool newline = true);
00045 protected:
00046         void setFileInputPtr(FILE *g)                                                   { fi = g; }
00047         FILE *getFileInputPtr()                                                         { return fi; }
00048         void setFileOutputPtr(FILE *g)                                                  { fo = g; }
00049         FILE *getFileOutputPtr()                                                        { return fo; }
00050 private:
00051         bool readInputLineInternal(std::string &line);
00052         void writeInputPrefix(const std::string &prefix);
00053 
00054         FILE *fi,*fo;
00055 };
00056 
00057 } // end namespace
00058 
00059 #endif // SHELLP_FILEPTRIOSYSTEM_H
00060