|
diff --git a/mecab/src/char_property.cpp b/mecab/src/char_property.cpp |
|
index f78dacb..336456a 100644 |
|
--- a/mecab/src/char_property.cpp |
|
+++ b/mecab/src/char_property.cpp |
|
@@ -135,17 +135,32 @@ bool CharProperty::compile(const char *cfile, |
|
std::vector<Range> range; |
|
std::map<std::string, CharInfo> category; |
|
std::vector<std::string> category_ary; |
|
- std::ifstream ifs(WPATH(cfile)); |
|
std::istringstream iss(CHAR_PROPERTY_DEF_DEFAULT); |
|
- std::istream *is = &ifs; |
|
+#ifdef HAVE_BOOST |
|
+ boost::filesystem::path path(WPATH(cfile)); |
|
+ boost::filesystem::ifstream ifs(path); |
|
+ boost::iostreams::filtering_streambuf<boost::iostreams::input> ifilter; |
|
+ |
|
+ if (!ifs.is_open()) { |
|
+ std::cerr << cfile |
|
+ << " is not found. minimum setting is used" << std::endl; |
|
+ ifilter.push(iss); |
|
+ } else { |
|
+ ifilter.push(ifs); |
|
+ } |
|
+ std::istream is(&ifilter); |
|
+#else |
|
+ std::ifstream ifs(WPATH(cfile)); |
|
+ std::istream &is = ifs; |
|
|
|
if (!ifs) { |
|
std::cerr << cfile |
|
<< " is not found. minimum setting is used" << std::endl; |
|
- is = &iss; |
|
+ is = iss; |
|
} |
|
+#endif |
|
|
|
- while (is->getline(line.get(), line.size())) { |
|
+ while (is.getline(line.get(), line.size())) { |
|
if (std::strlen(line.get()) == 0 || line[0] == '#') { |
|
continue; |
|
} |
|
@@ -211,17 +226,32 @@ bool CharProperty::compile(const char *cfile, |
|
<< "category [SPACE] is undefined"; |
|
|
|
std::istringstream iss2(UNK_DEF_DEFAULT); |
|
+#ifdef HAVE_BOOST |
|
+ boost::filesystem::path path2(WPATH(ufile)); |
|
+ boost::filesystem::ifstream ifs2(path2); |
|
+ boost::iostreams::filtering_streambuf<boost::iostreams::input> ofilter; |
|
+ |
|
+ if (!ifs2.is_open()) { |
|
+ std::cerr << ufile |
|
+ << " is not found. minimum setting is used." << std::endl; |
|
+ ofilter.push(iss2); |
|
+ } else { |
|
+ ofilter.push(ifs2); |
|
+ } |
|
+ std::istream is2(&ofilter); |
|
+#else |
|
std::ifstream ifs2(WPATH(ufile)); |
|
- std::istream *is2 = &ifs2; |
|
+ std::istream &is2 = ifs2; |
|
|
|
if (!ifs2) { |
|
std::cerr << ufile |
|
<< " is not found. minimum setting is used." << std::endl; |
|
- is2 = &iss2; |
|
+ is2 = iss2; |
|
} |
|
+#endif |
|
|
|
std::set<std::string> unk; |
|
- while (is2->getline(line.get(), line.size())) { |
|
+ while (is2.getline(line.get(), line.size())) { |
|
const size_t n = tokenizeCSV(line.get(), col.get(), 2); |
|
CHECK_DIE(n >= 1) << "format error: " << line.get(); |
|
const std::string key = col[0]; |
|
@@ -256,7 +286,11 @@ bool CharProperty::compile(const char *cfile, |
|
|
|
// output binary table |
|
{ |
|
+#ifdef HAVE_BOOST |
|
+ iostreams_ofstream ofs(WPATH(ofile), std::ios::binary|std::ios::out); |
|
+#else |
|
std::ofstream ofs(WPATH(ofile), std::ios::binary|std::ios::out); |
|
+#endif |
|
CHECK_DIE(ofs) << "permission denied: " << ofile; |
|
|
|
unsigned int size = static_cast<unsigned int>(category.size()); |
|
diff --git a/mecab/src/common.h b/mecab/src/common.h |
|
index d1fc459..9b5a53d 100644 |
|
--- a/mecab/src/common.h |
|
+++ b/mecab/src/common.h |
|
@@ -23,6 +23,116 @@ |
|
#include "config.h" |
|
#endif |
|
|
|
+#ifdef HAVE_BOOST |
|
+#include <boost/filesystem/path.hpp> |
|
+#include <boost/filesystem/fstream.hpp> |
|
+#include <boost/iostreams/filtering_streambuf.hpp> |
|
+ |
|
+class iostreams_ifstream |
|
+{ |
|
+public: |
|
+ iostreams_ifstream(const char *filename, |
|
+ std::ios_base::openmode mode=std::ios::in) : |
|
+ iostreams_ifstream(boost::filesystem::path(filename), mode) |
|
+ {} |
|
+ |
|
+ iostreams_ifstream(const wchar_t *filename, |
|
+ std::ios_base::openmode mode=std::ios::in) : |
|
+ iostreams_ifstream(boost::filesystem::path(filename), mode) |
|
+ {} |
|
+ |
|
+ iostreams_ifstream(const boost::filesystem::path &path, |
|
+ std::ios_base::openmode mode) : |
|
+ ifs(path, mode), |
|
+ filter(ifs), |
|
+ is_(new std::istream(&filter)) |
|
+ {} |
|
+ |
|
+ std::istream &operator*() const { return *is_; } |
|
+ std::istream *operator->() const { return is_; } |
|
+ std::istream *operator&() const { return is_; } |
|
+ |
|
+ operator bool() const { |
|
+ return ifs.is_open(); |
|
+ } |
|
+ operator std::istream &() const { return *is_; } |
|
+ |
|
+ void close() { ifs.close(); } |
|
+ |
|
+ std::istream &getline(char *s, std::streamsize n) { |
|
+ return is_->getline(s, n); |
|
+ } |
|
+ |
|
+ boost::filesystem::ifstream ifs; |
|
+ boost::iostreams::filtering_streambuf<boost::iostreams::input> filter; |
|
+ std::istream *is_; |
|
+}; |
|
+ |
|
+template <class T> |
|
+std::istream& operator >>(iostreams_ifstream &os, T &dt) |
|
+{ |
|
+ return (*os) >> dt; |
|
+} |
|
+ |
|
+namespace std { |
|
+inline std::istream &getline(iostreams_ifstream &is, std::string &s) { |
|
+ return std::getline((*is), s); |
|
+} |
|
+} |
|
+ |
|
+class iostreams_ofstream |
|
+{ |
|
+public: |
|
+ iostreams_ofstream(const char *filename, |
|
+ std::ios_base::openmode mode=std::ios::out) : |
|
+ iostreams_ofstream(boost::filesystem::path(filename), mode) |
|
+ {} |
|
+ |
|
+ iostreams_ofstream(const wchar_t *filename, |
|
+ std::ios_base::openmode mode=std::ios::out) : |
|
+ iostreams_ofstream(boost::filesystem::path(filename), mode) |
|
+ {} |
|
+ |
|
+ iostreams_ofstream(const boost::filesystem::path &path, |
|
+ std::ios_base::openmode mode) : |
|
+ ofs(path, mode), |
|
+ filter(ofs), |
|
+ os_(new std::ostream(&filter)) |
|
+ {} |
|
+ |
|
+ std::ostream &operator*() const { return *os_; } |
|
+ std::ostream *operator->() const { return os_; } |
|
+ std::ostream *operator&() const { return os_; } |
|
+ |
|
+ operator bool() const { |
|
+ return ofs.is_open(); |
|
+ } |
|
+ |
|
+ void close() { ofs.close(); } |
|
+ |
|
+ std::size_t tellp() { |
|
+ return os_->tellp(); |
|
+ } |
|
+ std::ostream &seekp(std::size_t pos) { |
|
+ return os_->seekp(pos); |
|
+ } |
|
+ |
|
+ std::ostream &write(const char *s, std::streamsize n) { |
|
+ return os_->write(s, n); |
|
+ } |
|
+ |
|
+ boost::filesystem::ofstream ofs; |
|
+ boost::iostreams::filtering_streambuf<boost::iostreams::output> filter; |
|
+ std::ostream *os_; |
|
+}; |
|
+ |
|
+template <class T> |
|
+std::ostream& operator <<(iostreams_ofstream &os, const T &dt) |
|
+{ |
|
+ return (*os) << dt; |
|
+} |
|
+#endif |
|
+ |
|
#if defined(_MSC_VER) || defined(__CYGWIN__) |
|
#define NOMINMAX |
|
#define snprintf _snprintf |
|
diff --git a/mecab/src/connector.cpp b/mecab/src/connector.cpp |
|
index 4021cbe..f718d4b 100644 |
|
--- a/mecab/src/connector.cpp |
|
+++ b/mecab/src/connector.cpp |
|
@@ -46,7 +46,11 @@ void Connector::close() { |
|
} |
|
|
|
bool Connector::openText(const char *filename) { |
|
+#ifdef HAVE_BOOST |
|
+ iostreams_ifstream ifs(WPATH(filename)); |
|
+#else |
|
std::ifstream ifs(WPATH(filename)); |
|
+#endif |
|
if (!ifs) { |
|
WHAT << "no such file or directory: " << filename; |
|
return false; |
|
@@ -62,21 +66,35 @@ bool Connector::openText(const char *filename) { |
|
} |
|
|
|
bool Connector::compile(const char *ifile, const char *ofile) { |
|
- std::ifstream ifs(WPATH(ifile)); |
|
std::istringstream iss(MATRIX_DEF_DEFAULT); |
|
- std::istream *is = &ifs; |
|
+#ifdef HAVE_BOOST |
|
+ boost::filesystem::path path(WPATH(ifile)); |
|
+ boost::filesystem::ifstream ifs(path); |
|
+ boost::iostreams::filtering_streambuf<boost::iostreams::input> filter; |
|
|
|
- if (!ifs) { |
|
+ if (!ifs.is_open()) { |
|
std::cerr << ifile |
|
<< " is not found. minimum setting is used." << std::endl; |
|
- is = &iss; |
|
+ filter.push(iss); |
|
+ } else { |
|
+ filter.push(ifs); |
|
} |
|
+ std::istream is(&filter); |
|
+#else |
|
+ std::ifstream ifs(WPATH(ifile)); |
|
+ std::istream &is = ifs; |
|
|
|
+ if (!ifs) { |
|
+ std::cerr << ifile |
|
+ << " is not found. minimum setting is used." << std::endl; |
|
+ is = iss; |
|
+ } |
|
+#endif |
|
|
|
char *column[4]; |
|
scoped_fixed_array<char, BUF_SIZE> buf; |
|
|
|
- is->getline(buf.get(), buf.size()); |
|
+ is.getline(buf.get(), buf.size()); |
|
|
|
CHECK_DIE(tokenize2(buf.get(), "\t ", column, 2) == 2) |
|
<< "format error: " << buf.get(); |
|
@@ -89,7 +107,7 @@ bool Connector::compile(const char *ifile, const char *ofile) { |
|
std::cout << "reading " << ifile << " ... " |
|
<< lsize << "x" << rsize << std::endl; |
|
|
|
- while (is->getline(buf.get(), buf.size())) { |
|
+ while (is.getline(buf.get(), buf.size())) { |
|
CHECK_DIE(tokenize2(buf.get(), "\t ", column, 3) == 3) |
|
<< "format error: " << buf.get(); |
|
const size_t l = std::atoi(column[0]); |
|
@@ -100,7 +118,12 @@ bool Connector::compile(const char *ifile, const char *ofile) { |
|
matrix[(l + lsize * r)] = static_cast<short>(c); |
|
} |
|
|
|
+#ifdef HAVE_BOOST |
|
+ iostreams_ofstream ofs(WPATH(ofile), |
|
+ std::ios::binary|std::ios::out); |
|
+#else |
|
std::ofstream ofs(WPATH(ofile), std::ios::binary|std::ios::out); |
|
+#endif |
|
CHECK_DIE(ofs) << "permission denied: " << ofile; |
|
ofs.write(reinterpret_cast<const char*>(&lsize), sizeof(unsigned short)); |
|
ofs.write(reinterpret_cast<const char*>(&rsize), sizeof(unsigned short)); |
|
diff --git a/mecab/src/context_id.cpp b/mecab/src/context_id.cpp |
|
index c3d6a49..dfa0f5e 100644 |
|
--- a/mecab/src/context_id.cpp |
|
+++ b/mecab/src/context_id.cpp |
|
@@ -15,7 +15,11 @@ using namespace MeCab; |
|
bool open_map(const char *filename, |
|
std::map<std::string, int> *cmap, |
|
Iconv *iconv) { |
|
+#ifdef HAVE_BOOST |
|
+ iostreams_ifstream ifs(WPATH(filename)); |
|
+#else |
|
std::ifstream ifs(WPATH(filename)); |
|
+#endif |
|
CHECK_DIE(ifs) << "no such file or directory: " << filename; |
|
cmap->clear(); |
|
char *col[2]; |
|
@@ -46,7 +50,11 @@ bool build(std::map<std::string, int> *cmap, |
|
|
|
bool save(const char* filename, |
|
std::map<std::string, int> *cmap) { |
|
+#ifdef HAVE_BOOST |
|
+ iostreams_ofstream ofs(WPATH(filename)); |
|
+#else |
|
std::ofstream ofs(WPATH(filename)); |
|
+#endif |
|
CHECK_DIE(ofs) << "permission denied: " << filename; |
|
for (std::map<std::string, int>::const_iterator it = cmap->begin(); |
|
it != cmap->end(); ++it) { |
|
diff --git a/mecab/src/dictionary.cpp b/mecab/src/dictionary.cpp |
|
index f171dd4..afcac54 100644 |
|
--- a/mecab/src/dictionary.cpp |
|
+++ b/mecab/src/dictionary.cpp |
|
@@ -192,7 +192,11 @@ bool Dictionary::assignUserDictionaryCosts( |
|
CHECK_DIE(ofs) << "permission denied: " << output; |
|
|
|
for (size_t i = 0; i < dics.size(); ++i) { |
|
+#ifdef HAVE_BOOST |
|
+ iostreams_ifstream ifs(WPATH(dics[i].c_str())); |
|
+#else |
|
std::ifstream ifs(WPATH(dics[i].c_str())); |
|
+#endif |
|
CHECK_DIE(ifs) << "no such file or directory: " << dics[i]; |
|
std::cout << "reading " << dics[i] << " ... "; |
|
scoped_fixed_array<char, BUF_SIZE> line; |
|
@@ -293,7 +297,11 @@ bool Dictionary::compile(const Param ¶m, |
|
std::istringstream iss(UNK_DEF_DEFAULT); |
|
|
|
for (size_t i = 0; i < dics.size(); ++i) { |
|
+#ifdef HAVE_BOOST |
|
+ iostreams_ifstream ifs(WPATH(dics[i].c_str())); |
|
+#else |
|
std::ifstream ifs(WPATH(dics[i].c_str())); |
|
+#endif |
|
std::istream *is = &ifs; |
|
if (!ifs) { |
|
if (type == MECAB_UNK_DIC) { |
|
@@ -495,7 +503,11 @@ bool Dictionary::compile(const Param ¶m, |
|
std::fill(charset, charset + sizeof(charset), '\0'); |
|
std::strncpy(charset, to.c_str(), 31); |
|
|
|
+#ifdef HAVE_BOOST |
|
+ iostreams_ofstream bofs(WPATH(output), std::ios::binary|std::ios::out); |
|
+#else |
|
std::ofstream bofs(WPATH(output), std::ios::binary|std::ios::out); |
|
+#endif |
|
CHECK_DIE(bofs) << "permission denied: " << output; |
|
|
|
unsigned int magic = 0; |
|
diff --git a/mecab/src/dictionary_generator.cpp b/mecab/src/dictionary_generator.cpp |
|
index fdbbf26..35dfeaa 100644 |
|
--- a/mecab/src/dictionary_generator.cpp |
|
+++ b/mecab/src/dictionary_generator.cpp |
|
@@ -25,7 +25,11 @@ void copy(const char *src, const char *dst) { |
|
std::cout << "copying " << src << " to " << dst << std::endl; |
|
Mmap<char> mmap; |
|
CHECK_DIE(mmap.open(src)) << mmap.what(); |
|
+#ifdef HAVE_BOOST |
|
+ iostreams_ofstream ofs(WPATH(dst), std::ios::binary|std::ios::out); |
|
+#else |
|
std::ofstream ofs(WPATH(dst), std::ios::binary|std::ios::out); |
|
+#endif |
|
CHECK_DIE(ofs) << "permission denied: " << dst; |
|
ofs.write(reinterpret_cast<char*>(mmap.begin()), mmap.size()); |
|
ofs.close(); |
|
@@ -44,7 +48,11 @@ class DictionaryGenerator { |
|
static void gencid(const char *filename, |
|
DictionaryRewriter *rewrite, |
|
ContextID *cid) { |
|
+#ifdef HAVE_BOOST |
|
+ iostreams_ifstream ifs(WPATH(filename)); |
|
+#else |
|
std::ifstream ifs(WPATH(filename)); |
|
+#endif |
|
CHECK_DIE(ifs) << "no such file or directory: " << filename; |
|
scoped_fixed_array<char, BUF_SIZE> line; |
|
std::cout << "reading " << filename << " ... " << std::flush; |
|
@@ -67,7 +75,11 @@ class DictionaryGenerator { |
|
const ContextID &cid, |
|
DecoderFeatureIndex *fi, |
|
int factor) { |
|
+#ifdef HAVE_BOOST |
|
+ iostreams_ofstream ofs(WPATH(filename)); |
|
+#else |
|
std::ofstream ofs(WPATH(filename)); |
|
+#endif |
|
CHECK_DIE(ofs) << "permission denied: " << filename; |
|
|
|
LearnerPath path; |
|
@@ -115,10 +127,18 @@ class DictionaryGenerator { |
|
DecoderFeatureIndex *fi, |
|
bool unk, |
|
int factor) { |
|
+#ifdef HAVE_BOOST |
|
+ iostreams_ifstream ifs(WPATH(ifile)); |
|
+#else |
|
std::ifstream ifs(WPATH(ifile)); |
|
+#endif |
|
CHECK_DIE(ifs) << "no such file or directory: " << ifile; |
|
|
|
+#ifdef HAVE_BOOST |
|
+ iostreams_ofstream ofs(WPATH(ofile)); |
|
+#else |
|
std::ofstream ofs(WPATH(ofile)); |
|
+#endif |
|
CHECK_DIE(ofs) << "permission denied: " << ofile; |
|
|
|
std::cout << "emitting " << ofile << " ... " << std::flush; |
|
diff --git a/mecab/src/dictionary_rewriter.cpp b/mecab/src/dictionary_rewriter.cpp |
|
index 583b089..3bb397c 100644 |
|
--- a/mecab/src/dictionary_rewriter.cpp |
|
+++ b/mecab/src/dictionary_rewriter.cpp |
|
@@ -132,7 +132,11 @@ void DictionaryRewriter::clear() { cache_.clear(); } |
|
|
|
bool DictionaryRewriter::open(const char *filename, |
|
Iconv *iconv) { |
|
+#ifdef HAVE_BOOST |
|
+ iostreams_ifstream ifs(WPATH(filename)); |
|
+#else |
|
std::ifstream ifs(WPATH(filename)); |
|
+#endif |
|
CHECK_DIE(ifs) << "no such file or directory: " << filename; |
|
int append_to = 0; |
|
std::string line; |
|
@@ -201,7 +205,11 @@ bool DictionaryRewriter::rewrite2(const std::string &feature, |
|
|
|
bool POSIDGenerator::open(const char *filename, |
|
Iconv *iconv) { |
|
+#ifdef HAVE_BOOST |
|
+ iostreams_ifstream ifs(WPATH(filename)); |
|
+#else |
|
std::ifstream ifs(WPATH(filename)); |
|
+#endif |
|
if (!ifs) { |
|
std::cerr << filename |
|
<< " is not found. minimum setting is used" << std::endl; |
|
diff --git a/mecab/src/eval.cpp b/mecab/src/eval.cpp |
|
index 3e2f9bd..dd15c95 100644 |
|
--- a/mecab/src/eval.cpp |
|
+++ b/mecab/src/eval.cpp |
|
@@ -123,8 +123,13 @@ class Eval { |
|
|
|
const std::string level_str = param.get<std::string>("level"); |
|
|
|
+#ifdef HAVE_BOOST |
|
+ iostreams_ifstream ifs1(WPATH(files[0].c_str())); |
|
+ iostreams_ifstream ifs2(WPATH(files[1].c_str())); |
|
+#else |
|
std::ifstream ifs1(WPATH(files[0].c_str())); |
|
std::ifstream ifs2(WPATH(files[1].c_str())); |
|
+#endif |
|
|
|
CHECK_DIE(ifs1) << "no such file or directory: " << files[0].c_str(); |
|
CHECK_DIE(ifs2) << "no such file or directory: " << files[0].c_str(); |
|
diff --git a/mecab/src/feature_index.cpp b/mecab/src/feature_index.cpp |
|
index 051bdf8..062ef3a 100644 |
|
--- a/mecab/src/feature_index.cpp |
|
+++ b/mecab/src/feature_index.cpp |
|
@@ -77,7 +77,11 @@ void FeatureIndex::set_alpha(const double *alpha) { |
|
bool FeatureIndex::openTemplate(const Param ¶m) { |
|
std::string filename = create_filename(param.get<std::string>("dicdir"), |
|
FEATURE_FILE); |
|
+#ifdef HAVE_BOOST |
|
+ iostreams_ifstream ifs(WPATH(filename.c_str())); |
|
+#else |
|
std::ifstream ifs(WPATH(filename.c_str())); |
|
+#endif |
|
CHECK_DIE(ifs) << "no such file or directory: " << filename; |
|
|
|
scoped_fixed_array<char, BUF_SIZE> buf; |
|
@@ -529,7 +533,11 @@ bool FeatureIndex::compile(const Param ¶m, |
|
const char* txtfile, const char *binfile) { |
|
std::string buf; |
|
FeatureIndex::convert(param, txtfile, &buf); |
|
+#ifdef HAVE_BOOST |
|
+ iostreams_ofstream ofs(WPATH(binfile), std::ios::binary|std::ios::out); |
|
+#else |
|
std::ofstream ofs(WPATH(binfile), std::ios::binary|std::ios::out); |
|
+#endif |
|
CHECK_DIE(ofs) << "permission denied: " << binfile; |
|
ofs.write(buf.data(), buf.size()); |
|
return true; |
|
@@ -537,7 +545,11 @@ bool FeatureIndex::compile(const Param ¶m, |
|
|
|
bool FeatureIndex::convert(const Param ¶m, |
|
const char* txtfile, std::string *output) { |
|
+#ifdef HAVE_FILESYSTEM |
|
+ iostreams_ifstream ifs(WPATH(txtfile)); |
|
+#else |
|
std::ifstream ifs(WPATH(txtfile)); |
|
+#endif |
|
CHECK_DIE(ifs) << "no such file or directory: " << txtfile; |
|
scoped_fixed_array<char, BUF_SIZE> buf; |
|
char *column[4]; |
|
@@ -618,7 +630,11 @@ bool EncoderFeatureIndex::reopen(const char *filename, |
|
std::vector<double> *alpha, |
|
Param *param) { |
|
close(); |
|
+#ifdef HAVE_FILESYSTEM |
|
+ iostreams_ifstream ifs(WPATH(filename)); |
|
+#else |
|
std::ifstream ifs(WPATH(filename)); |
|
+#endif |
|
if (!ifs) { |
|
return false; |
|
} |
|
@@ -669,7 +685,11 @@ bool EncoderFeatureIndex::save(const char *filename, const char *header) const { |
|
CHECK_DIE(header); |
|
CHECK_DIE(alpha_); |
|
|
|
+#ifdef HAVE_FILESYSTEM |
|
+ iostreams_ofstream ofs(WPATH(filename)); |
|
+#else |
|
std::ofstream ofs(WPATH(filename)); |
|
+#endif |
|
if (!ofs) { |
|
return false; |
|
} |
|
diff --git a/mecab/src/learner.cpp b/mecab/src/learner.cpp |
|
index 187640c..2d5488a 100644 |
|
--- a/mecab/src/learner.cpp |
|
+++ b/mecab/src/learner.cpp |
|
@@ -108,7 +108,11 @@ class CRFLearner { |
|
|
|
std::cout << "reading corpus ..." << std::flush; |
|
|
|
+#ifdef HAVE_BOOST |
|
+ iostreams_ifstream ifs(WPATH(ifile.c_str())); |
|
+#else |
|
std::ifstream ifs(WPATH(ifile.c_str())); |
|
+#endif |
|
CHECK_DIE(ifs) << "no such file or directory: " << ifile; |
|
|
|
while (ifs) { |
|
diff --git a/mecab/src/param.cpp b/mecab/src/param.cpp |
|
index 65328a2..b46ac2b 100644 |
|
--- a/mecab/src/param.cpp |
|
+++ b/mecab/src/param.cpp |
|
@@ -64,7 +64,11 @@ void Param::dump_config(std::ostream *os) const { |
|
} |
|
|
|
bool Param::load(const char *filename) { |
|
+#ifdef HAVE_BOOST |
|
+ iostreams_ifstream ifs(WPATH(filename)); |
|
+#else |
|
std::ifstream ifs(WPATH(filename)); |
|
+#endif |
|
|
|
CHECK_FALSE(ifs) << "no such file or directory: " << filename; |
|
|
|
diff --git a/mecab/src/stream_wrapper.h b/mecab/src/stream_wrapper.h |
|
index b2b9666..a64729a 100644 |
|
--- a/mecab/src/stream_wrapper.h |
|
+++ b/mecab/src/stream_wrapper.h |
|
@@ -15,6 +15,10 @@ namespace MeCab { |
|
|
|
class istream_wrapper { |
|
private: |
|
+#ifdef HAVE_BOOST |
|
+ boost::iostreams::filtering_streambuf<boost::iostreams::input> filter; |
|
+ boost::filesystem::ifstream* ifs_; |
|
+#endif |
|
std::istream* is_; |
|
public: |
|
std::istream &operator*() const { return *is_; } |
|
@@ -23,17 +27,30 @@ class istream_wrapper { |
|
if (std::strcmp(filename, "-") == 0) { |
|
is_ = &std::cin; |
|
} else { |
|
+#ifdef HAVE_BOOST |
|
+ ifs_ = new boost::filesystem::ifstream(boost::filesystem::path(WPATH(filename))); |
|
+ filter.push(*ifs_); |
|
+ is_ = new std::istream(&filter); |
|
+#else |
|
is_ = new std::ifstream(WPATH(filename)); |
|
+#endif |
|
} |
|
} |
|
|
|
virtual ~istream_wrapper() { |
|
if (is_ != &std::cin) delete is_; |
|
+#ifdef HAVE_BOOST |
|
+ delete ifs_; |
|
+#endif |
|
} |
|
}; |
|
|
|
class ostream_wrapper { |
|
private: |
|
+#ifdef HAVE_BOOST |
|
+ boost::iostreams::filtering_streambuf<boost::iostreams::output> filter; |
|
+ boost::filesystem::ofstream* ofs_; |
|
+#endif |
|
std::ostream* os_; |
|
public: |
|
std::ostream &operator*() const { return *os_; } |
|
@@ -42,12 +59,21 @@ class ostream_wrapper { |
|
if (std::strcmp(filename, "-") == 0) { |
|
os_ = &std::cout; |
|
} else { |
|
+#ifdef HAVE_BOOST |
|
+ ofs_ = new boost::filesystem::ofstream(boost::filesystem::path(WPATH(filename))); |
|
+ filter.push(*ofs_); |
|
+ os_ = new std::ostream(&filter); |
|
+#else |
|
os_ = new std::ofstream(WPATH(filename)); |
|
+#endif |
|
} |
|
} |
|
|
|
virtual ~ostream_wrapper() { |
|
if (os_ != &std::cout) delete os_; |
|
+#ifdef HAVE_BOOST |
|
+ delete ofs_; |
|
+#endif |
|
} |
|
}; |
|
} |
|
diff --git a/mecab/src/utils.cpp b/mecab/src/utils.cpp |
|
index fe86657..c2a05c8 100644 |
|
--- a/mecab/src/utils.cpp |
|
+++ b/mecab/src/utils.cpp |
|
@@ -298,7 +298,11 @@ bool load_dictionary_resource(Param *param) { |
|
if (homedir) { |
|
const std::string s = MeCab::create_filename(std::string(homedir), |
|
".mecabrc"); |
|
+#ifdef HAVE_BOOST |
|
+ iostreams_ifstream ifs(WPATH(s.c_str())); |
|
+#else |
|
std::ifstream ifs(WPATH(s.c_str())); |
|
+#endif |
|
if (ifs) { |
|
rcfile = s; |
|
} |
|
@@ -554,7 +558,11 @@ uint64_t fingerprint(const std::string &str) { |
|
} |
|
|
|
bool file_exists(const char *filename) { |
|
+#ifdef HAVE_BOOST |
|
+ iostreams_ifstream ifs(WPATH(filename)); |
|
+#else |
|
std::ifstream ifs(WPATH(filename)); |
|
+#endif |
|
if (!ifs) { |
|
return false; |
|
} |