YARP
Yet Another Robot Platform
resource.cpp
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 
10 
11 using namespace yarp::manager;
12 
13 
19 {
20  modOwner = nullptr;
21  bAvailable = true;
22  bDisabled = false;
23  if(szTypeName)
24  strTypeName = szTypeName;
25 }
26 
28 
29 
30 
36 {
37 }
38 
39 
40 MultiResource::MultiResource(const char* szName) : GenericResource("MultipleResource")
41 {
42  setName(szName);
43 }
44 
45 
47 {
48  MultiResource::swap(resource);
49 }
50 
51 
53 {
54  GenericResource::operator=(rhs);
55  MultiResource::swap(rhs);
56  return *this;
57 }
58 
59 
61 {
62  auto* newres = (GenericResource*) res.clone();
63  resources.push_back(newres);
64  return true;
65 }
66 
68 {
69  // MultiResource is used as intermediate concept for
70  // disjunctive resource dependencies and it never
71  // can be a provider.
72  return false;
73 }
74 
75 
77 {
78  auto* resource = new MultiResource(*this);
79  return resource;
80 }
81 
82 void MultiResource::swap(const MultiResource &res)
83 {
84  clear();
85  // deep copy
86  for(int i=0; i<res.resourceCount(); i++)
87  addResource(res.getResourceAt(i));
88 }
89 
91 {
92  for(auto& resource : resources)
93  {
94  delete resource;
95  resource = nullptr;
96  }
97  resources.clear();
98 }
99 
100 
102 {
103  clear();
104 }
yarp::manager::MultiResource::resourceCount
int resourceCount() const
Definition: resource.h:81
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
Definition: application.h:24
yarp::manager::Node::clone
virtual Node * clone()=0
yarp::manager::MultiResource::MultiResource
MultiResource()
Class MultiResource.
Definition: resource.cpp:35
yarp::manager::MultiResource::operator=
MultiResource & operator=(const MultiResource &rhs)
Definition: resource.cpp:52
yarp::manager::MultiResource::~MultiResource
~MultiResource() override
Definition: resource.cpp:101
yarp::manager::RESOURCE
@ RESOURCE
Definition: ymm-types.h:29
yarp::manager::Node
a Node of a Graph
Definition: node.h:68
resource.h
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::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::setName
void setName(const char *szName)
Definition: resource.h:31