-
Notifications
You must be signed in to change notification settings - Fork 146
/
gambit.h
150 lines (126 loc) · 4.55 KB
/
gambit.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//
// This file is part of Gambit
// Copyright (c) 1994-2024, The Gambit Project (http://www.gambit-project.org)
//
// FILE: src/libgambit/gambit.h
// Top-level include file for Gambit library
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#ifndef LIBGAMBIT_H
#define LIBGAMBIT_H
#include <stdexcept>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <map>
namespace Gambit {
// Naming compatible with Boost's lexical_cast concept for potential future compatibility.
template <class D, class S> D lexical_cast(const S &p_value)
{
std::ostringstream s;
s << p_value;
return s.str();
}
template <class D, class S> D lexical_cast(const S &p_value, int p_prec)
{
std::ostringstream s;
s.setf(std::ios::fixed);
s << std::setprecision(p_prec) << p_value;
return s.str();
}
inline double abs(double x) { return std::fabs(x); }
inline double sqr(double x) { return x * x; }
template <class Key, class T> bool contains(const std::map<Key, T> &map, const Key &key)
// TODO: remove when we move to C++20 which already includes a "contains" method
{
return map.find(key) != map.end();
}
//========================================================================
// Exception classes
//========================================================================
/// A base class for all Gambit exceptions
class Exception : public std::runtime_error {
public:
Exception() : std::runtime_error("") {}
explicit Exception(const std::string &s) : std::runtime_error(s) {}
~Exception() noexcept override = default;
};
/// Exception thrown on out-of-range index
class IndexException : public Exception {
public:
IndexException() : Exception("Index out of range") {}
explicit IndexException(const std::string &s) : Exception(s) {}
~IndexException() noexcept override = default;
};
/// Exception thrown on invalid index ranges
class RangeException : public Exception {
public:
RangeException() : Exception("Invalid index range") {}
explicit RangeException(const std::string &s) : Exception(s) {}
~RangeException() noexcept override = default;
};
/// Exception thrown on dimension mismatches
class DimensionException : public Exception {
public:
DimensionException() : Exception("Mismatched dimensions") {}
explicit DimensionException(const std::string &s) : Exception(s) {}
~DimensionException() noexcept override = default;
};
/// Exception thrown on invalid value
class ValueException : public Exception {
public:
ValueException() : Exception("Invalid value") {}
explicit ValueException(const std::string &s) : Exception(s) {}
~ValueException() noexcept override = default;
};
/// Exception thrown on a failed assertion
class AssertionException : public Exception {
public:
AssertionException() : Exception("Failed assertion") {}
explicit AssertionException(const std::string &s) : Exception(s) {}
~AssertionException() noexcept override = default;
};
/// Exception thrown on attempted division by zero
class ZeroDivideException : public Exception {
public:
ZeroDivideException() : Exception("Attempted division by zero") {}
explicit ZeroDivideException(const std::string &s) : Exception(s) {}
~ZeroDivideException() noexcept override = default;
};
/// An exception thrown when attempting to dereference a null pointer
class NullException : public Exception {
public:
NullException() : Exception("Dereferenced null pointer") {}
explicit NullException(const std::string &s) : Exception(s) {}
~NullException() noexcept override = default;
};
} // end namespace Gambit
#include "core/array.h"
#include "core/list.h"
#include "core/recarray.h"
#include "core/vector.h"
#include "core/matrix.h"
#include "core/rational.h"
#include "games/game.h"
#include "games/writer.h"
#include "games/behavspt.h"
#include "games/behavmixed.h"
#include "games/behavpure.h"
#include "games/stratspt.h"
#include "games/stratpure.h"
#include "games/stratmixed.h"
#endif // LIBGAMBIT_H