SOIL C++
C++ Unified Device Interface
SOIL::Element Class Reference

SOIL Base Element. More...

#include <Element.h>

Inheritance diagram for SOIL::Element:
HTTP::Resource SOIL::Figure< T, -1, -1 > SOIL::Figure< T, x, y > SOIL::Function SOIL::Object SOIL::Parameter< T, x, y > SOIL::Variable< T, x, y >

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< Elementoperator[] (std::string fqid)
 Access Operator. More...
 
std::shared_ptr< Elementadd (std::string uuid, std::shared_ptr< Element > child)
 Add Child Element. More...
 
std::shared_ptr< Elementadd (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...
 
- Public Member Functions inherited from HTTP::Resource
 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< Elementparent
 Parent Pointer. More...
 
std::shared_ptr< Elementself
 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 Public Member Functions inherited from HTTP::Resource
static web::json::value request_info (Request message, std::smatch match=std::smatch())
 Request Info. More...
 
- Protected Member Functions inherited from HTTP::Resource
void apply_headers (Response &response)
 Apply headers. More...
 
- Protected Attributes inherited from HTTP::Resource
std::vector< web::http::method > allowed_methods
 Allowed methods. More...
 
std::string content_type
 Content type. More...
 
std::string allowed_origins
 Allowed Origins. More...
 

Detailed Description

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++.

Definition at line 23 of file Element.h.

Constructor & Destructor Documentation

◆ Element()

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.

Parameters
[in]parentShared pointer to parent object. Can be set to NULL for the creation of a root object
[in]uuidLocally Unique identifier
[in]nameHuman-readable name
[in]descriptionHuman-readable description
[in]ontologyOntology reference, is set to null if an empty string is passed

Definition at line 5 of file Element.cpp.

◆ ~Element()

SOIL::Element::~Element ( )
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.

Postcondition
If the parent element was the last instance to contain shared pointers to the child elements, their lifecycle will end with this operation.

Definition at line 19 of file Element.cpp.

Member Function Documentation

◆ add() [1/2]

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.

Parameters
[in]uuidUUID to assign to the child, which also acts as internal identifier
[in]childPointer to the element
Returns
Shared pointer to child element

Definition at line 86 of file Element.cpp.

◆ add() [2/2]

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.

Parameters
[in]uuidUUID to assign to the child, which also acts as internal identifier
[in]childShared pointer to the element
Returns
Shared pointer to child element

Definition at line 79 of file Element.cpp.

◆ cast()

template<typename T >
T * SOIL::Element::cast ( void  )

Dynamically casts the stored element reference to a given type. This useful for casting pointers to derived classes of which the type is known.

Template Parameters
TDervied type to cast to.
Returns
Raw pointer

Definition at line 264 of file Element.h.

◆ fqid()

std::vector< std::string > SOIL::Element::fqid ( void  )

Constructs the FQID of the element by concatenating the UUIDs of the parent elements

Returns
FQID string separated by /

Definition at line 26 of file Element.cpp.

◆ handle()

HTTP::Response SOIL::Element::handle ( HTTP::Request  request,
std::smatch  match = std::smatch() 
)
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.

Parameters
[in]messageIncoming HTTP request as preprocessed by cpprestsdk
[in]matchMatch result of the request path that led to this resource
Returns
Outgoing HTTP response to be processed by cpprestdsk

Reimplemented from HTTP::Resource.

Definition at line 155 of file Element.cpp.

◆ insert() [1/2]

bool SOIL::Element::insert ( std::string  uuid,
Element child 
)

Alias to add provide compatibilty to prior versions.

Todo:
Remove in future versions. This version takes a raw pointer (as e.g. returned by new) and internally makes a shared pointer.
Parameters
[in]uuidUUID to assign to the child, which also acts as internal identifier
[in]childPointer to the element
Returns
True if the element previously already existed.

Definition at line 98 of file Element.cpp.

◆ insert() [2/2]

bool SOIL::Element::insert ( std::string  uuid,
std::shared_ptr< Element child 
)

Alias to add provide compatibilty to prior versions.

Todo:
Remove in future versions.
Parameters
[in]uuidUUID to assign to the child, which also acts as internal identifier
[in]childShared pointer to the element
Returns
True if the element previously already existed.

Definition at line 91 of file Element.cpp.

◆ is_function()

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.

Returns
Boolean response whether the element is a function.

Definition at line 120 of file Element.cpp.

◆ is_object()

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.

Returns
Boolean response whether the element is an object.

Definition at line 110 of file Element.cpp.

◆ is_parameter()

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.

Returns
Boolean response whether the element is a parameter.

Definition at line 125 of file Element.cpp.

◆ is_variable()

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.

Returns
Boolean response whether the element is at.

Definition at line 115 of file Element.cpp.

◆ json()

std::string SOIL::Element::json ( void  )
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.

Returns
JSON string

Definition at line 148 of file Element.cpp.

◆ operator[]()

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.

Exceptions
std::runtime_errorIf no matching child is found, a runtime_error is thrown.
Parameters
[in]fqidRelative FQID of the element to retrieve
Returns
Share pointer to the requested element

Definition at line 38 of file Element.cpp.

◆ remove()

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.

Parameters
[in]uuidUUID to identify the element to remove
Returns
True if the element existed prior to deletion.

Definition at line 103 of file Element.cpp.

◆ wjson()

HTTP::Json SOIL::Element::wjson ( void  )
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.

Returns
JSON object

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.

Member Data Documentation

◆ children

std::map<std::string, std::shared_ptr<Element> > SOIL::Element::children

Map of child elements, which are referenced by means of shared pointers and identified by their local UUID in string form.

Definition at line 32 of file Element.h.

◆ description

std::string SOIL::Element::description

Human-readable description of the element in string format.

Definition at line 67 of file Element.h.

◆ mutex

std::recursive_mutex SOIL::Element::mutex

Recursive Mutex to provide thread safe access to SOIL elements.

Definition at line 83 of file Element.h.

◆ name

std::string SOIL::Element::name

Human-readable name of the element in string format.

Definition at line 60 of file Element.h.

◆ ontology

std::string SOIL::Element::ontology

Ontology identifier, can be set to null if no ontology is followed

Precondition
Referencing to an ontology prerequisites that an ontology in SOIL format has been declared elsewhere.

Definition at line 76 of file Element.h.

◆ parent

std::shared_ptr<Element> SOIL::Element::parent

Shared pointer reference to the parent element.

Definition at line 39 of file Element.h.

◆ self

std::shared_ptr<Element> SOIL::Element::self

Shared pointer reference to the element itself.

Definition at line 46 of file Element.h.

◆ uuid

std::string SOIL::Element::uuid

Locally unique identifier of the object, which must start with OBJ-, FUN-, PAR-, or VAR- depending on the type.

Definition at line 53 of file Element.h.


The documentation for this class was generated from the following files: