Skip to content

Commit edda8d3

Browse files
Move the templated getProfile utility function to the profile dictionary
1 parent 8b8cf83 commit edda8d3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tesseract_common/include/tesseract_common/profile_dictionary.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,24 @@ class ProfileDictionary
8888
*/
8989
Profile::ConstPtr getProfile(std::size_t key, const std::string& ns, const std::string& profile_name) const;
9090

91+
/**
92+
* @brief Gets the profile specified from the profile map
93+
* @param ns The profile namespace
94+
* @param profile_name The profile name
95+
* @param default_profile Profile that is returned if the requested profile is not found. Default = nullptr
96+
* @return The profile requested if found. Otherwise the default_profile
97+
*/
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+
91109
/**
92110
* @brief Remove a profile
93111
* @param key The profile key
@@ -142,6 +160,7 @@ class ProfileDictionary
142160
};
143161

144162
using ProfileDictionaryPtrAnyPoly = tesseract_common::AnyWrapper<std::shared_ptr<ProfileDictionary>>;
163+
145164
} // namespace tesseract_common
146165

147166
BOOST_CLASS_EXPORT_KEY(tesseract_common::ProfileDictionary)

0 commit comments

Comments
 (0)