YARP
Yet Another Robot Platform
resource.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 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__
yarp::manager::GenericResource::setDisable
void setDisable(bool flag)
Definition: resource.h:28
yarp::manager::MultiResource::resourceCount
int resourceCount() const
Definition: resource.h:81
yarp::manager::GenericResource::setAvailability
void setAvailability(bool flag)
Definition: resource.h:26
yarp::manager::MultiResource::getResourceAt
GenericResource & getResourceAt(int index) const
Definition: resource.h:82
yarp::manager::MultiResource::clear
void clear()
Definition: resource.cpp:90
yarp::manager::GenericResource::~GenericResource
~GenericResource() override
yarp::manager::GenericResource::getDescription
const char * getDescription()
Definition: resource.h:34
yarp::manager::MultiResource::MultiResource
MultiResource()
Class MultiResource.
Definition: resource.cpp:35
yarp::manager::GenericResource::getDisable
bool getDisable()
Definition: resource.h:29
yarp::manager::ResourcePContainer
std::vector< GenericResource * > ResourcePContainer
Definition: resource.h:62
utility.h
yarp::manager::MultiResource::operator=
MultiResource & operator=(const MultiResource &rhs)
Definition: resource.cpp:52
yarp::manager::GenericResource::setXmlFile
void setXmlFile(const char *szFilename)
Definition: resource.h:39
yarp::manager::GenericResource::setDescription
void setDescription(const char *szDesc)
Definition: resource.h:33
yarp::manager::GenericResource::satisfy
virtual bool satisfy(GenericResource *resource)=0
yarp::manager::MultiResource::~MultiResource
~MultiResource() override
Definition: resource.cpp:101
yarp::manager::GenericResource::getXmlFile
const char * getXmlFile()
Definition: resource.h:40
node.h
yarp::manager::Node
a Node of a Graph
Definition: node.h:68
yarp::manager::GenericResource::owner
Node * owner()
Definition: resource.h:38
ymm-types.h
yarp::manager::GenericResource::operator==
bool operator==(const GenericResource &res) const
Definition: resource.h:45
yarp::manager::GenericResource::getAvailability
bool getAvailability()
Definition: resource.h:27
yarp::manager::GenericResource::setOwner
void setOwner(Node *owner)
Definition: resource.h:37
yarp::manager::MultiResource
Class MultiResource.
Definition: resource.h:71
yarp::manager::GenericResource::GenericResource
GenericResource(const char *szTypeName)
Class GenericResource.
Definition: resource.cpp:18
yarp::manager::GenericResource
Definition: resource.h:21
yarp::manager::ResourcePIterator
std::vector< GenericResource * >::iterator ResourcePIterator
Definition: resource.h:63
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::manager::MultiResource::satisfy
bool satisfy(GenericResource *resource) override
Definition: resource.cpp:67
yarp::manager::MultiResource::clone
Node * clone() override
Definition: resource.cpp:76
yarp::manager::MultiResource::addResource
bool addResource(GenericResource &res)
Definition: resource.cpp:60
yarp::manager::GenericResource::getTypeName
const char * getTypeName()
Definition: resource.h:35
yarp::manager::GenericResource::setName
void setName(const char *szName)
Definition: resource.h:31
api.h
yarp::manager::GenericResource::getName
const char * getName()
Definition: resource.h:32