19 _id(id), _operation(operation), _isSingle(isSingle), _isMandatory(isMandatory), _typeID(dataType) {
24 _operation = resource._operation;
25 _isSingle = resource._isSingle;
26 _isMandatory = resource._isMandatory;
27 _typeID = resource._typeID;
28 _instances = resource._instances;
29 _dataVerifier = resource._dataVerifier;
34 _operation = resource._operation;
35 _isSingle = resource._isSingle;
36 _isMandatory = resource._isMandatory;
37 _typeID = resource._typeID;
38 _instances = std::move(resource._instances);
39 resource._instances.clear();
40 _dataVerifier = resource._dataVerifier;
44 if (
this == &resource)
return *
this;
47 _operation = resource._operation;
48 _isSingle = resource._isSingle;
49 _isMandatory = resource._isMandatory;
50 _typeID = resource._typeID;
51 _instances = resource._instances;
52 _dataVerifier = resource._dataVerifier;
58 if (
this == &resource)
return *
this;
61 _operation = resource._operation;
62 _isSingle = resource._isSingle;
63 _isMandatory = resource._isMandatory;
64 _typeID = resource._typeID;
65 _instances = std::move(resource._instances);
66 resource._instances.clear();
67 _dataVerifier = resource._dataVerifier;
100 bool Resource::isInstanceIdPossible(
ID_T resInstId)
const {
105 return getInstIter(resInstId) != _instances.end();
108 bool Resource::isTypeIdCompatible(
TYPE_ID type)
const {
120 return _typeID == type;
124 return _instances.size();
128 std::vector<ID_T> ids;
129 ids.reserve(_instances.size());
130 std::transform(_instances.begin(), _instances.end(), std::back_inserter(ids), [](
const auto& inst) { return inst.id; });
136 if (!
isExist(_instances.size()))
return _instances.size();
146 WPP_LOGW(
TAG_WPP_RES,
"Resource[%d], instance with ID %d not found or resource is SINGLE", _id, resInstId);
149 auto instForRemove = getInstIter(resInstId);
150 _instances.erase(instForRemove);
165 if (!isDataVerifierValid(verifier)) {
169 _dataVerifier = verifier;
173 bool Resource::isDataVerifierValid(
const DATA_VERIFIER_T &verifier)
const {
174 if (std::holds_alternative<VERIFY_BOOL_T>(verifier) && std::get<VERIFY_BOOL_T>(verifier))
return _typeID ==
TYPE_ID::BOOL;
175 else if (std::holds_alternative<VERIFY_INT_T>(verifier) && std::get<VERIFY_INT_T>(verifier))
return _typeID ==
TYPE_ID::INT;
176 else if (std::holds_alternative<VERIFY_UINT_T>(verifier) && std::get<VERIFY_UINT_T>(verifier))
return _typeID ==
TYPE_ID::UINT;
177 else if (std::holds_alternative<VERIFY_FLOAT_T>(verifier) && std::get<VERIFY_FLOAT_T>(verifier))
return _typeID ==
TYPE_ID::FLOAT;
178 else if (std::holds_alternative<VERIFY_OPAQUE_T>(verifier) && std::get<VERIFY_OPAQUE_T>(verifier))
return _typeID ==
TYPE_ID::OPAQUE;
179 else if (std::holds_alternative<VERIFY_OBJ_LINK_T>(verifier) && std::get<VERIFY_OBJ_LINK_T>(verifier))
return _typeID ==
TYPE_ID::OBJ_LINK;
181 else if (std::holds_alternative<VERIFY_STRING_T>(verifier) && std::get<VERIFY_STRING_T>(verifier))
return _typeID ==
TYPE_ID::STRING || _typeID ==
TYPE_ID::CORE_LINK;
182 else if (std::holds_alternative<VERIFY_EXECUTE_T>(verifier) && std::get<VERIFY_EXECUTE_T>(verifier))
return _typeID ==
TYPE_ID::EXECUTE;
186 std::vector<Resource::ResInst>::iterator Resource::getInstIter(
ID_T resInstId)
const {
187 auto finder = [&resInstId](
const ResInst &inst) ->
bool {
return inst.id == resInstId; };
188 return std::find_if(_instances.begin(), _instances.end(), finder);
#define WPP_LOGW(TAG, FMT,...)
#define SINGLE_INSTANCE_ID
The Resource class in the wpp namespace is a comprehensive and flexible class designed to handle diff...
bool clear()
Remove all instances.
bool isExist(ID_T resInstId) const
Check if the instance ID is exist.
Resource & operator=(const Resource &other)
bool remove(ID_T resInstId)
Remove resource instance if resource is MULTIPLE and instance exists, if the resource is SINGLE remov...
std::variant< VERIFY_INT_T, VERIFY_UINT_T, VERIFY_FLOAT_T, VERIFY_OPAQUE_T, VERIFY_BOOL_T, VERIFY_OBJ_LINK_T, VERIFY_STRING_T, VERIFY_EXECUTE_T > DATA_VERIFIER_T
Universal type for data validation functions.
const ItemOp & getOperation() const
size_t instCount() const
Get the number of resource instances.
ID_T newInstId() const
Find first available instance ID that is not used.
std::vector< ID_T > instIds() const
Returns vector with available ids of resource instances.
bool setDataVerifier(const DATA_VERIFIER_T &verifier)
Set data verifier for the resource.
TYPE_ID getTypeId() const
The WppConnection class represents a connection interface for the Wpp library.
TYPE_ID
Wpp data types ID.
The ItemOp struct represents the operations that can be performed on a instance/resource.