00001 #include "tool.h"
00002
00003 #include <cstdlib>
00004 #include <iostream>
00005 #include <sstream>
00006
00007 #include <boost/program_options/cmdline.hpp>
00008
00009 namespace MosesTraining {
00010 namespace Syntax {
00011
00012 int Tool::MosesOptionStyle() {
00013 namespace cls = boost::program_options::command_line_style;
00014 return cls::allow_long | cls::long_allow_adjacent | cls::long_allow_next;
00015 }
00016
00017 void Tool::Warn(const std::string &msg) const {
00018 std::cerr << name_ << ": warning: " << msg << std::endl;
00019 }
00020
00021 void Tool::Error(const std::string &msg) const {
00022 std::cerr << name_ << ": error: " << msg << std::endl;
00023 std::exit(1);
00024 }
00025
00026 void Tool::OpenInputFileOrDie(const std::string &filename,
00027 std::ifstream &stream) {
00028 stream.open(filename.c_str());
00029 if (!stream) {
00030 std::ostringstream msg;
00031 msg << "failed to open input file: " << filename;
00032 Error(msg.str());
00033 }
00034 }
00035
00036 void Tool::OpenOutputFileOrDie(const std::string &filename,
00037 std::ofstream &stream) {
00038 stream.open(filename.c_str());
00039 if (!stream) {
00040 std::ostringstream msg;
00041 msg << "failed to open output file: " << filename;
00042 Error(msg.str());
00043 }
00044 }
00045
00046 void Tool::OpenOutputFileOrDie(const std::string &filename,
00047 Moses::OutputFileStream &stream) {
00048 bool ret = stream.Open(filename);
00049 if (!ret) {
00050 std::ostringstream msg;
00051 msg << "failed to open output file: " << filename;
00052 Error(msg.str());
00053 }
00054 }
00055
00056 }
00057 }