Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

FileFilter.h

Go to the documentation of this file.
00001 //  ======================================================================== //
00002 //                                                                           //
00003 //    File      : FileFilter.h                                               //
00004 //    Purpose   : Easy to use interface for programs which act as filter.    //
00005 //    Time-stamp: <Wed Nov/13/2002 05:43 MET Coder@ReallySoft.de>            //
00006 //                                                                           //
00007 //    (C) May 2002 by Ralf Westram                                           //
00008 //                                                                           //
00009 //    Permission to use, copy, modify, distribute and sell this software     //
00010 //    and its documentation for any purpose is hereby granted without fee,   //
00011 //    provided that the above copyright notice appear in all copies and      //
00012 //    that both that copyright notice and this permission notice appear      //
00013 //    in supporting documentation.                                           //
00014 //                                                                           //
00015 //    Ralf Westram makes no representations about the suitability of this    //
00016 //    software for any purpose.  It is provided "as is" without express or   //
00017 //    implied warranty.                                                      //
00018 //                                                                           //
00019 //  ======================================================================== //
00020 
00021 #ifndef FILEFILTER_H
00022 #define FILEFILTER_H
00023 
00024 #ifndef OPTION_H
00025 #include <Option.h>
00026 #endif
00027 #ifndef INPUTFILE_H
00028 #include <InputFile.h>
00029 #endif
00030 
00031 namespace rs {
00032     namespace file {
00033 
00035         namespace filter {
00036 
00037             class FilterArguments {
00038             private:
00039                 cmdline::OptionalCmdLineArgument input;
00040                 cmdline::OptionalCmdLineArgument output;
00041                 cmdline::CmdLineAnnotation arg_info;
00042 
00043             public:
00052                 FilterArguments(const std::string& input_type, const std::string& output_type);
00053                 virtual ~FilterArguments() {}
00054 
00058                 cmdline::OptionalCmdLineArgument& get_input() { return input; }
00059 
00063                 cmdline::OptionalCmdLineArgument& get_output() { return output; }
00064             };
00065 
00066             //  -------------------------
00067             //      class FileFilter
00068             //  -------------------------
00069             class FileFilter {
00070             private:
00071                 file::InputFile *in;
00072                 std::ostream    *out;
00073                 bool             is_stdout;
00074 
00075                 void init(cmdline::CmdLineArgument& input, cmdline::CmdLineArgument& output);
00076 
00077             public:
00078                 FileFilter(FilterArguments& filter) { init(filter.get_input(), filter.get_output()); }
00079                 FileFilter(cmdline::CmdLineArgument& input, cmdline::CmdLineArgument& output) { init(input, output); }
00080 
00081                 virtual ~FileFilter() {
00082                     delete in;
00083                     if (!is_stdout) delete out;
00084                 }
00085 
00086                 bool getLine(std::string& s) { return in->getLine(s); }
00087                 void putLine(const std::string& s) { (*out) << s << "\n"; }
00088             };
00089 
00090         };
00091     };
00092 }; // end of namespace rs
00093 
00094 #else
00095 #error FileFilter.h included twice
00096 #endif // FILEFILTER_H
00097 

Contact me in case of errors or questions.
This documentation is powered by Doxygen.
(C) 2000-2002 Doxygen