![]() |
![]() |
00001 #include "Utilities/General/interface/Tokenizer.h" 00002 #include "Utilities/General/interface/FileInPath.h" 00003 #include <iostream> 00004 #include <fstream> 00005 00006 const std::string FileInPath::semicolon(":"); 00007 00008 FileInPath::FileInPath(const std::string & ipath, const std::string & ifile) { 00009 init(ipath, ifile); 00010 } 00011 00012 void FileInPath::init(const std::string & ipath, const std::string & ifile) { 00013 if (ipath.empty()||ifile.empty()) return; 00014 00015 directories = Tokenizer(semicolon,ipath); 00016 typedef std::vector<std::string>::const_iterator Itr; 00017 for (Itr d=directories.begin(); d!=directories.end(); d++) { 00018 file = *d; file += "/"; file += ifile; 00019 in = own_ptr<std::ifstream>(new std::ifstream(file.c_str())); 00020 if (in->good()) break; 00021 } 00022 if (!in->good()) { in.release(); file="";} 00023 } 00024 00025 FileInPath::FileInPath(const FileInPath& rh ) : 00026 directories(rh.directories), file(rh.file) { 00027 if (rh.in.get()) in = own_ptr<std::ifstream>(new std::ifstream(file.c_str())); 00028 } 00029 00030 00031 FileInPath & FileInPath::operator=(const FileInPath& rh ) { 00032 directories = rh.directories; 00033 file = rh.file; 00034 if (rh.in.get()&&(!file.empty())) in = own_ptr<std::ifstream>(new std::ifstream(file.c_str())); 00035 return *this; 00036 } 00037 00038 FileInPath::~FileInPath() {} 00039