File: pykopeninghours.cpp

package info (click to toggle)
kopeninghours 25.04.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 920 kB
  • sloc: cpp: 3,918; yacc: 795; lex: 335; python: 18; sh: 17; makefile: 16
file content (42 lines) | stat: -rw-r--r-- 2,201 bytes parent folder | download | duplicates (3)
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
/*
    SPDX-FileCopyrightText: 2020 David Faure <faure@kde.org>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include <boost/python/class.hpp>
#include <boost/python/module.hpp>
#include <boost/python/enum.hpp>
#include "python_qt_wrappers.h"
#include <KOpeningHours/OpeningHours>

using namespace boost::python;
using namespace KOpeningHours;

BOOST_PYTHON_MODULE(PyKOpeningHours)
{
    register_qt_wrappers();

    enum_<OpeningHours::Mode>("Mode")
            .value("IntervalMode", OpeningHours::IntervalMode)
            .value("PointInTimeMode", OpeningHours::PointInTimeMode);
    class_<OpeningHours::Modes>("Modes", init<OpeningHours::Mode>());

    // select the right overload of setExpression
    using SetExpressionFunc = void(OpeningHours::*)(const QByteArray&,OpeningHours::Modes);
    class_<OpeningHours>("OpeningHours", init<>())
        .def("setExpression", static_cast<SetExpressionFunc>(&OpeningHours::setExpression),
             (arg("expression"), arg("modes")=OpeningHours::Modes{OpeningHours::IntervalMode}))
        .def("error", &OpeningHours::error)
        .def("normalizedExpression", &OpeningHours::normalizedExpression);

    enum_<OpeningHours::Error>("Error")
            .value("Null", OpeningHours::Null) ///< no expression is set
            .value("NoError", OpeningHours::NoError) ///< there is no error, the expression is valid and can be used
            .value("SyntaxError", OpeningHours::SyntaxError) ///< syntax error in the opening hours expression
            .value("MissingRegion", OpeningHours::MissingRegion) ///< expression refers to public or school holidays, but that information is not available
            .value("MissingLocation", OpeningHours::MissingLocation) ///< evaluation requires location information and those aren't set
            .value("IncompatibleMode", OpeningHours::IncompatibleMode) ///< expression mode doesn't match the expected mode
            .value("UnsupportedFeature", OpeningHours::UnsupportedFeature) ///< expression uses a feature that isn't implemented/supported (yet)
            .value("EvaluationError", OpeningHours::EvaluationError) ///< runtime error during evaluating the expression
            ;
}