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  virtual bool hasError(){return false;}
49 
50  protected:
51  /// @brief adds the given tag to the Device
52  void addDeviceTag(const std::string& tag);
53 
54  private:
55  std::set<std::string> tags;
56  const std::string deviceName;
57  };
58 } // namespace armarx
59 
60 //inline functions
61 namespace armarx
62 {
63  inline bool
64  DeviceBase::hasTag(const std::string& tag) const
65  {
66  return getTags().count(tag);
67  }
68 
69  inline void
70  DeviceBase::addDeviceTag(const std::string& tag)
71  {
72  tags.emplace(tag);
73  }
74 
75  inline const std::string&
77  {
78  return deviceName;
79  }
80 
81  inline const char*
83  {
84  return deviceName.c_str();
85  }
86 
87  inline const std::set<std::string>&
89  {
90  return tags;
91  }
92 } // namespace armarx
armarx::DeviceBase::getDeviceName
const std::string & getDeviceName() const
Definition: DeviceBase.h:76
armarx::DeviceBase::rtGetDeviceName
const char * rtGetDeviceName() const
Definition: DeviceBase.h:82
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:64
armarx::DeviceBase::hasError
virtual bool hasError()
Definition: DeviceBase.h:48
armarx::DeviceBase::getTags
const std::set< std::string > & getTags() const
Definition: DeviceBase.h:88
armarx::DeviceBase::addDeviceTag
void addDeviceTag(const std::string &tag)
adds the given tag to the Device
Definition: DeviceBase.h:70
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28