cppyabm
1.0.17
An agent-based library to integrate C++ and Python
|
|
Go to the documentation of this file.
24 std::string
toString()
const {
return "[" + std::to_string(x) +
", " + std::to_string(y) +
"]"; }
48 return x == v.x && y == v.y;
51 return x != v.x || y != v.y;
80 return "abs(Vector2)";
85 #pragma GCC diagnostic push
91 #if defined(__APPLE__) && defined(__clang__)
92 #if (__clang_major__ >= 10)
93 #pragma GCC diagnostic ignored "-Wself-assign-overloaded"
95 #elif defined(__clang__)
96 #if (__clang_major__ >= 7)
97 #pragma GCC diagnostic ignored "-Wself-assign-overloaded"
105 py::class_<Vector2>(
m,
"Vector2")
106 .def(py::init<float, float>())
107 .def(py::self + py::self)
108 .def(py::self +
float())
109 .def(py::self - py::self)
110 .def(py::self -
float())
111 .def(py::self *
float())
112 .def(py::self /
float())
113 .def(py::self * py::self)
114 .def(py::self / py::self)
115 .def(py::self += py::self)
116 .def(py::self -= py::self)
117 .def(py::self *=
float())
118 .def(py::self /=
float())
119 .def(py::self *= py::self)
120 .def(py::self /= py::self)
121 .def(
float() + py::self)
122 .def(
float() - py::self)
123 .def(
float() * py::self)
124 .def(
float() / py::self)
128 .def(py::self == py::self)
129 .def(py::self != py::self)
133 .def(
"__abs__", [](
const Vector2& v) {
return abs(v); })
136 m.attr(
"Vector") =
m.attr(
"Vector2");
140 py::class_<C1>(
m,
"C1")
142 .def(py::self + py::self);
144 py::class_<C2>(
m,
"C2")
146 .def(py::self + py::self)
147 .def(
"__add__", [](
const C2& c2,
const C1& c1) {
return c2 + c1; })
148 .
def(
"__radd__", [](
const C2& c2,
const C1& c1) {
return c1 + c2; });
152 struct NestABase {
int value = -2; };
153 py::class_<NestABase>(
m,
"NestABase")
157 struct NestA : NestABase {
159 NestA& operator+=(
int i) {
value +=
i;
return *
this; }
161 py::class_<NestA>(
m,
"NestA")
163 .def(py::self +=
int())
164 .def(
"as_base", [](NestA &a) -> NestABase& {
165 return (NestABase&) a;
166 }, py::return_value_policy::reference_internal);
167 m.def(
"get_NestA", [](
const NestA &a) {
return a.value; });
172 NestB& operator-=(
int i) {
value -=
i;
return *
this; }
174 py::class_<NestB>(
m,
"NestB")
176 .def(py::self -=
int())
177 .def_readwrite(
"a", &NestB::a);
178 m.def(
"get_NestB", [](
const NestB &b) {
return b.value; });
183 NestC& operator*=(
int i) {
value *=
i;
return *
this; }
185 py::class_<NestC>(
m,
"NestC")
187 .def(py::self *=
int())
188 .def_readwrite(
"b", &NestC::b);
189 m.def(
"get_NestC", [](
const NestC &c) {
return c.value; });
196 bool operator==(
const Comparable& rhs)
const {
return value == rhs.value;}
199 struct Hashable : Comparable {
200 explicit Hashable(
int value): Comparable{
value}{};
201 size_t hash()
const {
return static_cast<size_t>(
value); }
204 struct Hashable2 : Hashable {
205 using Hashable::Hashable;
208 py::class_<Comparable>(
m,
"Comparable")
209 .def(py::init<int>())
210 .def(py::self == py::self);
212 py::class_<Hashable>(
m,
"Hashable")
213 .def(py::init<int>())
214 .def(py::self == py::self)
218 py::class_<Hashable2>(
m,
"Hashable2")
220 .def(py::init<int>())
221 .def(py::self == py::self);
225 #pragma GCC diagnostic pop
Vector2 & operator+=(const Vector2 &v)
Vector2 & operator=(Vector2 &&v)
Vector2 operator/(float value) const
Vector2 operator-(const Vector2 &v) const
bool operator==(const NonZeroIterator< std::pair< A, B >> &it, const NonZeroSentinel &)
friend Vector2 operator/(float f, const Vector2 &v)
Vector2 & operator*=(float v)
Vector2(const Vector2 &v)
friend Vector2 operator+(float f, const Vector2 &v)
Vector2 operator-() const
TEST_SUBMODULE(operators, m)
std::string toString() const
Vector2 operator*(const Vector2 &v) const
void print_copy_created(T *inst, Values &&...values)
bool operator==(const Vector2 &v) const
Vector2 & operator=(const Vector2 &v)
Vector2 & operator/=(float v)
Vector2 operator+(float value) const
std::string abs(const Vector2 &)
Vector2 operator+(const Vector2 &v) const
void print_copy_assigned(T *inst, Values &&...values)
Vector2 & operator*=(const Vector2 &v)
Vector2 & operator/=(const Vector2 &v)
Vector2 operator-(float value) const
Vector2 operator*(float value) const
friend Vector2 operator*(float f, const Vector2 &v)
void print_move_created(T *inst, Values &&...values)
size_t operator()(const Vector2 &)
friend Vector2 operator-(float f, const Vector2 &v)
void print_destroyed(T *inst, Values &&...values)
bool operator!=(const Vector2 &v) const
void print_move_assigned(T *inst, Values &&...values)
Vector2(float x, float y)
Vector2 operator/(const Vector2 &v) const
int operator+(const C1 &, const C1 &)
Vector2 & operator-=(const Vector2 &v)
void print_created(T *inst, Values &&...values)