YARP
Yet Another Robot Platform
resource.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_MANAGER_RESOURCE
10 #define YARP_MANAGER_RESOURCE
11 
12 #include <yarp/manager/ymm-types.h>
13 #include <yarp/manager/node.h>
14 #include <yarp/manager/utility.h>
15 #include <yarp/conf/api.h>
16 
17 namespace yarp {
18 namespace manager {
19 
20 class GenericResource : public Node
21 {
22 public:
23  GenericResource(const char* szTypeName);
24  ~GenericResource() override;
25 
26  void setAvailability(bool flag) { bAvailable = flag; }
27  bool getAvailability() { return bAvailable; }
28  void setDisable(bool flag) { bDisabled = flag; }
29  bool getDisable() { return bDisabled; }
30 
31  void setName(const char* szName) { if(szName) { strName = szName; } }
32  const char* getName() { return strName.c_str(); }
33  void setDescription(const char* szDesc) { if(szDesc) { strDescription = szDesc; } }
34  const char* getDescription() { return strDescription.c_str(); }
35  const char* getTypeName() { return strTypeName.c_str(); }
36 
37  void setOwner(Node* owner) { modOwner = owner; }
38  Node* owner() { return modOwner; }
39  void setXmlFile(const char* szFilename) { if(szFilename) { strXmlFile = szFilename; } }
40  const char* getXmlFile() { return strXmlFile.c_str(); }
41 
42  //virtual Node* clone();
43  virtual bool satisfy(GenericResource* resource) = 0;
44 
45  bool operator==(const GenericResource& res) const {
46  return (strName == res.strName);
47  }
48 
49 protected:
50 
51 private:
52  bool bAvailable;
53  bool bDisabled;
54  std::string strName;
55  std::string strTypeName;
56  std::string strDescription;
57  Node* modOwner;
58  std::string strXmlFile;
59 
60 };
61 
62 typedef std::vector<GenericResource*> ResourcePContainer;
63 typedef std::vector<GenericResource*>::iterator ResourcePIterator;
64 
65 
66 
71 {
72 public:
73  MultiResource();
74  MultiResource(const char* szName);
75  MultiResource(const MultiResource& rhs);
77  ~MultiResource() override;
78  Node* clone() override;
79  bool satisfy(GenericResource* resource) override;
80 
81  int resourceCount() const { return resources.size(); }
82  GenericResource& getResourceAt(int index) const { return *(resources[index]); }
83  bool addResource(GenericResource& res);
84  void clear();
85 
86 protected:
87 
88 private:
89  ResourcePContainer resources;
90  void swap(const MultiResource &res);
91 };
92 
93 } // namespace yarp
94 } // namespace manager
95 
96 
97 #endif // __YARP_MANAGER_RESOURCE__
const char * getDescription()
Definition: resource.h:34
void setAvailability(bool flag)
Definition: resource.h:26
bool operator==(const GenericResource &res) const
Definition: resource.h:45
GenericResource(const char *szTypeName)
Class GenericResource.
Definition: resource.cpp:18
void setName(const char *szName)
Definition: resource.h:31
const char * getXmlFile()
Definition: resource.h:40
const char * getTypeName()
Definition: resource.h:35
void setXmlFile(const char *szFilename)
Definition: resource.h:39
void setDescription(const char *szDesc)
Definition: resource.h:33
virtual bool satisfy(GenericResource *resource)=0
void setDisable(bool flag)
Definition: resource.h:28
void setOwner(Node *owner)
Definition: resource.h:37
Class MultiResource.
Definition: resource.h:71
MultiResource()
Class MultiResource.
Definition: resource.cpp:35
bool satisfy(GenericResource *resource) override
Definition: resource.cpp:67
GenericResource & getResourceAt(int index) const
Definition: resource.h:82
MultiResource & operator=(const MultiResource &rhs)
Definition: resource.cpp:52
bool addResource(GenericResource &res)
Definition: resource.cpp:60
Node * clone() override
Definition: resource.cpp:76
a Node of a Graph
Definition: node.h:68
std::vector< GenericResource * >::iterator ResourcePIterator
Definition: resource.h:63
std::vector< GenericResource * > ResourcePContainer
Definition: resource.h:62
The main, catch-all namespace for YARP.
Definition: environment.h:25