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
armarx::priorknowledge::core::PKFinder::checkAll
bool checkAll() const override
Definition: PKFinder.cpp:30
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:21
armarx::priorknowledge::core::FinderBase< std::string, PKFinderInfo >::getAbsolutePackagePath
std::filesystem::path getAbsolutePackagePath() const
Definition: FinderBase.h:77
armarx::priorknowledge::core::PKFinder::find
std::optional< PKFinderInfo > find(const std::string &id) const override
Definition: PKFinder.cpp:69
armarx::priorknowledge::core::PKFinder::registerPropertyDefinitions
virtual void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr &defs, const std::string &prefix)
Definition: PKFinder.cpp:12
PKFinder.h
armarx::priorknowledge::core::FinderBase< std::string, PKFinderInfo >::getRelativePath
std::filesystem::path getRelativePath() const
Definition: FinderBase.h:71
armarx::priorknowledge::core::FinderBase< std::string, PKFinderInfo >::accept
virtual bool accept(const std::filesystem::path &idPath) const=0
armarx::armem::contains
bool contains(const MemoryID &general, const MemoryID &specific)
Indicates whether general is "less specific" than, or equal to, specific, i.e.
Definition: MemoryID.cpp:558
armarx::priorknowledge::core::PKFinder::check
bool check(const std::string &id) const override
Definition: PKFinder.cpp:56
armarx::priorknowledge::core::FinderBase< std::string, PKFinderInfo >::packageName
std::string packageName
Definition: FinderBase.h:109
armarx::priorknowledge::core::FinderBase< std::string, PKFinderInfo >::getPackageName
std::string getPackageName() const
Definition: FinderBase.h:65
armarx::priorknowledge::core::PKFinder::init
virtual void init()
Definition: PKFinder.cpp:24
armarx::priorknowledge::core::PKFinder::findAll
std::vector< PKFinderInfo > findAll() const override
Definition: PKFinder.cpp:82
armarx::priorknowledge::core::PKFinderInfo
The ObjectFinderInfo class Specialization of the DatasetFinderInfo with strings as dataset and id typ...
Definition: PKFinder.h:14
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::priorknowledge::core
Definition: FinderBase.h:16
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::priorknowledge::core::FinderBase< std::string, PKFinderInfo >::recalculateBasePath
void recalculateBasePath()
Definition: FinderBase.h:31
armarx::priorknowledge::core::FinderBase< std::string, PKFinderInfo >::getFullPath
std::filesystem::path getFullPath() const
Definition: FinderBase.h:84