PKFinder.cpp
Go to the documentation of this file.
1// Simox
2#include <SimoxUtility/algorithm/vector.hpp>
3
4// BaseClass
5#include "PKFinder.h"
6
7// ArmarX
8
10{
11 void
13 const std::string& prefix)
14 {
15 if (not defs->hasDefinition(prefix + "packageName"))
16 {
17 defs->optional(this->packageName,
18 prefix + "packageName",
19 "The name of the prior knowledge data package.");
20 }
21 }
22
23 void
25 {
26 this->recalculateBasePath();
27 }
28
29 bool
31 {
32 const std::filesystem::path absPath = Base::getFullPath();
33 if (std::filesystem::is_regular_file(absPath))
34 {
35 ARMARX_WARNING << "The entered path is leading to a file!";
36 return false;
37 }
38
39 for (const auto& d : std::filesystem::directory_iterator(absPath))
40 {
41 std::string k = d.path().filename();
42 if (simox::alg::contains(ID_BLACKLIST, k))
43 {
44 continue;
45 }
46
47 if (not this->check(d.path()))
48 {
49 return false;
50 }
51 }
52 return true;
53 }
54
55 bool
56 PKFinder::check(const std::string& id) const
57 {
58 if (simox::alg::contains(ID_BLACKLIST, id))
59 {
60 return false;
61 }
62
63 const std::filesystem::path absPath = Base::getFullPath() / id;
64
65 return this->accept(absPath);
66 }
67
68 std::optional<PKFinderInfo>
69 PKFinder::find(const std::string& id) const
70 {
71 const std::filesystem::path absPath = Base::getFullPath() / id;
72
73 if (this->check(absPath))
74 {
75 return PKFinderInfo{
77 }
78 return std::nullopt;
79 }
80
81 std::vector<PKFinderInfo>
83 {
84 const std::filesystem::path absPath = Base::getFullPath();
85 if (std::filesystem::is_regular_file(absPath))
86 {
87 ARMARX_WARNING << "The entered path is leading to a file!";
88 return {};
89 }
90
91 std::vector<PKFinderInfo> ret;
92 for (const auto& d : std::filesystem::directory_iterator(absPath))
93 {
94 std::string k = d.path().filename();
95 if (simox::alg::contains(ID_BLACKLIST, k))
96 {
97 continue;
98 }
99
100 auto el = this->find(k);
101 if (el.has_value())
102 {
103 ret.push_back(*el);
104 }
105 }
106 return ret;
107 }
108
109} // namespace armarx::priorknowledge::core
virtual bool accept(const std::filesystem::path &idPath) const=0
The ObjectFinderInfo class Specialization of the DatasetFinderInfo with strings as dataset and id typ...
Definition PKFinder.h:15
std::vector< PKFinderInfo > findAll() const override
Definition PKFinder.cpp:82
virtual void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr &defs, const std::string &prefix)
Definition PKFinder.cpp:12
std::optional< PKFinderInfo > find(const std::string &id) const override
Definition PKFinder.cpp:69
bool check(const std::string &id) const override
Definition PKFinder.cpp:56
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.