SOIL C++
C++ Unified Device Interface
|
#include <Element.h>
Public Member Functions | |
Element (std::shared_ptr< Element > parent, std::string uuid, std::string name, std::string description, std::string ontology="") | |
Constructor. More... | |
virtual | ~Element () |
Destructor. More... | |
std::vector< std::string > | fqid (void) |
FQID. More... | |
std::shared_ptr< Element > | operator[] (std::string fqid) |
Access Operator. More... | |
std::shared_ptr< Element > | add (std::string uuid, std::shared_ptr< Element > child) |
Add Child Element. More... | |
std::shared_ptr< Element > | add (std::string uuid, Element *child) |
Add Child Element. More... | |
bool | insert (std::string uuid, std::shared_ptr< Element > child) |
Add Child Element. More... | |
bool | insert (std::string uuid, Element *child) |
Add Child Element. More... | |
bool | remove (std::string uuid) |
Remove Child element. More... | |
template<typename T > | |
T * | cast (void) |
Get dynamically casted pointer. More... | |
bool | is_object (void) const |
Is Object? More... | |
bool | is_variable (void) const |
Is Variable? More... | |
bool | is_function (void) const |
Is Function? More... | |
bool | is_parameter (void) const |
Is Parameter? More... | |
virtual HTTP::Json | wjson (void) |
HTTP JSON. More... | |
virtual std::string | json (void) |
JSON string. More... | |
HTTP::Response | handle (HTTP::Request request, std::smatch match=std::smatch()) |
HTTP Handler. More... | |
![]() | |
Resource () | |
Constructor. More... | |
~Resource () | |
Default Destructor. More... | |
virtual Response | handle (Request message, std::smatch match=std::smatch()) |
HTTP Handler. More... | |
virtual Response | handle_get (Request message, std::smatch match=std::smatch()) |
HTTP GET Handler. More... | |
virtual Response | handle_put (Request message, std::smatch match=std::smatch()) |
HTTP PUT Handler. More... | |
virtual Response | handle_post (Request message, std::smatch match=std::smatch()) |
HTTP POST Handler. More... | |
virtual Response | handle_delete (Request message, std::smatch match=std::smatch()) |
HTTP DELETE Handler. More... | |
virtual Response | handle_patch (Request message, std::smatch match=std::smatch()) |
HTTP PATCH Handler. More... | |
virtual Response | handle_options (Request message, std::smatch match=std::smatch()) |
HTTP OPTIONS Handler. More... | |
virtual Response | handle_head (Request message, std::smatch match=std::smatch()) |
HTTP HEAD Handler. More... | |
virtual Response | handle_exception (Request message, std::exception &exception, std::smatch match=std::smatch()) |
HTTP Exception handler. More... | |
Public Attributes | |
std::map< std::string, std::shared_ptr< Element > > | children |
Children Map. More... | |
std::shared_ptr< Element > | parent |
Parent Pointer. More... | |
std::shared_ptr< Element > | self |
Self Pointer. More... | |
std::string | uuid |
Local UUID. More... | |
std::string | name |
Name. More... | |
std::string | description |
Description. More... | |
std::string | ontology |
Ontology identifier. More... | |
std::recursive_mutex | mutex |
Element Mutex. More... | |
Additional Inherited Members | |
![]() | |
static web::json::value | request_info (Request message, std::smatch match=std::smatch()) |
Request Info. More... | |
![]() | |
void | apply_headers (Response &response) |
Apply headers. More... | |
![]() | |
std::vector< web::http::method > | allowed_methods |
Allowed methods. More... | |
std::string | content_type |
Content type. More... | |
std::string | allowed_origins |
Allowed Origins. More... | |
Element is the base class of Object, Function, Parameter and Variable in SOIL. It is the first class that inherits from HTTP::Resource. It contains the main implementation of the business logic for building the Element tree, i.e. managing child items and resolving absolute and relative parths. It also provides common base class which can be used for generic pointer in C++.
SOIL::Element::Element | ( | std::shared_ptr< Element > | parent, |
std::string | uuid, | ||
std::string | name, | ||
std::string | description, | ||
std::string | ontology = "" |
||
) |
Default constructor for SOIL elements, to be called from derived classes.
[in] | parent | Shared pointer to parent object. Can be set to NULL for the creation of a root object |
[in] | uuid | Locally Unique identifier |
[in] | name | Human-readable name |
[in] | description | Human-readable description |
[in] | ontology | Ontology reference, is set to null if an empty string is passed |
Definition at line 5 of file Element.cpp.
|
virtual |
Destructor for Element, which is declared virtual such that Element pointers can be used to delete instances of derived types. When an Element is deleted in SOIL, all references to the child objects are cleared.
Definition at line 19 of file Element.cpp.
std::shared_ptr< SOIL::Element > SOIL::Element::add | ( | std::string | uuid, |
Element * | child | ||
) |
Inserts a child to this element. Children are always managed as shared pointers, i.e. no object is copied. This version takes a raw pointer (as e.g. returned by new
) and internally makes a shared pointer.
[in] | uuid | UUID to assign to the child, which also acts as internal identifier |
[in] | child | Pointer to the element |
Definition at line 86 of file Element.cpp.
std::shared_ptr< SOIL::Element > SOIL::Element::add | ( | std::string | uuid, |
std::shared_ptr< Element > | child | ||
) |
Inserts a child to this element. Children are always managed as shared pointers, i.e. no object is copied.
[in] | uuid | UUID to assign to the child, which also acts as internal identifier |
[in] | child | Shared pointer to the element |
Definition at line 79 of file Element.cpp.
T * SOIL::Element::cast | ( | void | ) |
std::vector< std::string > SOIL::Element::fqid | ( | void | ) |
Constructs the FQID of the element by concatenating the UUIDs of the parent elements
Definition at line 26 of file Element.cpp.
|
virtual |
Handles an incoming HTTP request as resource. It determines the correct child item (or the itdem itself) and than calls the handler of the HTTP::Resource base clase. The arguments are directly passed on to the latter.
[in] | message | Incoming HTTP request as preprocessed by cpprestsdk |
[in] | match | Match result of the request path that led to this resource |
Reimplemented from HTTP::Resource.
Definition at line 155 of file Element.cpp.
bool SOIL::Element::insert | ( | std::string | uuid, |
Element * | child | ||
) |
Alias to add provide compatibilty to prior versions.
new
) and internally makes a shared pointer. [in] | uuid | UUID to assign to the child, which also acts as internal identifier |
[in] | child | Pointer to the element |
Definition at line 98 of file Element.cpp.
bool SOIL::Element::insert | ( | std::string | uuid, |
std::shared_ptr< Element > | child | ||
) |
Alias to add provide compatibilty to prior versions.
[in] | uuid | UUID to assign to the child, which also acts as internal identifier |
[in] | child | Shared pointer to the element |
Definition at line 91 of file Element.cpp.
bool SOIL::Element::is_function | ( | void | ) | const |
Determines whether the element actually is a function. Internally, the prefix FUN- of the UUID is checked for this purpose. This function is typically used before dynamic casts.
Definition at line 120 of file Element.cpp.
bool SOIL::Element::is_object | ( | void | ) | const |
Determines whether the element actually is an object. Internally, the prefix OBJ- of the UUID is checked for this purpose. This function is typically used before dynamic casts.
Definition at line 110 of file Element.cpp.
bool SOIL::Element::is_parameter | ( | void | ) | const |
Determines whether the element actually is a parameter. Internally, the prefix PAR- of the UUID is checked for this purpose. This function is typically used before dynamic casts.
Definition at line 125 of file Element.cpp.
bool SOIL::Element::is_variable | ( | void | ) | const |
Determines whether the element actually is a variable. Internally, the prefix VAR- of the UUID is checked for this purpose. This function is typically used before dynamic casts.
Definition at line 115 of file Element.cpp.
|
virtual |
Get a JSON string corresponding to the current state of the element. This function internally useses wjson() such that there is no need to override both methods in derived classes.
Definition at line 148 of file Element.cpp.
std::shared_ptr< SOIL::Element > SOIL::Element::operator[] | ( | std::string | fqid | ) |
Returns the child matching the relative FQID of the element. If the empty string is passed, the element itself is resturned.
std::runtime_error | If no matching child is found, a runtime_error is thrown. |
[in] | fqid | Relative FQID of the element to retrieve |
Definition at line 38 of file Element.cpp.
bool SOIL::Element::remove | ( | std::string | uuid | ) |
Removes an element from the children of this element. If the internal shared pointer is the last reference to this element, it will go out of scope.
[in] | uuid | UUID to identify the element to remove |
Definition at line 103 of file Element.cpp.
|
virtual |
Get a HTTP JSON object corresponding to the current state of the element. This function is virtual as normally it should be specialized by Object, Variable, Parameter and Function.
Reimplemented in SOIL::Function, SOIL::Object, SOIL::Figure< T, x, y >, SOIL::Figure< T, -1, -1 >, SOIL::Parameter< T, x, y >, and SOIL::Variable< T, x, y >.
Definition at line 130 of file Element.cpp.
std::map<std::string, std::shared_ptr<Element> > SOIL::Element::children |
std::string SOIL::Element::description |
std::recursive_mutex SOIL::Element::mutex |
std::string SOIL::Element::name |
std::string SOIL::Element::ontology |
std::shared_ptr<Element> SOIL::Element::parent |
std::shared_ptr<Element> SOIL::Element::self |
std::string SOIL::Element::uuid |