説明を見る。00001 #include "osl/record/record.h"
00002 #include "osl/record/kanjiCode.h"
00003 #include "osl/misc/eucToLang.h"
00004 #include <boost/algorithm/string/classification.hpp>
00005 #include <boost/algorithm/string/split.hpp>
00006 #include <boost/algorithm/string/replace.hpp>
00007 #include <stack>
00008 #include <iostream>
00009
00010 osl::record::Record::Record() : result(Unknown)
00011 {
00012 }
00013 osl::record::Record::~Record()
00014 {
00015 }
00016
00017 void osl::record::Record::setMoveComment(const std::string& msg)
00018 {
00019 if (moves().empty()) {
00020 addWithNewLine(initial_comment, msg);
00021 return;
00022 }
00023 comments.resize(moves().size());
00024 comments.back() = msg;
00025 }
00026 void osl::record::Record::setMoveInfo(const SearchInfo& info)
00027 {
00028 move_info.resize(moves().size());
00029 move_info.back() = info;
00030 }
00031 void osl::record::Record::setMoveTime(int s)
00032 {
00033 times.resize(moves().size());
00034 times.back() = s;
00035 }
00036
00037 void osl::record::Record::setDate(const std::string& date_str)
00038 {
00039 std::vector<std::string> values;
00040 boost::algorithm::split(values, date_str, boost::algorithm::is_any_of("/"));
00041 if (values.size() < 3) {
00042 std::cerr << "ERROR: Invalid date format found: "
00043 #ifndef MINIMAL
00044 << misc::eucToLang(date_str)
00045 #endif
00046 << "\n";
00047 return;
00048 } else if (values.size() > 3) {
00049 std::cerr << "WARNING: Invalid date format found: "
00050 #ifndef MINIMAL
00051 << misc::eucToLang(date_str)
00052 #endif
00053 << "\n";
00054
00055 }
00056 for (std::string& value: values) {
00057 static const CArray<const char *,9> kanji = {{
00058 K_R1, K_R2, K_R3, K_R4, K_R5, K_R6, K_R7, K_R8, K_R9,
00059 }};
00060 for (size_t i=0; i<kanji.size(); ++i)
00061 boost::algorithm::replace_all(value, kanji[i], std::string(1, char('0'+i)));
00062 }
00063 int year = 0;
00064 int month = 0;
00065 int day = 0;
00066 try {
00067 year = stoi(values[0]);
00068 month = stoi(values[1]);
00069 if (month == 0) month = 1;
00070 if ("??" == values[2]) {
00071 std::cerr << "WARNING: Invalid date format found: "
00072 #ifndef MINIMAL
00073 << misc::eucToLang(values[2])
00074 #endif
00075 << "\n";
00076
00077 day = 1;
00078 } else if (values[2].size() > 2) {
00079 std::cerr << "WARNING: Invalid date format found: "
00080 #ifndef MINIMAL
00081 << misc::eucToLang(values[2])
00082 #endif
00083 << "\n";
00084
00085 day = stoi(values[2].substr(0,2));
00086 } else {
00087 day = stoi(values[2]);
00088 }
00089 if (day == 0) day = 1;
00090 start_date = boost::gregorian::date(year, month, day);
00091 assert(!start_date.is_special());
00092 }
00093 catch (boost::gregorian::bad_day_of_month& ebdm) {
00094 std::cerr << "Bad day of month: "
00095 #ifndef MINIMAL
00096 << misc::eucToLang(date_str)
00097 #endif
00098 << "\n"
00099 << ebdm.what() << std::endl;
00100 }
00101 catch (std::exception& e) {
00102 std::cerr << "Invalid date format found: "
00103 #ifndef MINIMAL
00104 << misc::eucToLang(date_str)
00105 #endif
00106 << "\n"
00107 << e.what() << std::endl;
00108 }
00109 return;
00110 }
00111
00112 #ifndef MINIMAL
00113 std::ostream& osl::record::operator<<(std::ostream& os, const Record & r){
00114 os << "Record(";
00115 os << "version=" << r.version
00116 << ",BLACK=" << r.player[BLACK]
00117 << ",WHITE=" << r.player[WHITE];
00118 os << ",initial=" << std:: endl << r.record.initial_state << std::endl;
00119 NumEffectState state(r.record.initial_state);
00120 for (auto& m: r.record.moves) os << m;
00121 return os << ')';
00122 }
00123 #endif
00124
00125
00126 osl::record::RecordFile::~RecordFile()
00127 {
00128 }
00129
00130
00131
00132
00133