Skip to content

Commit b4cd2e9

Browse files
c++: move types main.cpp -> types.cpp
1 parent 2497d27 commit b4cd2e9

3 files changed

Lines changed: 84 additions & 51 deletions

File tree

src/main.cpp

Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -66,38 +66,16 @@ namespace libsemigroups {
6666
}
6767
}
6868

69-
// TODO move to types.cpp
70-
// This has its own function so the py::options can be set for just this enum
71-
void init_tril(py::module& m) {
72-
py::options options;
73-
options.disable_enum_members_docstring();
74-
py::enum_<tril>(m, "tril", R"pbdoc(
75-
The values in this enum can be used to indicate a result is true, false, or not
76-
currently known.
77-
78-
The valid values are:
79-
80-
.. py:attribute:: tril.false
81-
:value: <tril.false: 0>
82-
83-
Value representing false.
84-
85-
.. py:attribute:: tril.true
86-
:value: <tril.true: 1>
87-
88-
Value representing true.
89-
90-
.. py:attribute:: tril.unknown
91-
:value: <tril.unknown: 2>
92-
93-
Value representing unknown (either true or false).
94-
)pbdoc")
95-
.value("true", tril::TRUE)
96-
.value("false", tril::FALSE)
97-
.value("unknown", tril::unknown);
98-
}
99-
10069
PYBIND11_MODULE(_libsemigroups_pybind11, m) {
70+
////////////////////////////////////////////////////////////////////////
71+
// Module attributes
72+
////////////////////////////////////////////////////////////////////////
73+
74+
#ifdef VERSION_INFO
75+
m.attr("__version__") = VERSION_INFO;
76+
#else
77+
m.attr("__version__") = "dev";
78+
#endif
10179
#ifdef LIBSEMIGROUPS_EIGEN_ENABLED
10280
m.attr("LIBSEMIGROUPS_EIGEN_ENABLED")
10381
= static_cast<bool>(LIBSEMIGROUPS_EIGEN_ENABLED);
@@ -141,7 +119,7 @@ The valid values are:
141119
init_constants(m);
142120
init_reporter(m);
143121
init_runner(m);
144-
init_tril(m);
122+
init_types(m);
145123

146124
////////////////////////////////////////////////////////////////////////
147125
// Classes in (almost) alphabetical order
@@ -191,28 +169,10 @@ The valid values are:
191169
init_word_graph(m);
192170
init_words(m);
193171

194-
#ifdef VERSION_INFO
195-
m.attr("__version__") = VERSION_INFO;
196-
#else
197-
m.attr("__version__") = "dev";
198-
#endif
199-
200172
////////////////////////////////////////////////////////////////////////
201-
// Enums
173+
// Miscellaneous
202174
////////////////////////////////////////////////////////////////////////
203175

204-
// TODO to types.cpp
205-
py::enum_<congruence_kind>(m, "congruence_kind", R"pbdoc(
206-
The values in this class can be used to indicate that a congruence should
207-
be 1-sided or 2-sided.
208-
)pbdoc")
209-
.value("onesided",
210-
congruence_kind::onesided,
211-
R"pbdoc(Type for 1-sided congruences (right).)pbdoc")
212-
.value("twosided",
213-
congruence_kind::twosided,
214-
R"pbdoc(Type for 2-sided congruences.)pbdoc");
215-
216176
py::class_<ReportGuard>(m,
217177
"ReportGuard",
218178
R"pbdoc(

src/main.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ namespace libsemigroups {
7272
void init_to_todd_coxeter(py::module&);
7373
void init_todd_coxeter(py::module&);
7474
void init_transf(py::module&);
75+
void init_types(py::module&);
7576
void init_ukkonen(py::module&);
7677
void init_word_graph(py::module&);
7778
void init_words(py::module&);

src/types.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//
2+
// libsemigroups_pybind11
3+
// Copyright (C) 2025 James D. Mitchell
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
//
18+
19+
// libsemigroups headers
20+
#include <libsemigroups/types.hpp>
21+
22+
// pybind11....
23+
#include <pybind11/pybind11.h>
24+
25+
// libsemigroups_pybind11....
26+
#include "main.hpp" // for init_types
27+
28+
namespace libsemigroups {
29+
30+
void init_types(py::module& m) {
31+
{
32+
py::options options;
33+
options.disable_enum_members_docstring();
34+
py::enum_<tril>(m, "tril", R"pbdoc(
35+
The values in this enum can be used to indicate a result is true, false, or not
36+
currently known.
37+
38+
The valid values are:
39+
40+
.. py:attribute:: tril.false
41+
:value: <tril.false: 0>
42+
43+
Value representing false.
44+
45+
.. py:attribute:: tril.true
46+
:value: <tril.true: 1>
47+
48+
Value representing true.
49+
50+
.. py:attribute:: tril.unknown
51+
:value: <tril.unknown: 2>
52+
53+
Value representing unknown (either true or false).
54+
)pbdoc")
55+
.value("true", tril::TRUE)
56+
.value("false", tril::FALSE)
57+
.value("unknown", tril::unknown);
58+
}
59+
60+
py::enum_<congruence_kind>(m, "congruence_kind", R"pbdoc(
61+
The values in this class can be used to indicate that a congruence should
62+
be 1-sided or 2-sided.
63+
)pbdoc")
64+
.value("onesided",
65+
congruence_kind::onesided,
66+
R"pbdoc(Type for 1-sided congruences (right).)pbdoc")
67+
.value("twosided",
68+
congruence_kind::twosided,
69+
R"pbdoc(Type for 2-sided congruences.)pbdoc");
70+
}
71+
72+
} // namespace libsemigroups

0 commit comments

Comments
 (0)