FinderInfoBase.h
Go to the documentation of this file.
1 #pragma once
2 
3 // STD/STL
4 #include <filesystem>
5 #include <optional>
6 #include <string>
7 
8 // Base Class
10 
11 // ArmarX
14 
16 {
18  {
19  /// Name of the ArmarX package.
20  std::string package;
21 
22  /// Relative to the package's data directory.
23  std::filesystem::path relativePath;
24 
25  /// The absolute path (in the host's file system).
26  std::filesystem::path absolutePath;
27  };
28 
29  /**
30  * @brief The FinderInfoBase class
31  * Indicates an into to 'something' of type IDType
32  */
33  template <class IDType>
35  {
36  public:
37  FinderInfoBase(const std::string& packageName,
38  const std::filesystem::path& absPackageDataPath, // the path to the data dir
39  const std::filesystem::path&
40  relPathToId, // the path to 'something' from data/packageName
41  const IDType& id) :
42  packageName(packageName),
43  absPackageDataPath(absPackageDataPath),
44  relPathToId(relPathToId),
45  id(id)
46  {
47  }
48 
49  virtual ~FinderInfoBase()
50  {
51  }
52 
55  {
57  }
58 
59  std::string
61  {
62  return packageName;
63  }
64 
65  std::filesystem::path
67  {
68  return relPathToId;
69  }
70 
71  std::filesystem::path
73  {
75  return absPackageDataPath;
76  }
77 
78  virtual std::filesystem::path
79  getFullPath() const
80  {
82  return absPackageDataPath / packageName / relPathToId;
83  }
84 
85  IDType
86  getID() const
87  {
88  return id;
89  }
90 
91  protected:
92  void
94  {
95  if (!std::filesystem::exists(absPackageDataPath))
96  {
97  ARMARX_ERROR << "Could not resolve absolute path for package '" << packageName
98  << "'.";
99  }
100  }
101 
102 
103  protected:
104  bool logError = true;
105 
106  private:
107  std::string packageName;
108  std::filesystem::path absPackageDataPath;
109  std::filesystem::path relPathToId;
110  IDType id;
111  };
112 
113  /**
114  * @brief The DatasetFinderInfoBase class
115  * Indicates an into to 'something' of type IDType inside a dataset of type DatasetType
116  */
117  template <class IDType, class DatasetType>
118  class DatasetFinderInfoBase : public FinderInfoBase<IDType>
119  {
120 
121  public:
123 
125  const std::string& packageName,
126  const std::filesystem::path& absPackageDataDir,
127  const std::filesystem::path&
128  relDatasetPath, // the path to the dataset from data/packageName
129  const std::filesystem::path& relPath, // the path to 'something' from the dataset
130  const DatasetType& dataset,
131  const IDType& id) :
132  Base(packageName, absPackageDataDir, (relDatasetPath / relPath), id),
133  dataset(dataset),
134  relDatasetPath(relDatasetPath)
135  {
136  }
137 
139  {
140  }
141 
142  DatasetType
143  getDataset() const
144  {
145  return dataset;
146  }
147 
148  private:
149  DatasetType dataset;
150  std::filesystem::path relDatasetPath;
151  };
152 
153 } // namespace armarx::priorknowledge::core
armarx::priorknowledge::core::FinderInfoBase::toPackageFileLocation
PackageFileLocation toPackageFileLocation()
Definition: FinderInfoBase.h:54
armarx::priorknowledge::core::DatasetFinderInfoBase::getDataset
DatasetType getDataset() const
Definition: FinderInfoBase.h:143
armarx::priorknowledge::core::PackageFileLocation
Definition: FinderInfoBase.h:17
armarx::priorknowledge::core::PackageFileLocation::absolutePath
std::filesystem::path absolutePath
The absolute path (in the host's file system).
Definition: FinderInfoBase.h:26
armarx::priorknowledge::core::FinderInfoBase::FinderInfoBase
FinderInfoBase(const std::string &packageName, const std::filesystem::path &absPackageDataPath, const std::filesystem::path &relPathToId, const IDType &id)
Definition: FinderInfoBase.h:37
armarx::priorknowledge::core::FinderInfoBase::~FinderInfoBase
virtual ~FinderInfoBase()
Definition: FinderInfoBase.h:49
armarx::priorknowledge::core::PackageFileLocation::package
std::string package
Name of the ArmarX package.
Definition: FinderInfoBase.h:20
armarx::priorknowledge::core::DatasetFinderInfoBase::~DatasetFinderInfoBase
virtual ~DatasetFinderInfoBase()
Definition: FinderInfoBase.h:138
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::priorknowledge::core::FinderInfoBase::getRelativePath
std::filesystem::path getRelativePath() const
Definition: FinderInfoBase.h:66
armarx::priorknowledge::core::FinderInfoBase::checkAbsolutePathIsValid
void checkAbsolutePathIsValid() const
Definition: FinderInfoBase.h:93
ExpressionException.h
armarx::priorknowledge::core::FinderInfoBase::getPackageName
std::string getPackageName() const
Definition: FinderInfoBase.h:60
armarx::priorknowledge::core::DatasetFinderInfoBase
The DatasetFinderInfoBase class Indicates an into to 'something' of type IDType inside a dataset of t...
Definition: FinderInfoBase.h:118
armarx::priorknowledge::core
Definition: FinderBase.h:16
armarx::priorknowledge::core::FinderInfoBase::getAbsolutePackageDataPath
std::filesystem::path getAbsolutePackageDataPath() const
Definition: FinderInfoBase.h:72
armarx::priorknowledge::core::FinderInfoBase
The FinderInfoBase class Indicates an into to 'something' of type IDType.
Definition: FinderInfoBase.h:34
armarx::priorknowledge::core::DatasetFinderInfoBase::DatasetFinderInfoBase
DatasetFinderInfoBase(const std::string &packageName, const std::filesystem::path &absPackageDataDir, const std::filesystem::path &relDatasetPath, const std::filesystem::path &relPath, const DatasetType &dataset, const IDType &id)
Definition: FinderInfoBase.h:124
armarx::priorknowledge::core::FinderInfoBase::logError
bool logError
Definition: FinderInfoBase.h:104
armarx::priorknowledge::core::FinderInfoBase::getID
IDType getID() const
Definition: FinderInfoBase.h:86
Logging.h
ArmarXDataPath.h
armarx::priorknowledge::core::PackageFileLocation::relativePath
std::filesystem::path relativePath
Relative to the package's data directory.
Definition: FinderInfoBase.h:23
armarx::priorknowledge::core::FinderInfoBase::getFullPath
virtual std::filesystem::path getFullPath() const
Definition: FinderInfoBase.h:79