profile_dictionary.h
Go to the documentation of this file.
1 
26 #ifndef TESSERACT_COMMON_PROFILE_DICTIONARY_H
27 #define TESSERACT_COMMON_PROFILE_DICTIONARY_H
28 
31 #include <unordered_map>
32 #include <memory>
33 #include <shared_mutex>
35 
38 
39 namespace tesseract_common
40 {
41 struct Serialization;
47 {
48 public:
49  using Ptr = std::shared_ptr<ProfileDictionary>;
50  using ConstPtr = std::shared_ptr<const ProfileDictionary>;
51 
52  ProfileDictionary() = default;
53  ~ProfileDictionary() = default;
57  ProfileDictionary& operator=(ProfileDictionary&&) noexcept;
58 
66  void addProfile(const std::string& ns, const std::string& profile_name, const Profile::ConstPtr& profile);
67  void addProfile(const std::string& ns,
68  const std::vector<std::string>& profile_names,
69  const Profile::ConstPtr& profile);
70 
79  bool hasProfile(std::size_t key, const std::string& ns, const std::string& profile_name) const;
80 
89  Profile::ConstPtr getProfile(std::size_t key, const std::string& ns, const std::string& profile_name) const;
90 
98  template <typename ProfileType>
99  std::shared_ptr<const ProfileType> getProfile(const std::string& ns,
100  const std::string& profile_name,
101  std::shared_ptr<const ProfileType> default_profile = nullptr) const
102  {
103  if (hasProfile(ProfileType::getStaticKey(), ns, profile_name))
104  return std::static_pointer_cast<const ProfileType>(getProfile(ProfileType::getStaticKey(), ns, profile_name));
105 
106  return default_profile;
107  }
108 
115  void removeProfile(std::size_t key, const std::string& ns, const std::string& profile_name);
116 
123  bool hasProfileEntry(std::size_t key, const std::string& ns) const;
124 
130  void removeProfileEntry(std::size_t key, const std::string& ns);
131 
138  std::unordered_map<std::string, Profile::ConstPtr> getProfileEntry(std::size_t key, const std::string& ns) const;
139 
144  std::unordered_map<std::string, std::unordered_map<std::size_t, std::unordered_map<std::string, Profile::ConstPtr>>>
145  getAllProfileEntries() const;
146 
148  void clear();
149 
150 protected:
151  mutable std::shared_mutex mutex_;
152  std::unordered_map<std::string, std::unordered_map<std::size_t, std::unordered_map<std::string, Profile::ConstPtr>>>
154 
155 private:
158  template <class Archive>
159  void serialize(Archive& ar, const unsigned int version); // NOLINT
160 };
161 
163 
164 } // namespace tesseract_common
165 
166 BOOST_CLASS_EXPORT_KEY(tesseract_common::ProfileDictionary)
167 BOOST_CLASS_EXPORT_KEY(tesseract_common::ProfileDictionaryPtrAnyPoly)
168 
169 #endif // TESSERACT_COMMON_PROFILE_DICTIONARY_H
profile.h
This is a profile base class.
tesseract_common::ProfileDictionary::getProfile
Profile::ConstPtr getProfile(std::size_t key, const std::string &ns, const std::string &profile_name) const
Get a profile by name.
Definition: profile_dictionary.cpp:233
tesseract_common
Definition: allowed_collision_matrix.h:19
any_poly.h
tesseract_common::ProfileDictionary::mutex_
std::shared_mutex mutex_
Definition: profile_dictionary.h:151
macros.h
Common Tesseract Macros.
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
Definition: macros.h:71
tesseract_common::AnyWrapper
Definition: any_poly.h:80
tesseract_common::ProfileDictionary::removeProfile
void removeProfile(std::size_t key, const std::string &ns, const std::string &profile_name)
Remove a profile.
Definition: profile_dictionary.cpp:241
tesseract_common::Serialization
Definition: serialization.h:97
tesseract_common::ProfileDictionary::removeProfileEntry
void removeProfileEntry(std::size_t key, const std::string &ns)
Remove a profile entry.
Definition: profile_dictionary.cpp:88
tesseract_common::ProfileDictionary::getAllProfileEntries
std::unordered_map< std::string, std::unordered_map< std::size_t, std::unordered_map< std::string, Profile::ConstPtr > > > getAllProfileEntries() const
Get all profile entries.
Definition: profile_dictionary.cpp:118
tesseract_common::ProfileDictionary::~ProfileDictionary
~ProfileDictionary()=default
tesseract_common::ProfileDictionary::ConstPtr
std::shared_ptr< const ProfileDictionary > ConstPtr
Definition: profile_dictionary.h:50
tesseract_common::ProfileDictionary::ProfileDictionary
ProfileDictionary()=default
tesseract_common::ProfileDictionary::access
friend class boost::serialization::access
Definition: profile_dictionary.h:156
tesseract_common::Profile
The Profile class.
Definition: profile.h:39
tesseract_common::ProfileDictionary::hasProfileEntry
bool hasProfileEntry(std::size_t key, const std::string &ns) const
Check if a profile entry exists.
Definition: profile_dictionary.cpp:78
tesseract_common::ProfileDictionary::profiles_
std::unordered_map< std::string, std::unordered_map< std::size_t, std::unordered_map< std::string, Profile::ConstPtr > > > profiles_
Definition: profile_dictionary.h:153
tesseract_common::ProfileDictionary::clear
void clear()
Clear the dictionary.
Definition: profile_dictionary.cpp:261
tesseract_common::ProfileDictionary
This class is used to store profiles used by various tasks.
Definition: profile_dictionary.h:46
tesseract_common::ProfileDictionary::operator=
ProfileDictionary & operator=(const ProfileDictionary &)
Definition: profile_dictionary.cpp:47
tesseract_common::ProfileDictionary::Ptr
std::shared_ptr< ProfileDictionary > Ptr
Definition: profile_dictionary.h:49
TESSERACT_COMMON_IGNORE_WARNINGS_POP
#define TESSERACT_COMMON_IGNORE_WARNINGS_POP
Definition: macros.h:72
tesseract_common::ProfileDictionary::serialize
void serialize(Archive &ar, const unsigned int version)
Definition: profile_dictionary.cpp:268
tesseract_common::ProfileDictionary::hasProfile
bool hasProfile(std::size_t key, const std::string &ns, const std::string &profile_name) const
Check if a profile exists.
Definition: profile_dictionary.cpp:216
tesseract_common::ProfileDictionary::getProfileEntry
std::unordered_map< std::string, Profile::ConstPtr > getProfileEntry(std::size_t key, const std::string &ns) const
Get a profile entry.
Definition: profile_dictionary.cpp:101
tesseract_common::ProfileDictionary::addProfile
void addProfile(const std::string &ns, const std::string &profile_name, const Profile::ConstPtr &profile)
Add a profile.
Definition: profile_dictionary.cpp:124


tesseract_common
Author(s): Levi Armstrong
autogenerated on Sun May 18 2025 03:01:40