Friendly LWM2M client
wpp::ResourceContainer Class Referenceabstract

#include <ResourceContainer.h>

+ Inheritance diagram for wpp::ResourceContainer:
+ Collaboration diagram for wpp::ResourceContainer:

Public Member Functions

 ResourceContainer ()=default
 
virtual ~ResourceContainer ()=default
 
bool isSingle (ID_T resId)
 Check if the resource is SINGLE. More...
 
bool isMultiple (ID_T resId)
 Check if the resource is MULTIPLE. More...
 
bool isExist (ID_T resId)
 Check if the instance ID is exist. More...
 
bool isExist (ID_T resId, ID_T resInstId)
 Check if the instance ID is exist. More...
 
size_t instCount (ID_T resId)
 Get the number of resource instances. More...
 
std::vector< ID_TinstIds (ID_T resId)
 Returns vector with available ids of resource instances. More...
 
ID_T newInstId (ID_T resId)
 Find first available instance ID that is not used. More...
 
template<typename T >
bool set (ID_T resId, const T &value)
 Set data value by copy for the resource. More...
 
template<typename T >
bool set (ID_T resId, ID_T resInstId, const T &value)
 Set data value by copy for the resource instance. More...
 
template<typename T >
bool set (ID_T resId, T &&value)
 Set data value by move for the resource. More...
 
template<typename T >
bool set (ID_T resId, ID_T resInstId, T &&value)
 Set data value by move for the resource instance. More...
 
template<typename T >
const T & get (ID_T resId, ID_T resInstId=SINGLE_INSTANCE_ID)
 
template<typename T >
bool add (ID_T resId, const T &value)
 Add new instance with data value by copy for the MULTIPLE resource. More...
 
template<typename T >
bool add (ID_T resId, T &&value)
 Add new instance with data value by move for the MULTIPLE resource. More...
 
bool removeRes (ID_T resId, ID_T resInstId)
 Remove resource instance if resource is MULTIPLE and instance exists, if the resource is SINGLE remove is not possible. More...
 
bool clearRes (ID_T resId)
 Remove all instances. More...
 

Protected Member Functions

void setupResources (const std::vector< Resource > &resources)
 This methods setup resources list. More...
 
void setupResources (std::vector< Resource > &&resources)
 
Resourceresource (ID_T resId)
 This method return resource ptr if it exists. If resources does not exist then return NULL. More...
 
std::vector< Resource > & resources ()
 This method return list with all resources that has been defined. More...
 
virtual void resourceOperationNotifier (ItemOp::TYPE type, ID_T resId, ID_T resInstId)=0
 This method must be implemented by the derived class, and handle information about resource operation (WRITE, DELETE). Called by ResourceContainer after resource operation performed. More...
 

Detailed Description

Definition at line 13 of file ResourceContainer.h.

Constructor & Destructor Documentation

◆ ResourceContainer()

wpp::ResourceContainer::ResourceContainer ( )
default

◆ ~ResourceContainer()

virtual wpp::ResourceContainer::~ResourceContainer ( )
virtualdefault

Member Function Documentation

◆ add() [1/2]

template<typename T >
bool wpp::ResourceContainer::add ( ID_T  resId,
const T &  value 
)

Add new instance with data value by copy for the MULTIPLE resource.

Parameters
valueThe data value to add
resIdThe resource ID
Note
If the resource is SINGLE, the method will return false. If the data type is not valid, the method will return false. Instance ID will be generated automatically.The ID is determined according to the following algorithm: if the ID is equal to the number of free instances, then we return it, otherwise, starting with ID 0, we search for the first free index, if no free indexes are found, then method returns false.
Returns
True if the instance is added, false otherwise

Definition at line 269 of file ResourceContainer.h.

+ Here is the call graph for this function:

◆ add() [2/2]

template<typename T >
bool wpp::ResourceContainer::add ( ID_T  resId,
T &&  value 
)

Add new instance with data value by move for the MULTIPLE resource.

Parameters
valueThe data value to add
resIdThe resource ID
Note
If the resource is SINGLE, the method will return false. If the data type is not valid, the method will return false. Instance ID will be generated automatically. The ID is determined according to the following algorithm: if the ID is equal to the number of free instances, then we return it, otherwise, starting with ID 0, we search for the first free index, if no free indexes are found, then method returns false.
Returns
True if the instance is added, false otherwise

Definition at line 294 of file ResourceContainer.h.

+ Here is the call graph for this function:

◆ clearRes()

bool wpp::ResourceContainer::clearRes ( ID_T  resId)

Remove all instances.

Note
If the resource is SINGLE, the method will return false.
Returns
True if all instances are removed, false otherwise.

Definition at line 74 of file ResourceContainer.cpp.

+ Here is the call graph for this function:

◆ get()

template<typename T >
const T & wpp::ResourceContainer::get ( ID_T  resId,
ID_T  resInstId = SINGLE_INSTANCE_ID 
)

Definition at line 255 of file ResourceContainer.h.

+ Here is the call graph for this function:

◆ instCount()

size_t wpp::ResourceContainer::instCount ( ID_T  resId)

Get the number of resource instances.

Parameters
resIdThe resource ID
Note
If the resource is SINGLE, the number of instances is always 1
Returns
The number of resource instances

Definition at line 36 of file ResourceContainer.cpp.

+ Here is the call graph for this function:

◆ instIds()

std::vector< ID_T > wpp::ResourceContainer::instIds ( ID_T  resId)

Returns vector with available ids of resource instances.

Parameters
resIdThe resource ID
Note
If the resource is SINGLE, the vector will be contain only one element with value SINGLE_INSTANCE_ID

Definition at line 45 of file ResourceContainer.cpp.

+ Here is the call graph for this function:

◆ isExist() [1/2]

bool wpp::ResourceContainer::isExist ( ID_T  resId)

Check if the instance ID is exist.

Parameters
resIdThe resource ID
Returns
True if the instance ID is exist, false otherwise

Definition at line 23 of file ResourceContainer.cpp.

+ Here is the call graph for this function:

◆ isExist() [2/2]

bool wpp::ResourceContainer::isExist ( ID_T  resId,
ID_T  resInstId 
)

Check if the instance ID is exist.

Parameters
resIdThe resource ID
resInstIdThe instance ID to check
Note
If the resource is SINGLE, the instance ID always SINGLE_INSTANCE_ID
Returns
True if the instance ID is exist, false otherwise

Definition at line 27 of file ResourceContainer.cpp.

+ Here is the call graph for this function:

◆ isMultiple()

bool wpp::ResourceContainer::isMultiple ( ID_T  resId)

Check if the resource is MULTIPLE.

Parameters
resIdThe resource ID

Definition at line 14 of file ResourceContainer.cpp.

+ Here is the call graph for this function:

◆ isSingle()

bool wpp::ResourceContainer::isSingle ( ID_T  resId)

Check if the resource is SINGLE.

Parameters
resIdThe resource ID

Definition at line 5 of file ResourceContainer.cpp.

+ Here is the call graph for this function:

◆ newInstId()

ID_T wpp::ResourceContainer::newInstId ( ID_T  resId)

Find first available instance ID that is not used.

Parameters
resIdThe resource ID
Note
If the resource is SINGLE, the method will return ID_T_MAX_VAL
Returns
The first available instance ID else ID_T_MAX_VAL

Definition at line 54 of file ResourceContainer.cpp.

+ Here is the call graph for this function:

◆ removeRes()

bool wpp::ResourceContainer::removeRes ( ID_T  resId,
ID_T  resInstId 
)

Remove resource instance if resource is MULTIPLE and instance exists, if the resource is SINGLE remove is not possible.

Parameters
resIdThe resource ID
resInstIdThe instance ID to remove
Returns
True if the instance is removed, false otherwise.

Definition at line 63 of file ResourceContainer.cpp.

+ Here is the call graph for this function:

◆ resource()

Resource * wpp::ResourceContainer::resource ( ID_T  resId)
protected

This method return resource ptr if it exists. If resources does not exist then return NULL.

Parameters
resId- Resource ID.
Returns
Resource pointer or NULL.

Definition at line 93 of file ResourceContainer.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resourceOperationNotifier()

virtual void wpp::ResourceContainer::resourceOperationNotifier ( ItemOp::TYPE  type,
ID_T  resId,
ID_T  resInstId 
)
protectedpure virtual

This method must be implemented by the derived class, and handle information about resource operation (WRITE, DELETE). Called by ResourceContainer after resource operation performed.

Implemented in wpp::Instance.

+ Here is the caller graph for this function:

◆ resources()

std::vector< Resource > & wpp::ResourceContainer::resources ( )
protected

This method return list with all resources that has been defined.

Definition at line 99 of file ResourceContainer.cpp.

+ Here is the caller graph for this function:

◆ set() [1/4]

template<typename T >
bool wpp::ResourceContainer::set ( ID_T  resId,
const T &  value 
)

Set data value by copy for the resource.

Parameters
valueThe data value to set
resIdThe resource ID
Note
Before set new value its type will be checked. If resource is MULTIPLE then method set value for instance with ID SINGLE_INSTANCE_ID.
Returns
True if the value is set, false otherwise

Definition at line 215 of file ResourceContainer.h.

+ Here is the caller graph for this function:

◆ set() [2/4]

template<typename T >
bool wpp::ResourceContainer::set ( ID_T  resId,
ID_T  resInstId,
const T &  value 
)

Set data value by copy for the resource instance.

Parameters
valueThe data value to set
resIdThe resource ID
resInstIdThe instance ID to set the value, used only for MULTIPLE resources
Note
Before set new value its type will be checked. If resource is SINGLE then method will ignore
Parameters
resInstId.
Returns
True if the value is set, false otherwise

Definition at line 220 of file ResourceContainer.h.

+ Here is the call graph for this function:

◆ set() [3/4]

template<typename T >
bool wpp::ResourceContainer::set ( ID_T  resId,
ID_T  resInstId,
T &&  value 
)

Set data value by move for the resource instance.

Parameters
valueThe data value to set
resIdThe resource ID
resInstIdThe instance ID to set the value, used only for MULTIPLE resources
Note
Before set new value its type will be checked. If resource is SINGLE then method will ignore
Parameters
resInstId.
Returns
True if the value is set, false otherwise

Definition at line 240 of file ResourceContainer.h.

+ Here is the call graph for this function:

◆ set() [4/4]

template<typename T >
bool wpp::ResourceContainer::set ( ID_T  resId,
T &&  value 
)

Set data value by move for the resource.

Parameters
valueThe data value to set
resIdThe resource ID
Note
Before set new value its type will be checked. If resource is MULTIPLE then method will return false.
Returns
True if the value is set, false otherwise

Definition at line 235 of file ResourceContainer.h.

+ Here is the call graph for this function:

◆ setupResources() [1/2]

void wpp::ResourceContainer::setupResources ( const std::vector< Resource > &  resources)
protected

This methods setup resources list.

Definition at line 85 of file ResourceContainer.cpp.

+ Here is the call graph for this function:

◆ setupResources() [2/2]

void wpp::ResourceContainer::setupResources ( std::vector< Resource > &&  resources)
protected

Definition at line 89 of file ResourceContainer.cpp.

+ Here is the call graph for this function: