elo-ratings 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +22 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +23 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/elo-ratings.gemspec +148 -0
- data/ext/bayeselo/.gitignore +4 -0
- data/ext/bayeselo/CBradleyTerry.cpp +670 -0
- data/ext/bayeselo/CBradleyTerry.h +137 -0
- data/ext/bayeselo/CCDistribution.cpp +135 -0
- data/ext/bayeselo/CCDistribution.h +44 -0
- data/ext/bayeselo/CCDistributionCUI.cpp +104 -0
- data/ext/bayeselo/CCDistributionCUI.h +38 -0
- data/ext/bayeselo/CCondensedResults.cpp +253 -0
- data/ext/bayeselo/CCondensedResults.h +64 -0
- data/ext/bayeselo/CDiscretization.h +40 -0
- data/ext/bayeselo/CDistribution.cpp +123 -0
- data/ext/bayeselo/CDistribution.h +58 -0
- data/ext/bayeselo/CDistributionCollection.cpp +34 -0
- data/ext/bayeselo/CDistributionCollection.h +29 -0
- data/ext/bayeselo/CEloRatingCUI.cpp +1046 -0
- data/ext/bayeselo/CEloRatingCUI.h +67 -0
- data/ext/bayeselo/CIndirectCompare.h +28 -0
- data/ext/bayeselo/CJointBayesian.cpp +111 -0
- data/ext/bayeselo/CJointBayesian.h +38 -0
- data/ext/bayeselo/CLUDecomposition.cpp +154 -0
- data/ext/bayeselo/CLUDecomposition.h +36 -0
- data/ext/bayeselo/CMatrix.cpp +48 -0
- data/ext/bayeselo/CMatrix.h +35 -0
- data/ext/bayeselo/CMatrixIO.cpp +27 -0
- data/ext/bayeselo/CMatrixIO.h +17 -0
- data/ext/bayeselo/CPredictionCUI.cpp +393 -0
- data/ext/bayeselo/CPredictionCUI.h +50 -0
- data/ext/bayeselo/CResultSet.cpp +245 -0
- data/ext/bayeselo/CResultSet.h +50 -0
- data/ext/bayeselo/CResultSetCUI.cpp +355 -0
- data/ext/bayeselo/CResultSetCUI.h +44 -0
- data/ext/bayeselo/CTimeIO.cpp +58 -0
- data/ext/bayeselo/CTimeIO.h +19 -0
- data/ext/bayeselo/CVector.cpp +110 -0
- data/ext/bayeselo/CVector.h +42 -0
- data/ext/bayeselo/EloDataFromFile.cpp +120 -0
- data/ext/bayeselo/EloDataFromFile.h +21 -0
- data/ext/bayeselo/README +8 -0
- data/ext/bayeselo/ReadLineToString.cpp +32 -0
- data/ext/bayeselo/ReadLineToString.h +18 -0
- data/ext/bayeselo/chtime.cpp +56 -0
- data/ext/bayeselo/chtime.h +61 -0
- data/ext/bayeselo/chtimer.h +27 -0
- data/ext/bayeselo/clktimer.cpp +178 -0
- data/ext/bayeselo/clktimer.h +29 -0
- data/ext/bayeselo/consolui.cpp +538 -0
- data/ext/bayeselo/consolui.h +154 -0
- data/ext/bayeselo/const.cpp +79 -0
- data/ext/bayeselo/const.h +42 -0
- data/ext/bayeselo/date.cpp +96 -0
- data/ext/bayeselo/date.h +44 -0
- data/ext/bayeselo/debug.h +58 -0
- data/ext/bayeselo/elomain.cpp +26 -0
- data/ext/bayeselo/extconf.rb +6 -0
- data/ext/bayeselo/list.h +367 -0
- data/ext/bayeselo/listi.h +125 -0
- data/ext/bayeselo/move.cpp +249 -0
- data/ext/bayeselo/move.h +139 -0
- data/ext/bayeselo/pgn.h +62 -0
- data/ext/bayeselo/pgnlex.cpp +432 -0
- data/ext/bayeselo/pgnlex.h +105 -0
- data/ext/bayeselo/pgnstr.cpp +126 -0
- data/ext/bayeselo/piece.h +44 -0
- data/ext/bayeselo/player.h +31 -0
- data/ext/bayeselo/position.h +89 -0
- data/ext/bayeselo/random.cpp +114 -0
- data/ext/bayeselo/random.h +63 -0
- data/ext/bayeselo/rb_bayeselo.cpp +76 -0
- data/ext/bayeselo/readstr.cpp +51 -0
- data/ext/bayeselo/readstr.h +19 -0
- data/ext/bayeselo/square.h +61 -0
- data/ext/bayeselo/str.cpp +81 -0
- data/ext/bayeselo/str.h +71 -0
- data/ext/bayeselo/version.cpp +30 -0
- data/ext/bayeselo/version.h +28 -0
- data/ext/bayeselo/version_number.h +1 -0
- data/lib/bayeselo.rb +6 -0
- data/lib/bayeselo/bayeselo.rb +11 -0
- data/lib/bayeselo/c_bayeselo.rb +7 -0
- data/test/bayeselo/test_bayeselo.rb +33 -0
- data/test/bayeselo/test_c_bayeselo.rb +84 -0
- data/test/helper.rb +18 -0
- metadata +226 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
//
|
|
3
|
+
// consolui.h
|
|
4
|
+
//
|
|
5
|
+
// CConsoleUI class declaration
|
|
6
|
+
//
|
|
7
|
+
// This class is an abstract class, used to define console user interfaces.
|
|
8
|
+
// It is typically used by adding a pointer to a class, and overriding the
|
|
9
|
+
// ProcessCommand member function to process commands on this class.
|
|
10
|
+
// See classes that inherit from CConsoleUI to find examples demonstrating
|
|
11
|
+
// how to do so.
|
|
12
|
+
//
|
|
13
|
+
// Remi Coulom
|
|
14
|
+
//
|
|
15
|
+
// june 1996
|
|
16
|
+
//
|
|
17
|
+
////////////////////////////////////////////////////////////////////////////
|
|
18
|
+
#ifndef CONSOLUI_H
|
|
19
|
+
#define CONSOLUI_H
|
|
20
|
+
|
|
21
|
+
#include <iosfwd>
|
|
22
|
+
|
|
23
|
+
#include "list.h" // CList<>
|
|
24
|
+
|
|
25
|
+
class CConsoleUI //cui
|
|
26
|
+
{
|
|
27
|
+
private: //////////////////////////////////////////////////////////////////
|
|
28
|
+
//
|
|
29
|
+
// private data
|
|
30
|
+
//
|
|
31
|
+
static const int BufferSize;
|
|
32
|
+
static const char * const tszCommands[];
|
|
33
|
+
|
|
34
|
+
CList<CConsoleUI *> lpcuiChildren;
|
|
35
|
+
CConsoleUI *pcuiParent;
|
|
36
|
+
int fPrompt;
|
|
37
|
+
const int openmode;
|
|
38
|
+
|
|
39
|
+
//
|
|
40
|
+
// private functions
|
|
41
|
+
//
|
|
42
|
+
void Parse(char *pszCommand,
|
|
43
|
+
const char *&pszCommand2,
|
|
44
|
+
const char *&pszParameters,
|
|
45
|
+
const char *&pszInput,
|
|
46
|
+
const char *&pszOutput) const;
|
|
47
|
+
|
|
48
|
+
void OpenChild(int Parameter, std::istream &in, std::ostream &out);
|
|
49
|
+
|
|
50
|
+
//
|
|
51
|
+
// Copy constructor and assignment operator do not work
|
|
52
|
+
//
|
|
53
|
+
// CConsoleUI(const CConsoleUI &cui): openmode(0)
|
|
54
|
+
// {const CConsoleUI *pcui = &cui; pcui = pcui;}
|
|
55
|
+
// CConsoleUI &operator=(const CConsoleUI &cui): openmode(0)
|
|
56
|
+
// {const CConsoleUI *pcui = &cui; pcui = pcui; return *this;}
|
|
57
|
+
|
|
58
|
+
protected: ////////////////////////////////////////////////////////////////
|
|
59
|
+
//
|
|
60
|
+
// Prompt functions
|
|
61
|
+
//
|
|
62
|
+
virtual void PrintLocalPrompt(std::ostream &out) = 0;
|
|
63
|
+
void PrintPrompt(std::ostream &out);
|
|
64
|
+
|
|
65
|
+
//
|
|
66
|
+
// Useful fonctions to help processing commands
|
|
67
|
+
// ??? (should not be a member function)
|
|
68
|
+
//
|
|
69
|
+
const char *SetFlag(int &f, const char *psz);
|
|
70
|
+
int ArrayLookup(const char * const psz,
|
|
71
|
+
const char * const * const ppsz);
|
|
72
|
+
|
|
73
|
+
//
|
|
74
|
+
// This function is called repeatedly by EnterParseAndProcess
|
|
75
|
+
//
|
|
76
|
+
virtual int ProcessCommand(const char *pszCommand,
|
|
77
|
+
const char *pszParameters,
|
|
78
|
+
std::istream &in,
|
|
79
|
+
std::ostream &out);
|
|
80
|
+
|
|
81
|
+
//
|
|
82
|
+
// Opening modes
|
|
83
|
+
//
|
|
84
|
+
enum // openmode
|
|
85
|
+
{
|
|
86
|
+
OpenModal,
|
|
87
|
+
OpenModeless,
|
|
88
|
+
OpenPermanent
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
//
|
|
92
|
+
// Function to print an error message
|
|
93
|
+
//
|
|
94
|
+
virtual void PrintErrorMessage(std::ostream &out, const char *pszCommand);
|
|
95
|
+
|
|
96
|
+
//
|
|
97
|
+
// Function used to add a CConsoleCUI to the list of modeless children
|
|
98
|
+
// These user interfaces are deleted when they are closed (they must have
|
|
99
|
+
// been allocated dynamically by new ...)
|
|
100
|
+
//
|
|
101
|
+
void AddChild(CConsoleUI *pcui, std::istream &in, std::ostream &out);
|
|
102
|
+
|
|
103
|
+
//
|
|
104
|
+
// Utility function to get[set] variables
|
|
105
|
+
//
|
|
106
|
+
template<class T>
|
|
107
|
+
static void GetSet(T &x, const char *psz, std::ostream &out);
|
|
108
|
+
|
|
109
|
+
public: ///////////////////////////////////////////////////////////////////
|
|
110
|
+
//
|
|
111
|
+
// Constructor
|
|
112
|
+
//
|
|
113
|
+
CConsoleUI(CConsoleUI *pcui = 0, int openmodeInit = OpenModal);
|
|
114
|
+
|
|
115
|
+
//
|
|
116
|
+
// ProcessCommand return values
|
|
117
|
+
//
|
|
118
|
+
enum
|
|
119
|
+
{
|
|
120
|
+
PC_Continue, // The command loop should go on
|
|
121
|
+
PC_Close, // The command loop should stop and return PC_Close
|
|
122
|
+
PC_Parent // The command loop should stop and return PC_Parent
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
//
|
|
126
|
+
// Functions to set/get the prompt flag
|
|
127
|
+
//
|
|
128
|
+
void SetFPrompt(int i) {fPrompt = !!i;};
|
|
129
|
+
int GetFPrompt() const {return fPrompt;};
|
|
130
|
+
|
|
131
|
+
//
|
|
132
|
+
// set parent
|
|
133
|
+
//
|
|
134
|
+
void SetParent(CConsoleUI *pcui);
|
|
135
|
+
|
|
136
|
+
//
|
|
137
|
+
// Function to process a single command
|
|
138
|
+
//
|
|
139
|
+
int EnterParseAndProcess(std::istream &in,
|
|
140
|
+
std::ostream &out,
|
|
141
|
+
std::ostream *pofsLog = 0);
|
|
142
|
+
|
|
143
|
+
//
|
|
144
|
+
// Main command loop of calls to EnterParseAndProcess
|
|
145
|
+
//
|
|
146
|
+
int MainLoop(std::istream &in, std::ostream &out);
|
|
147
|
+
|
|
148
|
+
//
|
|
149
|
+
// This class has virtual functions, so we provide a virtual destructor
|
|
150
|
+
//
|
|
151
|
+
virtual ~CConsoleUI();
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
#endif
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
//
|
|
3
|
+
// const.cpp
|
|
4
|
+
//
|
|
5
|
+
// CConst class
|
|
6
|
+
//
|
|
7
|
+
// Remi Coulom
|
|
8
|
+
//
|
|
9
|
+
// July 1996
|
|
10
|
+
//
|
|
11
|
+
////////////////////////////////////////////////////////////////////////////
|
|
12
|
+
#include "const.h"
|
|
13
|
+
#include "square.h" // CSquare class
|
|
14
|
+
|
|
15
|
+
//
|
|
16
|
+
// Table indicating distances to the edge of the board
|
|
17
|
+
//
|
|
18
|
+
const int CConst::tcEdge[64] =
|
|
19
|
+
{
|
|
20
|
+
Left|Down ,Left2|Down ,Down ,Down ,Down ,Down ,Right2|Down ,Right|Down,
|
|
21
|
+
Left|Down2,Left2|Down2,Down2,Down2,Down2,Down2,Right2|Down2,Right|Down2,
|
|
22
|
+
Left ,Left2 ,0 ,0 ,0 ,0 ,Right2 ,Right,
|
|
23
|
+
Left ,Left2 ,0 ,0 ,0 ,0 ,Right2 ,Right,
|
|
24
|
+
Left ,Left2 ,0 ,0 ,0 ,0 ,Right2 ,Right,
|
|
25
|
+
Left ,Left2 ,0 ,0 ,0 ,0 ,Right2 ,Right,
|
|
26
|
+
Left|Up2 ,Left2|Up2 ,Up2 ,Up2 ,Up2 ,Up2 ,Right2|Up2 ,Right|Up2,
|
|
27
|
+
Left|Up ,Left2|Up ,Up ,Up ,Up ,Up ,Right2|Up ,Right|Up
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//
|
|
31
|
+
// Table of Knight moves
|
|
32
|
+
//
|
|
33
|
+
const struct CConst::st CConst::TKnightMove[8] =
|
|
34
|
+
{
|
|
35
|
+
{Up | Left | Left2 , CSquare::a5 - CSquare::c4},
|
|
36
|
+
{Up | Up2 | Left , CSquare::b6 - CSquare::c4},
|
|
37
|
+
{Up | Up2 | Right , CSquare::d6 - CSquare::c4},
|
|
38
|
+
{Up | Right | Right2 , CSquare::e5 - CSquare::c4},
|
|
39
|
+
{Down | Right | Right2 , CSquare::e3 - CSquare::c4},
|
|
40
|
+
{Down | Down2 | Right , CSquare::d2 - CSquare::c4},
|
|
41
|
+
{Down | Down2 | Left , CSquare::b2 - CSquare::c4},
|
|
42
|
+
{Down | Left | Left2 , CSquare::a3 - CSquare::c4}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
//
|
|
46
|
+
// Table of King moves
|
|
47
|
+
//
|
|
48
|
+
const struct CConst::st CConst::TKingMove[8] =
|
|
49
|
+
{
|
|
50
|
+
{Down | Right, CSquare::c1 - CSquare::b2},
|
|
51
|
+
{Down , CSquare::b1 - CSquare::b2},
|
|
52
|
+
{Down | Left , CSquare::a1 - CSquare::b2},
|
|
53
|
+
{ Left , CSquare::a2 - CSquare::b2},
|
|
54
|
+
{Up | Left , CSquare::a3 - CSquare::b2},
|
|
55
|
+
{Up , CSquare::b3 - CSquare::b2},
|
|
56
|
+
{Up | Right, CSquare::c3 - CSquare::b2},
|
|
57
|
+
{ Right, CSquare::c2 - CSquare::b2}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
//
|
|
61
|
+
// Array of directions
|
|
62
|
+
//
|
|
63
|
+
const int CConst::tDirection[13] =
|
|
64
|
+
{
|
|
65
|
+
0,
|
|
66
|
+
CSquare::Left,
|
|
67
|
+
CSquare::Up,
|
|
68
|
+
CSquare::Left + CSquare::Up,
|
|
69
|
+
CSquare::Right,
|
|
70
|
+
CSquare::Left + CSquare::Right,
|
|
71
|
+
CSquare::Up + CSquare::Right,
|
|
72
|
+
CSquare::Left + CSquare::Up + CSquare::Right,
|
|
73
|
+
CSquare::Down,
|
|
74
|
+
CSquare::Left + CSquare::Down,
|
|
75
|
+
CSquare::Up + CSquare::Down,
|
|
76
|
+
CSquare::Left + CSquare::Up + CSquare::Down,
|
|
77
|
+
CSquare::Right + CSquare::Down
|
|
78
|
+
};
|
|
79
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
//
|
|
3
|
+
// const.h
|
|
4
|
+
//
|
|
5
|
+
// CConst class definition
|
|
6
|
+
//
|
|
7
|
+
// Remi Coulom
|
|
8
|
+
//
|
|
9
|
+
// July 1996
|
|
10
|
+
//
|
|
11
|
+
////////////////////////////////////////////////////////////////////////////
|
|
12
|
+
#ifndef CONST_H
|
|
13
|
+
#define CONST_H
|
|
14
|
+
|
|
15
|
+
class CConst
|
|
16
|
+
{
|
|
17
|
+
public: ///////////////////////////////////////////////////////////////////
|
|
18
|
+
|
|
19
|
+
//
|
|
20
|
+
// Flags indicating direction and distance from the edge for each square
|
|
21
|
+
//
|
|
22
|
+
enum
|
|
23
|
+
{
|
|
24
|
+
Left = 0x01,
|
|
25
|
+
Up = 0x02,
|
|
26
|
+
Right = 0x04,
|
|
27
|
+
Down = 0x08,
|
|
28
|
+
Left2 = 0x10,
|
|
29
|
+
Up2 = 0x20,
|
|
30
|
+
Right2 = 0x40,
|
|
31
|
+
Down2 = 0x80
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
static const int tcEdge[64];
|
|
35
|
+
struct st {int cDirection; int Direction;};
|
|
36
|
+
static const struct st TKnightMove[8];
|
|
37
|
+
static const struct st TKingMove[8];
|
|
38
|
+
static const int tDirection[13];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
#endif
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
//
|
|
3
|
+
// date.cpp
|
|
4
|
+
//
|
|
5
|
+
// CDate class
|
|
6
|
+
//
|
|
7
|
+
// Remi Coulom
|
|
8
|
+
//
|
|
9
|
+
// june 1996
|
|
10
|
+
//
|
|
11
|
+
////////////////////////////////////////////////////////////////////////////
|
|
12
|
+
#include <ctime>
|
|
13
|
+
#include <iostream>
|
|
14
|
+
#include <sstream>
|
|
15
|
+
#include <iomanip>
|
|
16
|
+
#include <cstring>
|
|
17
|
+
|
|
18
|
+
#include "date.h"
|
|
19
|
+
|
|
20
|
+
using namespace std;
|
|
21
|
+
|
|
22
|
+
////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
// Function to retrieve the current date
|
|
24
|
+
////////////////////////////////////////////////////////////////////////////
|
|
25
|
+
CDate CDate::Today()
|
|
26
|
+
{
|
|
27
|
+
time_t now;
|
|
28
|
+
time(&now);
|
|
29
|
+
struct tm *ptm = localtime(&now);
|
|
30
|
+
return CDate(ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
////////////////////////////////////////////////////////////////////////////
|
|
35
|
+
// Constructor to convert a string to a date
|
|
36
|
+
// Format : YYYY?MM?DD (filled with zeroes)
|
|
37
|
+
////////////////////////////////////////////////////////////////////////////
|
|
38
|
+
CDate::CDate(const char *psz)
|
|
39
|
+
{
|
|
40
|
+
int Length = strlen(psz);
|
|
41
|
+
|
|
42
|
+
Year = 0;
|
|
43
|
+
Month = 0;
|
|
44
|
+
Day = 0;
|
|
45
|
+
|
|
46
|
+
char szBuffer[5];
|
|
47
|
+
|
|
48
|
+
szBuffer[0] = psz[0];
|
|
49
|
+
szBuffer[1] = psz[1];
|
|
50
|
+
szBuffer[2] = psz[2];
|
|
51
|
+
szBuffer[3] = psz[3];
|
|
52
|
+
szBuffer[4] = 0;
|
|
53
|
+
istringstream(szBuffer) >> dec >> Year;
|
|
54
|
+
|
|
55
|
+
if (Length > 5)
|
|
56
|
+
{
|
|
57
|
+
szBuffer[0] = psz[5];
|
|
58
|
+
szBuffer[1] = psz[6];
|
|
59
|
+
szBuffer[2] = 0;
|
|
60
|
+
istringstream(szBuffer) >> dec >> Month;
|
|
61
|
+
|
|
62
|
+
if (Length > 8)
|
|
63
|
+
{
|
|
64
|
+
szBuffer[0] = psz[8];
|
|
65
|
+
szBuffer[1] = psz[9];
|
|
66
|
+
szBuffer[2] = 0;
|
|
67
|
+
istringstream(szBuffer) >> dec >> Day;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
////////////////////////////////////////////////////////////////////////////
|
|
73
|
+
// output operator
|
|
74
|
+
////////////////////////////////////////////////////////////////////////////
|
|
75
|
+
ostream &operator<<(ostream &ostr, const CDate &date)
|
|
76
|
+
{
|
|
77
|
+
char cOldFill = ostr.fill('0');
|
|
78
|
+
|
|
79
|
+
if (date.GetYear())
|
|
80
|
+
ostr << setw(4) << date.GetYear() << '.';
|
|
81
|
+
else
|
|
82
|
+
ostr << "??" << "??.";
|
|
83
|
+
|
|
84
|
+
if (date.GetMonth())
|
|
85
|
+
ostr << setw(2) << date.GetMonth() << '.';
|
|
86
|
+
else
|
|
87
|
+
ostr << "??.";
|
|
88
|
+
|
|
89
|
+
if (date.GetDay())
|
|
90
|
+
ostr << setw(2) << date.GetDay();
|
|
91
|
+
else
|
|
92
|
+
ostr << "??";
|
|
93
|
+
|
|
94
|
+
ostr.fill(cOldFill);
|
|
95
|
+
return ostr;
|
|
96
|
+
}
|
data/ext/bayeselo/date.h
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
//
|
|
3
|
+
// date.h
|
|
4
|
+
//
|
|
5
|
+
// CDate class definition
|
|
6
|
+
//
|
|
7
|
+
// Remi Coulom
|
|
8
|
+
//
|
|
9
|
+
// June 1996
|
|
10
|
+
//
|
|
11
|
+
////////////////////////////////////////////////////////////////////////////
|
|
12
|
+
#ifndef DATE_H
|
|
13
|
+
#define DATE_H
|
|
14
|
+
|
|
15
|
+
#include <iostream>
|
|
16
|
+
|
|
17
|
+
class CDate;
|
|
18
|
+
|
|
19
|
+
std::ostream &operator<<(std::ostream &ostr, const CDate &date);
|
|
20
|
+
|
|
21
|
+
class CDate // date
|
|
22
|
+
{
|
|
23
|
+
private: //////////////////////////////////////////////////////////////////
|
|
24
|
+
int Day;
|
|
25
|
+
int Month;
|
|
26
|
+
int Year;
|
|
27
|
+
|
|
28
|
+
public: ///////////////////////////////////////////////////////////////////
|
|
29
|
+
CDate() : Day(0), Month(0), Year(0) {}
|
|
30
|
+
CDate(int y, int m, int d) : Day(d), Month(m), Year(y) {}
|
|
31
|
+
CDate(const char *psz);
|
|
32
|
+
|
|
33
|
+
void SetDay(int NewDay) {Day = NewDay;}
|
|
34
|
+
void SetMonth(int NewMonth) {Month = NewMonth;}
|
|
35
|
+
void SetYear(int NewYear) {Year = NewYear;}
|
|
36
|
+
|
|
37
|
+
int GetDay() const {return Day;}
|
|
38
|
+
int GetMonth() const {return Month;}
|
|
39
|
+
int GetYear() const {return Year;}
|
|
40
|
+
|
|
41
|
+
static CDate Today();
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
#endif
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
//
|
|
3
|
+
// debug.h
|
|
4
|
+
//
|
|
5
|
+
// debug macros
|
|
6
|
+
//
|
|
7
|
+
// Macros for conditionnal compilation :
|
|
8
|
+
// INLINE, MY_ERROR, ASSERT, FATAL, CHECKPOINT, TRACE
|
|
9
|
+
// (see the following code for details)
|
|
10
|
+
//
|
|
11
|
+
// Remi Coulom
|
|
12
|
+
//
|
|
13
|
+
// April, 1996
|
|
14
|
+
//
|
|
15
|
+
////////////////////////////////////////////////////////////////////////////
|
|
16
|
+
#ifndef DEBUG_H
|
|
17
|
+
#define DEBUG_H
|
|
18
|
+
|
|
19
|
+
#include <iostream>
|
|
20
|
+
#include <cstdlib>
|
|
21
|
+
|
|
22
|
+
//
|
|
23
|
+
// MY_ERROR
|
|
24
|
+
//
|
|
25
|
+
#define MY_ERROR(s) do { \
|
|
26
|
+
std::cout << '\n' << s << '\n'; \
|
|
27
|
+
std::cout << "File: " << __FILE__ << '\n'; \
|
|
28
|
+
std::cout << "Line: " << __LINE__ << '\n'; \
|
|
29
|
+
exit(1);} while(0)
|
|
30
|
+
|
|
31
|
+
//
|
|
32
|
+
// FATAL(x)
|
|
33
|
+
//
|
|
34
|
+
#define FATAL(x) do if ((x)) MY_ERROR("Fatal error: " << #x); while(0)
|
|
35
|
+
|
|
36
|
+
//
|
|
37
|
+
// INLINE, ASSERT(x), CHECKPOINT()
|
|
38
|
+
//
|
|
39
|
+
|
|
40
|
+
#ifdef DEBUG
|
|
41
|
+
#define INLINE
|
|
42
|
+
#define TRACE(s) do {std::cout << s << '\n';} while(0)
|
|
43
|
+
#define ASSERT(x) do if (!(x)) MY_ERROR("Assertion failed: "<<#x); while(0)
|
|
44
|
+
#define CHECKPOINT() do { \
|
|
45
|
+
std::cout << '?'; \
|
|
46
|
+
std::cout.flush(); \
|
|
47
|
+
int x = cin.get(); \
|
|
48
|
+
if (x != '\n') \
|
|
49
|
+
exit(1); \
|
|
50
|
+
} while(0);
|
|
51
|
+
#else
|
|
52
|
+
#define INLINE inline
|
|
53
|
+
#define TRACE(s)
|
|
54
|
+
#define ASSERT(x)
|
|
55
|
+
#define CHECKPOINT()
|
|
56
|
+
#endif
|
|
57
|
+
|
|
58
|
+
#endif
|