Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

BasicStreams.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 //
00003 //  Thomas Berger (main author), Pepijn Schreinemachers, and Thorsten Arnold
00004 //
00005 //
00006 //  Hohenheim University (490d)
00007 //  Professorship for Land Use Economics in the Tropics and Subtropics
00008 //
00009 //  May not be distributed without permission by main author
00010 //
00011 //  File:       BasicStreams.h (formerly fileFuns.h)
00012 //
00013 //  Contents:   Auxiliary class for stream handling, e.g. if file exists
00014 //
00015 //
00016 //
00017 //------------------------------------------------------------------------------
00018 
00019 
00020 
00021 #ifndef _BasicStreams_h
00022 #define _BasicStreams_h
00023 
00024 
00025 #include <string.h>
00026 #include <string>
00027 
00028 #include <stdio.h>
00029 #include <iostream>
00030 #include <fstream>
00031 
00032 using namespace std;  // std::stream  --> stream (simpler)
00033 
00034 
00035 #include "BasicEnums.h"
00036 
00037 //char* copyRestOfString(char* inchar, int startVal);
00038 void  copyRestOfString(char* inchar, char* outchar, int startVal);
00039 string   stringCopyRestOfString(string inchar, int startVal);
00040 string itos(int i);
00041 
00042 
00043 //Arnold2006_122
00044 //--------------------------------------------------------------------
00045 // output_file_open() and input_file_open() are safer versions of
00046 // using open().  When you open a file for output, if that file
00047 // already exists you will overwrite it and loose its previous
00048 // contents.  Not good. So output_file_open firsts check to see if
00049 // the file 'filename' exists.  If it does, then output_file_open
00050 // returns false, which means failure. If it returns true, then
00051 // the file was successfully opened, and the fout stream should
00052 // be ready for writing.
00053 //--------------------------------------------------------------------
00054 bool output_file_open (string filename, ofstream & fout);
00055 bool input_file_open  (string filename, ifstream & fin);
00056 
00057 //Arnold2006_122
00058 //--------------------------------------------------------------------
00059 // file_exists() uses a little trick to see if a file by the name of
00060 // "filename" currently exists.  It does so by opening the file for
00061 // reading.  If that fails, then we know the file doesn't exist, and
00062 // return false.  If the file does exist, then we simply close it and
00063 // return true.
00064 //--------------------------------------------------------------------
00065 bool file_exists (string filename);
00066 bool file_exists (string filename, bool do_output);
00067 
00068 int check_dirExists(string dname);
00069 int check_dirExists(char* dname);
00070 
00071 void createDIR(char* makeDIR);
00072 void createDIR(string str_makeDir);
00073 
00074 
00075 int getListOfAllDirectoriesStartingWith(string localDirectory, string startStringOfDirectories, string*& arrayOfStrings);
00076 int getListOfAllFilesStartingWith(string localDirectory, string startStringOfDirectories, string*& arrayOfStrings);
00077 // "Real" function for above two
00078 int getListOfAllFilesByType_StartingWith(int type, string localDirectory, string startStringOfDirectories, string*& arrayOfStrings);
00079 
00080 
00081 int getNumberOfFilesWithStart(string fnDir, string startFilename);
00082 int getArrayOfFilesnamesWithStart(
00083         string fnIn, 
00084         string startFilename, 
00085         string*& allFilenames);
00086 
00087 void deleteFile(string filename, bool doOutput);
00088 
00089 #endif

Generated on Thu Aug 28 12:38:44 2008 for MPMAS by  doxygen 1.3.9.1