forked from PolusAI/filepattern
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbindings.cpp
More file actions
101 lines (76 loc) · 3.65 KB
/
Copy pathbindings.cpp
File metadata and controls
101 lines (76 loc) · 3.65 KB
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
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/operators.h>
#include <pybind11/complex.h>
#include <pybind11/stl/filesystem.h>
#include <string>
#include "pattern_object.hpp"
#ifdef WITH_LIBFILEPATTERN
#include "filepattern/filepattern.h"
#else
#include "include/filepattern.h"
#endif
namespace py = pybind11;
PYBIND11_MODULE(backend, m){
py::class_<FilePattern>(m, "FilePattern")
.def(py::init<const std::string&,
const std::string&,
const std::string&,
bool,
bool,
bool>())
.def(py::init<const std::vector<std::string>&,
const std::string&,
bool,
bool,
bool>())
.def("getMatching", &FilePattern::getMatching)
.def("getOccurrences", &FilePattern::getOccurrences)
.def("getUniqueValues", &FilePattern::getUniqueValues)
.def("outputName", &FilePattern::outputName)
.def("getVariables", &FilePattern::getVariables)
.def("getNewNaming", &FilePattern::getNewNaming)
.def("groupBy", &FilePattern::groupBy)
.def("currentBlockLength", &FilePattern::currentBlockLength)
.def("getSlice", &FilePattern::getSlice)
.def("getMatchingBlock", &FilePattern::getMatchingBlock)
.def("getItem", &FilePattern::getItem)
.def("getItemList", &FilePattern::getItemList)
.def("setGroup", py::overload_cast<const std::vector<std::string>&>(&FilePattern::setGroup))
.def("setGroupStr", py::overload_cast<std::string&>(&FilePattern::setGroup))
.def("length", &FilePattern::length)
.def_static("getRegex", &FilePattern::getRegex)
.def_static("getVariablesFromPattern", &FilePattern::getVariablesFromPattern)
.def_static("inferPattern", py::overload_cast<const std::string&, std::string&, const std::string&>(&FilePattern::inferPattern))
.def_static("inferPattern", py::overload_cast<std::vector<std::string>&, std::string&>(&FilePattern::inferPattern))
.def("isGrouped", [](FilePattern &v){
auto& pattern_obj = v.getPatternObject();
return !(pattern_obj->group_.size() == 0 || (pattern_obj->group_.size() != 0 && pattern_obj->group_[0] == ""));
})
.def("iterator", [](FilePattern &v){
auto& pattern_obj = v.getPatternObject();
if(pattern_obj != nullptr) {
return py::make_iterator(pattern_obj->valid_files_.begin(), pattern_obj->valid_files_.end());
}
}, py::keep_alive<0, 1>())
.def("iteratorExternal", [](FilePattern &v){
auto& pattern_obj = v.getPatternObject();
if(pattern_obj != nullptr) {
v.next();
return py::make_iterator(pattern_obj->current_block_.begin(), pattern_obj->current_block_.end());
}
}, py::keep_alive<0, 1>())
.def("iteratorGrouped", [](FilePattern &v){
auto& pattern_obj = v.getPatternObject();
if(pattern_obj != nullptr) {
return py::make_iterator(pattern_obj->valid_grouped_files_.begin(), pattern_obj->valid_grouped_files_.end());
}
}, py::keep_alive<0, 1>())
.def("iteratorGroupedExternal", [](FilePattern &v){
auto& pattern_obj = v.getPatternObject();
if(pattern_obj != nullptr) {
v.nextGroup();
return py::make_iterator(pattern_obj->current_group_.begin(), pattern_obj->current_group_.end());
}
}, py::keep_alive<0, 1>());
}