diff options
author | Chris Dyer <redpony@gmail.com> | 2009-12-14 20:35:11 -0500 |
---|---|---|
committer | Chris Dyer <redpony@gmail.com> | 2009-12-14 20:35:11 -0500 |
commit | 851e389dffdd6996ea32d70defb8906de80b9edc (patch) | |
tree | 8c68ee77205badc056b8ab5b332e67e3e98017df /src/filelib.h | |
parent | dc6930c00b4b276883280cff1ed6dcd9ddef03c7 (diff) |
few small fixes of alignment tools, add new orthographic similarity feature for word aligner, final naming of directories, libraries in cdec
Diffstat (limited to 'src/filelib.h')
-rw-r--r-- | src/filelib.h | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/src/filelib.h b/src/filelib.h deleted file mode 100644 index 62cb9427..00000000 --- a/src/filelib.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef _FILELIB_H_ -#define _FILELIB_H_ - -#include <cassert> -#include <string> -#include <iostream> -#include <cstdlib> -#include "gzstream.h" - -// reads from standard in if filename is - -// uncompresses if file ends with .gz -// otherwise, reads from a normal file -class ReadFile { - public: - ReadFile(const std::string& filename) : - no_delete_on_exit_(filename == "-"), - in_(no_delete_on_exit_ ? static_cast<std::istream*>(&std::cin) : - (EndsWith(filename, ".gz") ? - static_cast<std::istream*>(new igzstream(filename.c_str())) : - static_cast<std::istream*>(new std::ifstream(filename.c_str())))) { - if (!*in_) { - std::cerr << "Failed to open " << filename << std::endl; - abort(); - } - } - ~ReadFile() { - if (!no_delete_on_exit_) delete in_; - } - - inline std::istream* stream() { return in_; } - - private: - static bool EndsWith(const std::string& f, const std::string& suf) { - return (f.size() > suf.size()) && (f.rfind(suf) == f.size() - suf.size()); - } - const bool no_delete_on_exit_; - std::istream* const in_; -}; - -class WriteFile { - public: - WriteFile(const std::string& filename) : - no_delete_on_exit_(filename == "-"), - out_(no_delete_on_exit_ ? static_cast<std::ostream*>(&std::cout) : - (EndsWith(filename, ".gz") ? - static_cast<std::ostream*>(new ogzstream(filename.c_str())) : - static_cast<std::ostream*>(new std::ofstream(filename.c_str())))) {} - ~WriteFile() { - (*out_) << std::flush; - if (!no_delete_on_exit_) delete out_; - } - - inline std::ostream* stream() { return out_; } - - private: - static bool EndsWith(const std::string& f, const std::string& suf) { - return (f.size() > suf.size()) && (f.rfind(suf) == f.size() - suf.size()); - } - const bool no_delete_on_exit_; - std::ostream* const out_; -}; - -bool FileExists(const std::string& file_name); -bool DirectoryExists(const std::string& dir_name); - -#endif |