record.cc
Go to the documentation of this file.
1 #include "osl/record/record.h"
2 #include "osl/record/kanjiCode.h"
3 #include "osl/misc/eucToLang.h"
4 #include <boost/algorithm/string/classification.hpp>
5 #include <boost/algorithm/string/split.hpp>
6 #include <boost/algorithm/string/replace.hpp>
7 #include <stack>
8 #include <iostream>
9 
10 osl::record::Record::Record() : result(Unknown)
11 {
12 }
14 {
15 }
16 
17 void osl::record::Record::setMoveComment(const std::string& msg)
18 {
19  if (moves().empty()) {
21  return;
22  }
23  comments.resize(moves().size());
24  comments.back() = msg;
25 }
27 {
28  move_info.resize(moves().size());
29  if (!move_info.empty()) {
30  move_info.back() = info;
31  }
32 }
34 {
35  times.resize(moves().size());
36  times.back() = s;
37 }
38 
39 void osl::record::Record::setDate(const std::string& date_str)
40 {
41  std::vector<std::string> values;
42  boost::algorithm::split(values, date_str, boost::algorithm::is_any_of("/"));
43  if (values.size() < 3) {
44  std::cerr << "ERROR: Invalid date format found: "
45 #ifndef MINIMAL
46  << misc::eucToLang(date_str)
47 #endif
48  << "\n";
49  return;
50  } else if (values.size() > 3) {
51  std::cerr << "WARNING: Invalid date format found: "
52 #ifndef MINIMAL
53  << misc::eucToLang(date_str)
54 #endif
55  << "\n";
56  // go through
57  }
58  for (std::string& value: values) {
59  static const CArray<const char *,9> kanji = {{
60  K_R1, K_R2, K_R3, K_R4, K_R5, K_R6, K_R7, K_R8, K_R9,
61  }};
62  for (size_t i=0; i<kanji.size(); ++i)
63  boost::algorithm::replace_all(value, kanji[i], std::string(1, char('0'+i)));
64  }
65  int year = 0;
66  int month = 0;
67  int day = 0;
68  try {
69  year = stoi(values[0]);
70  month = stoi(values[1]);
71  if (month == 0) month = 1;
72  if ("??" == values[2]) {
73  std::cerr << "WARNING: Invalid date format found: "
74 #ifndef MINIMAL
75  << misc::eucToLang(values[2])
76 #endif
77  << "\n";
78  // go through
79  day = 1;
80  } else if (values[2].size() > 2) {
81  std::cerr << "WARNING: Invalid date format found: "
82 #ifndef MINIMAL
83  << misc::eucToLang(values[2])
84 #endif
85  << "\n";
86  // go through
87  day = stoi(values[2].substr(0,2));
88  } else {
89  day = stoi(values[2]);
90  }
91  if (day == 0) day = 1;
92  start_date = boost::gregorian::date(year, month, day);
93  assert(!start_date.is_special());
94  }
95  catch (boost::gregorian::bad_day_of_month& ebdm) {
96  std::cerr << "Bad day of month: "
97 #ifndef MINIMAL
98  << misc::eucToLang(date_str)
99 #endif
100  << "\n"
101  << ebdm.what() << std::endl;
102  }
103  catch (std::exception& e) {
104  std::cerr << "Invalid date format found: "
105 #ifndef MINIMAL
106  << misc::eucToLang(date_str)
107 #endif
108  << "\n"
109  << e.what() << std::endl;
110  }
111  return;
112 }
113 
114 #ifndef MINIMAL
115 std::ostream& osl::record::operator<<(std::ostream& os, const Record & r){
116  os << "Record(";
117  os << "version=" << r.version
118  << ",BLACK=" << r.player[BLACK]
119  << ",WHITE=" << r.player[WHITE];
120  os << ",initial=" << std:: endl << r.record.initial_state << std::endl;
122  for (auto& m: r.record.moves) os << m;
123  return os << ')';
124 }
125 #endif
126 
127 
129 {
130 }
131 
132 // ;;; Local Variables:
133 // ;;; mode:c++
134 // ;;; c-basic-offset:2
135 // ;;; End:
std::string initial_comment
Definition: record.h:28
RecordMinimal record
Definition: record.h:16
CArray< std::string, 2 > player
Definition: record.h:29
std::vector< SearchInfo > move_info
Definition: record.h:26
#define K_R4
Definition: kanjiCode.h:21
static void addWithNewLine(std::string &a, const std::string &b)
Definition: record.h:35
virtual ~RecordFile()
Definition: record.cc:128
NumEffectState initial_state
Definition: csa.h:44
#define K_R9
Definition: kanjiCode.h:26
std::vector< std::string > comments
Definition: record.h:25
#define K_R3
Definition: kanjiCode.h:20
#define K_R7
Definition: kanjiCode.h:24
std::vector< int > times
Definition: record.h:24
#define K_R1
Definition: kanjiCode.h:18
#define K_R2
Definition: kanjiCode.h:19
void setMoveTime(int)
Definition: record.cc:33
#define K_R8
Definition: kanjiCode.h:25
#define K_R5
Definition: kanjiCode.h:22
std::string eucToLang(const std::string &src)
Definition: eucToLang.cc:14
#define K_R6
Definition: kanjiCode.h:23
利きを持つ局面
std::vector< Move > moves() const
Definition: record.h:41
std::ostream & operator<<(std::ostream &os, const Color &c)
Definition: kanjiPrint.cc:156
void setDate(const std::string &date_str)
Definition: record.cc:39
boost::gregorian::date start_date
Definition: record.h:31
std::vector< Move > moves
Definition: csa.h:45
void setMoveComment(const std::string &)
Definition: record.cc:17
static size_t size()
Definition: container.h:76
std::string version
Definition: record.h:28
void setMoveInfo(const SearchInfo &)
Definition: record.cc:26