hueplusplus
1.0.0
|
Handles a list of a certain API resource. More...
#include <hueplusplus/ResourceList.h>
Public Types | |
using | ResourceType = Resource |
using | IdType = IdT |
Public Member Functions | |
ResourceList (std::shared_ptr< APICache > baseCache, const std::string &cacheEntry, std::chrono::steady_clock::duration refreshDuration, bool sharedState=false, const std::function< Resource(IdType, const nlohmann::json &, const std::shared_ptr< APICache > &)> &factory=nullptr) | |
Construct ResourceList using a base cache and optional factory function. More... | |
ResourceList (const HueCommandAPI &commands, const std::string &path, std::chrono::steady_clock::duration refreshDuration, const std::function< Resource(IdType, const nlohmann::json &, const std::shared_ptr< APICache > &)> &factory=nullptr) | |
Construct ResourceList with a separate cache and optional factory function. More... | |
ResourceList (const ResourceList &)=delete | |
Deleted copy constructor. More... | |
ResourceList & | operator= (const ResourceList &)=delete |
Deleted copy assignment. More... | |
void | refresh () |
Refreshes internal state now. More... | |
void | setRefreshDuration (std::chrono::steady_clock::duration refreshDuration) |
Sets custom refresh interval for this list and all resources created. More... | |
std::vector< Resource > | getAll () |
Get all resources that exist. More... | |
Resource | get (const IdType &id) |
Get resource specified by id. More... | |
bool | exists (const IdType &id) |
Checks whether resource with id exists. More... | |
bool | exists (const IdType &id) const |
Checks whether resource with id exists. More... | |
bool | remove (const IdType &id) |
Removes the resource. More... | |
Protected Member Functions | |
Resource | construct (const IdType &id, const nlohmann::json &state) |
Constructs resource using factory or constructor, if available. More... | |
ResourceList (ResourceList &&)=default | |
Protected defaulted move constructor. More... | |
ResourceList & | operator= (ResourceList &&)=default |
Protected defaulted move assignment. More... | |
Static Protected Member Functions | |
static IdType | maybeStoi (const std::string &key) |
Calls std::stoi if IdType is int. More... | |
static std::string | maybeToString (const IdType &id) |
Calls std::to_string if IdType is int. More... | |
Protected Attributes | |
std::shared_ptr< APICache > | stateCache |
std::function< Resource(IdType, const nlohmann::json &, const std::shared_ptr< APICache > &)> | factory |
std::string | path |
bool | sharedState |
Handles a list of a certain API resource.
Resource | Resource type that is in the list |
IdT | Type of the resource id. int or std::string |
The resources are assumed to be in an object with ids as keys. The Resource class needs a constructor that accepts id
, HueCommandAPI, refreshDuration
and state
; otherwise a factory function needs to be provided that takes id
, state
and a base cache that is null when shared state is disabled.
using hueplusplus::ResourceList< Resource, IdT >::IdType = IdT |
using hueplusplus::ResourceList< Resource, IdT >::ResourceType = Resource |
|
inline |
Construct ResourceList using a base cache and optional factory function.
baseCache | Base cache which holds the parent state, not nullptr |
cacheEntry | Entry name of the list state in the base cache |
refreshDuration | Interval between refreshing the cache |
sharedState | Whether created resources should share the same base cache. |
factory | Optional factory function to create Resources. Necessary if Resource is not constructible as described above. |
|
inline |
Construct ResourceList with a separate cache and optional factory function.
commands | HueCommandAPI for requests |
path | Path of the resource list |
refreshDuration | Interval between refreshing the cache |
factory | Optional factory function to create Resources. Necessary if Resource is not constructible as described above. |
|
delete |
Deleted copy constructor.
|
protecteddefault |
Protected defaulted move constructor.
|
inlineprotected |
Constructs resource using factory or constructor, if available.
HueException | when factory is nullptr and Resource cannot be constructed as specified above. |
|
inline |
Checks whether resource with id exists.
id | Identifier of the resource to check |
std::system_error | when system or socket operations fail |
HueException | when response contains no body |
HueAPIResponseException | when response contains an error |
nlohmann::json::parse_error | when response could not be parsed |
|
inline |
Checks whether resource with id exists.
id | Identifier of the resource to check |
HueException | when the cache is empty |
|
inline |
Get resource specified by id.
id | Identifier of the resource |
std::system_error | when system or socket operations fail |
HueException | when id does not exist |
HueAPIResponseException | when response contains an error |
nlohmann::json::parse_error | when response could not be parsed |
|
inline |
Get all resources that exist.
std::system_error | when system or socket operations fail |
HueException | when response contains no body |
HueAPIResponseException | when response contains an error |
nlohmann::json::parse_error | when response could not be parsed |
|
inlinestaticprotected |
Calls std::stoi if IdType is int.
|
inlinestaticprotected |
Calls std::to_string if IdType is int.
|
delete |
Deleted copy assignment.
|
protecteddefault |
Protected defaulted move assignment.
|
inline |
Refreshes internal state now.
|
inline |
Removes the resource.
id | Identifier of the resource to remove |
std::system_error | when system or socket operations fail |
HueException | when response contains no body |
HueAPIResponseException | when response contains an error |
nlohmann::json::parse_error | when response could not be parsed |
If successful, invalidates references to the Resource removed.
|
inline |
Sets custom refresh interval for this list and all resources created.
refreshDuration | The new minimum duration between refreshes. May be 0 or c_refreshNever. |
|
protected |
|
protected |
|
protected |
|
protected |