unique-csa.cc
Go to the documentation of this file.
00001 #include "osl/container/moveVector.h"
00002 #include "osl/record/csaRecord.h"
00003 #include "osl/record/checkDuplicate.h"
00004 #include <boost/algorithm/string/trim.hpp>
00005 #include <boost/foreach.hpp>
00006 #include <boost/program_options.hpp>
00007 #include <iostream>
00008 #include <string>
00009 #include <vector>
00010 
00015 bool readFile(const std::string& csa_file,
00016               osl::record::CheckDuplicate& duplicates)
00017 {
00018   const osl::record::csa::CsaFile csa(csa_file);
00019   const osl::record::Record& record = csa.getRecord();
00020   const osl::vector<osl::Move> moves = record.getMoves();
00021  
00022   return !duplicates.regist(moves);
00023 }
00024 
00025 
00026 int main(int argc, char **argv)
00027 {
00028   namespace bp = boost::program_options;
00029 
00030   bp::options_description command_line_options;
00031   command_line_options.add_options()
00032     ("input-file", bp::value<std::vector<std::string> >(),
00033      "input files in the CSA format")
00034     ("help", "Show help message");
00035   bp::variables_map vm;
00036   bp::positional_options_description p;
00037   p.add("input-file", -1);
00038 
00039   try {
00040     bp::store(
00041       bp::command_line_parser(argc, argv).options(command_line_options).positional(p).run(), vm);
00042     bp::notify(vm);
00043     if (vm.count("help")) {
00044       std::cerr << "Filter duplicated records from specified CSA files.\n";
00045       std::cerr << "Usage: " << argv[0] << " [options] csa-file [...]\n";
00046       std::cerr << "       " << argv[0] << " [options]\n";
00047       std::cout << command_line_options << std::endl;
00048       return 0;
00049     }
00050   } catch (std::exception &e) {
00051     std::cerr << "error in parsing options" << std::endl
00052               << e.what() << std::endl;
00053     std::cerr << "Filter duplicated records from specified CSA files.\n";
00054     std::cerr << "Usage: " << argv[0] << " [options] csa-file [...]\n";
00055     std::cerr << "       " << argv[0] << " [options]\n";
00056     std::cerr << command_line_options << std::endl;
00057     return 1;
00058   }
00059 
00060   std::vector<std::string> files;
00061   if (vm.count("input-file")) {
00062     const std::vector<std::string> temp = vm["input-file"].as<std::vector<std::string> >();
00063     files.insert(files.end(), temp.begin(), temp.end());
00064   } else {
00065     std::string line;
00066     while(std::getline(std::cin , line)) {
00067       boost::algorithm::trim(line);
00068       files.push_back(line);
00069     }
00070   }
00071 
00072   osl::record::CheckDuplicate check_duplicate;
00073 
00074   BOOST_FOREACH(const std::string& file, files) {
00075     if (readFile(file, check_duplicate))
00076       std::cout << file << std::endl;
00077   }
00078 
00079   check_duplicate.print(std::cerr);
00080 
00081   return 0;
00082 }
00083 
00084 /* vim: set ts=2 sw=2 ft=cpp : */
00085 // ;;; Local Variables:
00086 // ;;; mode:c++
00087 // ;;; c-basic-offset:2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines