Robot Raconteur Companion C++ Library
Loading...
Searching...
No Matches
InfoFileLoader.h
Go to the documentation of this file.
1
23
24#include "IdentifierUtil.h"
26#include "UtilMacros.h"
27
29
30namespace RobotRaconteur
31{
32namespace Companion
33{
34namespace Util
35{
36namespace detail
37{
38template <typename T>
39class LoadInfoFile_traits
40{
41 public:
42 static bool LoadDeviceIdentifier(const T& info_file, const std::string& category,
43 std::vector<LocalIdentifierLockPtr>& locks,
44 boost::shared_ptr<RobotRaconteur::RobotRaconteurNode> node)
45 {
46 if (info_file && info_file->device_info && info_file->device_info->device &&
47 !IsIdentifierAnyName(info_file->device_info->device) && IsIdentifierAnyUuid(info_file->device_info->device))
48 {
49 LocalIdentifierLockPtr l =
50 GetIdentifierForNameAndLock(category, info_file->device_info->device->name, node);
51 info_file->device_info->device = l->GetIdentifier();
52 locks.push_back(l);
53 return true;
54 }
55 return false;
56 }
57};
58
59template <>
60class ROBOTRACONTEUR_COMPANION_UTIL_API LoadInfoFile_traits<com::robotraconteur::device::DeviceInfoPtr>
61{
62 public:
63 static bool LoadDeviceIdentifier(const com::robotraconteur::device::DeviceInfoPtr& info_file,
64 const std::string& category, std::vector<LocalIdentifierLockPtr>& locks,
65 const boost::shared_ptr<RobotRaconteur::RobotRaconteurNode>& node);
66};
67} // namespace detail
68
91template <typename T>
92static T LoadInfoFileFromString(const std::string& file_text, std::vector<LocalIdentifierLockPtr>& identifier_locks,
93 const std::string& category = "unspecified",
94 boost::shared_ptr<RobotRaconteur::RobotRaconteurNode> node =
95 boost::shared_ptr<RobotRaconteur::RobotRaconteurNode>())
96{
97 auto map = YAML::Load(file_text);
98 auto info = map.as<T>();
99 detail::LoadInfoFile_traits<T>::LoadDeviceIdentifier(info, category, identifier_locks, node);
100 return info;
101}
102
125template <typename T>
126static T LoadInfoFile(const std::string& file_name, std::vector<LocalIdentifierLockPtr>& identifier_locks,
127 const std::string& category = "unspecified",
128 boost::shared_ptr<RobotRaconteur::RobotRaconteurNode> node =
129 boost::shared_ptr<RobotRaconteur::RobotRaconteurNode>())
130{
131 auto map = YAML::LoadFile(file_name);
132 auto info = map.as<T>();
133 detail::LoadInfoFile_traits<T>::LoadDeviceIdentifier(info, category, identifier_locks, node);
134 return info;
135}
136
159template <typename T>
160static T LoadInfoFileFromNode(YAML::Node& node, std::vector<LocalIdentifierLockPtr>& identifier_locks,
161 const std::string& category = "unspecified",
162 boost::shared_ptr<RobotRaconteur::RobotRaconteurNode> rr_node =
163 boost::shared_ptr<RobotRaconteur::RobotRaconteurNode>())
164{
165 auto info = node.as<T>();
166 detail::LoadInfoFile_traits<T>::LoadDeviceIdentifier(info, category, identifier_locks, rr_node);
167 return info;
168}
169
170} // namespace Util
171} // namespace Companion
172} // namespace RobotRaconteur
bool IsIdentifierAnyName(const com::robotraconteur::identifier::IdentifierPtr &identifier)
Check if an identifier is "any" name (Name is empty).
bool IsIdentifierAnyUuid(const com::robotraconteur::identifier::IdentifierPtr &identifier)
Check if an identifier is "any" (UUID is all zeros).
static T LoadInfoFileFromNode(YAML::Node &node, std::vector< LocalIdentifierLockPtr > &identifier_locks, const std::string &category="unspecified", boost::shared_ptr< RobotRaconteur::RobotRaconteurNode > rr_node=boost::shared_ptr< RobotRaconteur::RobotRaconteurNode >())
Load an info file from a YAML node.
Definition InfoFileLoader.h:160
static T LoadInfoFile(const std::string &file_name, std::vector< LocalIdentifierLockPtr > &identifier_locks, const std::string &category="unspecified", boost::shared_ptr< RobotRaconteur::RobotRaconteurNode > node=boost::shared_ptr< RobotRaconteur::RobotRaconteurNode >())
Load an info file from a file.
Definition InfoFileLoader.h:126
static T LoadInfoFileFromString(const std::string &file_text, std::vector< LocalIdentifierLockPtr > &identifier_locks, const std::string &category="unspecified", boost::shared_ptr< RobotRaconteur::RobotRaconteurNode > node=boost::shared_ptr< RobotRaconteur::RobotRaconteurNode >())
Load an info file from a string.
Definition InfoFileLoader.h:92
LocalIdentifierLockPtr GetIdentifierForNameAndLock(const std::string &category, const std::string &name, boost::shared_ptr< RobotRaconteur::RobotRaconteurNode > node=boost::shared_ptr< RobotRaconteur::RobotRaconteurNode >())
Get the Identifier For Name And Lock object.