Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
HttpResourceTree Class Reference

Class to map URL paths to classes which handle them. More...

#include <HttpResourceTree.h>

Inheritance diagram for HttpResourceTree:
ObjectMap< String, HttpResource >

Public Member Functions

void setDefault (HttpResource *resource)
 Set the default resource handler. More...
 
void setDefault (const HttpResourceDelegate &onRequestComplete)
 Set the default resource handler, identified by "*" wildcard. More...
 
void setDefault (const HttpPathDelegate &callback)
 Set the default resource handler, identified by "*" wildcard. More...
 
HttpResourcegetDefault ()
 Get the current default resource handler, if any. More...
 
void set (const String &path, const HttpResourceDelegate &onRequestComplete)
 Set a callback to handle the given path. More...
 
void set (String path, const HttpPathDelegate &callback)
 Add a new path resource with a callback. More...
 
unsigned count () const
 Get the number of entries in this map. More...
 
const StringkeyAt (unsigned idx) const
 
StringkeyAt (unsigned idx)
 
const HttpResourcevalueAt (unsigned idx) const
 
Value valueAt (unsigned idx)
 
const HttpResourceoperator[] (const String &key) const
 Get value for given key, if it exists. More...
 
Value operator[] (const String &key)
 Access map entry by reference. More...
 
Value get (const String &key)
 Get map entry value. More...
 
void set (const String &key, HttpResource *value)
 Set a key value. More...
 
HttpResourcefind (const String &key) const
 Find the value for a given key, if it exists. More...
 
int indexOf (const String &key) const
 Get the index of a key. More...
 
bool contains (const String &key) const
 Check if a key is contained within this map. More...
 
void removeAt (unsigned index)
 Remove entry at given index. More...
 
bool remove (const String &key)
 Remove a key from this map. More...
 
HttpResourceextract (const String &key)
 Get the value for a given key and remove it from the map, without destroying it. More...
 
HttpResourceextractAt (unsigned index)
 Get the value at a given index and remove it from the map, without destroying it. More...
 
void clear ()
 Clear the map of all entries. More...
 

Protected Attributes

Vector< Entry > entries
 

Detailed Description

Class to map URL paths to classes which handle them.

Member Function Documentation

void ObjectMap< String , HttpResource >::clear ( void  )
inlineinherited

Clear the map of all entries.

bool ObjectMap< String , HttpResource >::contains ( const String key) const
inlineinherited

Check if a key is contained within this map.

Parameters
keythe key to check
Return values
booltrue if key exists
unsigned ObjectMap< String , HttpResource >::count ( ) const
inlineinherited

Get the number of entries in this map.

Return values
intEntry count
HttpResource * ObjectMap< String , HttpResource >::extract ( const String key)
inlineinherited

Get the value for a given key and remove it from the map, without destroying it.

Parameters
key
Return values
V*
Note
The returned object must be freed by the caller when no longer required
HttpResource * ObjectMap< String , HttpResource >::extractAt ( unsigned  index)
inlineinherited

Get the value at a given index and remove it from the map, without destroying it.

Parameters
index
Return values
V*
Note
The returned object must be freed by the caller when no longer required
HttpResource * ObjectMap< String , HttpResource >::find ( const String key) const
inlineinherited

Find the value for a given key, if it exists.

Parameters
key
Return values
V*Points to the object if it exists, otherwise nullptr
Note
If you need to modify the existing map entry, use operator[] or valueAt()
Value ObjectMap< String , HttpResource >::get ( const String key)
inlineinherited

Get map entry value.

Parameters
key
Return values
Value
See also
operator[]
HttpResource* HttpResourceTree::getDefault ( )
inline

Get the current default resource handler, if any.

Return values
HttpResource*
int ObjectMap< String , HttpResource >::indexOf ( const String key) const
inlineinherited

Get the index of a key.

Parameters
key
Return values
intThe index of the key, or -1 if key does not exist
const HttpResource * ObjectMap< String , HttpResource >::operator[] ( const String key) const
inlineinherited

Get value for given key, if it exists.

Parameters
key
Return values
constV* Will be null if not found in the map
Note
The caller must not use delete on the returned value
Value ObjectMap< String , HttpResource >::operator[] ( const String key)
inlineinherited

Access map entry by reference.

Parameters
key
Return values
ValueGuarded access to mapped value corresponding to given key
Note
If the given key does not exist in the map it will NOT be created
See also
valueAt()
bool ObjectMap< String , HttpResource >::remove ( const String key)
inlineinherited

Remove a key from this map.

Parameters
keyThe key identifying the entry to remove
Return values
booltrue if the value was found and removed
void ObjectMap< String , HttpResource >::removeAt ( unsigned  index)
inlineinherited

Remove entry at given index.

Parameters
indexlocation to remove from this map
void HttpResourceTree::set ( const String path,
const HttpResourceDelegate onRequestComplete 
)
inline

Set a callback to handle the given path.

Parameters
pathURL path
onRequestCompleteDelegate to handle this path
Note
Path should start with slash. Trailing slashes will be removed.
Any existing handler for this path is replaced
void HttpResourceTree::set ( String  path,
const HttpPathDelegate callback 
)

Add a new path resource with a callback.

Parameters
pathURL path
callbackThe callback that will handle this path
Note
Path should start with slash. Trailing slashes will be removed
Any existing handler for this path is replaced
void ObjectMap< String , HttpResource >::set ( const String key,
HttpResource value 
)
inlineinherited

Set a key value.

Parameters
key
value
void HttpResourceTree::setDefault ( HttpResource resource)
inline

Set the default resource handler.

Parameters
resourceThe default resource handler
void HttpResourceTree::setDefault ( const HttpResourceDelegate onRequestComplete)
inline

Set the default resource handler, identified by "*" wildcard.

Parameters
resourceThe default resource handler
void HttpResourceTree::setDefault ( const HttpPathDelegate callback)
inline

Set the default resource handler, identified by "*" wildcard.