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

LocateInputFileDirectory.cpp

Go to the documentation of this file.
00001 #include "LocateInputFileDirectory.h"
00002 #include <string.h>
00003 #include <stdio.h>
00004 #ifdef _WIN32
00005 #include <fstream>
00006 #include <iostream>
00007 #else
00008 #include <fstream>
00009 #include <iostream>
00010 #endif
00011 
00012 LocateInputFileDirectory::LocateInputFileDirectory(const char *fileName)
00013 {
00014         char inFileName[2000];
00015         // Directories to search for fileName
00016         int nDirectories = 4;
00017         char *directories[4];
00018         directories[0] = "";
00019         directories[1] = "../";
00020         directories[2] = "../../";
00021         directories[3] = "../../../";
00022 
00023         for (int dir=0; dir<nDirectories; dir++)
00024         {
00025                 strcpy(inFileName,directories[dir]);
00026                 strcat(inFileName, fileName);
00027 
00028                 #ifdef _WIN32
00029 //              std::ifstream input(inFileName,ios::nocreate,filebuf::sh_read);
00030                 std::ifstream input(inFileName);
00031                 #else
00032                 std::ifstream input;
00033                 input.open(inFileName);
00034                 #endif
00035 
00036                 if (input)
00037                 {
00038                         input.close();
00039                         strcpy(directoryName, directories[dir]);
00040                         std::cout << "Found directory = " << directoryName << std::endl << std::flush;
00041                         return;
00042                 }
00043                 else
00044                         input.close();
00045         }
00046 
00047         throw;
00048 }
00049 
00050 LocateInputFileDirectory::~LocateInputFileDirectory(void)
00051 {
00052 }
00053 
00054 const char* LocateInputFileDirectory::Get(const char* fileName) 
00055 {
00056         strcpy(gotFileName, directoryName);
00057         strcat(gotFileName, fileName);
00058         return gotFileName;
00059 }

Generated on Mon Nov 3 09:37:57 2003 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002