record.cc
Go to the documentation of this file.
#include "osl/record/record.h"
#include "osl/record/kanjiCode.h"
#include "osl/misc/eucToLang.h"
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <stack>
#include <iostream>
osl::record::Record::Record() : result(Unknown)
{
}
osl::record::Record::~Record()
{
}
void osl::record::Record::setMoveComment(const std::string& msg)
{
if (moves().empty()) {
addWithNewLine(initial_comment, msg);
return;
}
comments.resize(moves().size());
comments.back() = msg;
}
void osl::record::Record::setMoveInfo(const SearchInfo& info)
{
move_info.resize(moves().size());
if (!move_info.empty()) {
move_info.back() = info;
}
}
void osl::record::Record::setMoveTime(int s)
{
times.resize(moves().size());
times.back() = s;
}
void osl::record::Record::setDate(const std::string& date_str)
{
std::vector<std::string> values;
boost::algorithm::split(values, date_str, boost::algorithm::is_any_of("/"));
if (values.size() < 3) {
std::cerr << "ERROR: Invalid date format found: "
#ifndef MINIMAL
<< misc::eucToLang(date_str)
#endif
<< "\n";
return;
} else if (values.size() > 3) {
std::cerr << "WARNING: Invalid date format found: "
#ifndef MINIMAL
<< misc::eucToLang(date_str)
#endif
<< "\n";
// go through
}
for (std::string& value: values) {
static const CArray<const char *,9> kanji = {{
K_R1, K_R2, K_R3, K_R4, K_R5, K_R6, K_R7, K_R8, K_R9,
}};
for (size_t i=0; i<kanji.size(); ++i)
boost::algorithm::replace_all(value, kanji[i], std::string(1, char('0'+i)));
}
int year = 0;
int month = 0;
int day = 0;
try {
year = stoi(values[0]);
month = stoi(values[1]);
if (month == 0) month = 1;
if ("??" == values[2]) {
std::cerr << "WARNING: Invalid date format found: "
#ifndef MINIMAL
<< misc::eucToLang(values[2])
#endif
<< "\n";
// go through
day = 1;
} else if (values[2].size() > 2) {
std::cerr << "WARNING: Invalid date format found: "
#ifndef MINIMAL
<< misc::eucToLang(values[2])
#endif
<< "\n";
// go through
day = stoi(values[2].substr(0,2));
} else {
day = stoi(values[2]);
}
if (day == 0) day = 1;
start_date = boost::gregorian::date(year, month, day);
assert(!start_date.is_special());
}
catch (boost::gregorian::bad_day_of_month& ebdm) {
std::cerr << "Bad day of month: "
#ifndef MINIMAL
<< misc::eucToLang(date_str)
#endif
<< "\n"
<< ebdm.what() << std::endl;
}
catch (std::exception& e) {
std::cerr << "Invalid date format found: "
#ifndef MINIMAL
<< misc::eucToLang(date_str)
#endif
<< "\n"
<< e.what() << std::endl;
}
return;
}
#ifndef MINIMAL
std::ostream& osl::record::operator<<(std::ostream& os, const Record & r){
os << "Record(";
os << "version=" << r.version
<< ",BLACK=" << r.player[BLACK]
<< ",WHITE=" << r.player[WHITE];
os << ",initial=" << std:: endl << r.record.initial_state << std::endl;
NumEffectState state(r.record.initial_state);
for (auto& m: r.record.moves) os << m;
return os << ')';
}
#endif
␌
osl::record::RecordFile::~RecordFile()
{
}
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::CArray
Definition container.h:20
osl::CArray::size
static size_t size()
Definition container.h:76
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::record::RecordFile::~RecordFile
virtual ~RecordFile()
Definition record.cc:128
eucToLang.h
kanjiCode.h
K_R4
#define K_R4
Definition kanjiCode.h:21
K_R2
#define K_R2
Definition kanjiCode.h:19
K_R5
#define K_R5
Definition kanjiCode.h:22
K_R8
#define K_R8
Definition kanjiCode.h:25
K_R7
#define K_R7
Definition kanjiCode.h:24
K_R6
#define K_R6
Definition kanjiCode.h:23
K_R3
#define K_R3
Definition kanjiCode.h:20
K_R9
#define K_R9
Definition kanjiCode.h:26
K_R1
#define K_R1
Definition kanjiCode.h:18
osl::misc::eucToLang
std::string eucToLang(const std::string &src)
Definition eucToLang.cc:14
osl::record::operator<<
std::ostream & operator<<(std::ostream &os, const Color &c)
Definition kanjiPrint.cc:156
osl::WHITE
@ WHITE
Definition basic_type.h:10
osl::BLACK
@ BLACK
Definition basic_type.h:9
record.h
osl::RecordMinimal::initial_state
NumEffectState initial_state
Definition csa.h:44
osl::RecordMinimal::moves
std::vector< Move > moves
Definition csa.h:45
osl::record::Record
Definition record.h:15
osl::record::Record::record
RecordMinimal record
Definition record.h:16
osl::record::Record::result
ResultType result
Definition record.h:30
osl::record::Record::version
std::string version
Definition record.h:28
osl::record::Record::Record
Record()
Definition record.cc:10
osl::record::Record::~Record
~Record()
Definition record.cc:13
osl::record::Record::addWithNewLine
static void addWithNewLine(std::string &a, const std::string &b)
Definition record.h:35
osl::record::Record::Unknown
@ Unknown
Definition record.h:18
osl::record::Record::initial_comment
std::string initial_comment
Definition record.h:28
osl::record::Record::setMoveInfo
void setMoveInfo(const SearchInfo &)
Definition record.cc:26
osl::record::Record::moves
std::vector< Move > moves() const
Definition record.h:41
osl::record::Record::times
std::vector< int > times
Definition record.h:24
osl::record::Record::setMoveTime
void setMoveTime(int)
Definition record.cc:33
osl::record::Record::setDate
void setDate(const std::string &date_str)
Definition record.cc:39
osl::record::Record::setMoveComment
void setMoveComment(const std::string &)
Definition record.cc:17
osl::record::Record::player
CArray< std::string, 2 > player
Definition record.h:29
osl::record::Record::move_info
std::vector< SearchInfo > move_info
Definition record.h:26
osl::record::Record::comments
std::vector< std::string > comments
Definition record.h:25
osl::record::Record::start_date
boost::gregorian::date start_date
Definition record.h:31
osl::record::SearchInfo
Definition searchInfo.h:15