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

FileFilter.cpp

Go to the documentation of this file.
00001 //  ======================================================================== //
00002 //                                                                           //
00003 //    File      : FileFilter.cpp                                             //
00004 //    Purpose   :                                                            //
00005 //    Time-stamp: <Sat May/04/2002 16:51 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 #include "FileFilter.h"
00022 #include <sys_dep.h>
00023 #include <fstream>
00024 
00025 
00026 using namespace std;
00027 using namespace rs;
00028 using namespace rs::str;
00029 using namespace rs::sys_dep;
00030 
00031 namespace rs {
00032     namespace file {
00033         namespace filter {
00034 
00035             // ----------------------------------------------------
00036             //      static bool isInputName(const string *arg)
00037             // ----------------------------------------------------
00038             static bool isInputName(const string *arg) {
00039                 bool stdinRedirected = !is_a_TTY(stdin);
00040                 return stdinRedirected ? arg==0 : arg!=0;
00041             }
00042             // -----------------------------------------------------
00043             //      static bool isOutputName(const string *arg)
00044             // -----------------------------------------------------
00045             static bool isOutputName(const string *arg) {
00046                 bool stdoutRedirected = !is_a_TTY(stdout);
00047                 return stdoutRedirected ? arg==0 : arg!=0;
00048             }
00049 
00050             // start of implementation of class FileFilter:
00051 
00052             // -------------------------------------------------------------------------------------------------
00053             //      void FileFilter::init(cmdline::CmdLineArgument& input, cmdline::CmdLineArgument& output)
00054             // -------------------------------------------------------------------------------------------------
00055             void FileFilter::init(cmdline::CmdLineArgument& input, cmdline::CmdLineArgument& output)
00056             {
00057                 out       = 0;
00058                 is_stdout = false;
00059                 in        = input ? new InputFile(input.get()) : new InputFile();
00060 
00061                 if (output) {
00062                     out       = new ofstream(output.get().c_str());
00063                     is_stdout = false;
00064                 }
00065                 else {
00066                     out       = &cout;
00067                     is_stdout = true;
00068                 }
00069             }
00070 
00071             // -end- of implementation of class FileFilter.
00072 
00073             // start of implementation of class FilterArguments:
00074 
00075             // ----------------------------------------------------------------------------------------------
00076             //      FilterArguments::FilterArguments(const string& input_type, const string& output_type)
00077             // ----------------------------------------------------------------------------------------------
00078             FilterArguments::FilterArguments(const string& input_type, const string& output_type)
00079                 : input("input", strf("name of %s-inputfile", input_type.c_str()).c_str(), isInputName)
00080                 , output("output", strf("name of %s-outputfile", output_type.c_str()).c_str(), isOutputName)
00081                 , arg_info("If you redirect I/O to/from a file, the corresponding filename may be omitted.")
00082             {
00083             }
00084 
00085             // -end- of implementation of class FilterArguments.
00086 
00087         };
00088     };
00089 };

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