DeviceBase.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package RobotAPI
17  * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
18  * @date 2017
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 #include "../util.h"
26 
27 namespace armarx
28 {
29  class DeviceBase
30  {
31  public:
32  /// @brief Create a Device with the given name
33  DeviceBase(const std::string& name) : deviceName{name}
34  {
35  }
36 
37  virtual ~DeviceBase() = default;
38  /// @return The Device's name
39  const std::string& getDeviceName() const;
40  /// @return The Device's name
41  const char* rtGetDeviceName() const;
42  //tags
43  /// @return Thes set of tags for this Device
44  const std::set<std::string>& getTags() const;
45  /// @return Whether the device has the given tag
46  bool hasTag(const std::string& tag) const;
47 
48  protected:
49  /// @brief adds the given tag to the Device
50  void addDeviceTag(const std::string& tag);
51 
52  private:
53  std::set<std::string> tags;
54  const std::string deviceName;
55  };
56 } // namespace armarx
57 
58 //inline functions
59 namespace armarx
60 {
61  inline bool
62  DeviceBase::hasTag(const std::string& tag) const
63  {
64  return getTags().count(tag);
65  }
66 
67  inline void
68  DeviceBase::addDeviceTag(const std::string& tag)
69  {
70  tags.emplace(tag);
71  }
72 
73  inline const std::string&
75  {
76  return deviceName;
77  }
78 
79  inline const char*
81  {
82  return deviceName.c_str();
83  }
84 
85  inline const std::set<std::string>&
87  {
88  return tags;
89  }
90 } // namespace armarx
armarx::DeviceBase::getDeviceName
const std::string & getDeviceName() const
Definition: DeviceBase.h:74
armarx::DeviceBase::rtGetDeviceName
const char * rtGetDeviceName() const
Definition: DeviceBase.h:80
armarx::DeviceBase
Definition: DeviceBase.h:29
armarx::DeviceBase::DeviceBase
DeviceBase(const std::string &name)
Create a Device with the given name.
Definition: DeviceBase.h:33
armarx::DeviceBase::~DeviceBase
virtual ~DeviceBase()=default
armarx::DeviceBase::hasTag
bool hasTag(const std::string &tag) const
Definition: DeviceBase.h:62
armarx::DeviceBase::getTags
const std::set< std::string > & getTags() const
Definition: DeviceBase.h:86
armarx::DeviceBase::addDeviceTag
void addDeviceTag(const std::string &tag)
adds the given tag to the Device
Definition: DeviceBase.h:68
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28