Qore Programming Language Reference Manual  0.8.12.2
 All Classes Namespaces Functions Variables Groups Pages
Qore::TreeMap Class Reference

A container for efficient path prefix lookup. More...

Public Member Functions

 constructor ()
 Creates an empty TreeMap container. More...
 
 copy ()
 Throws an exception; objects of this class cannot be copied. More...
 
 destructor ()
 Releases any resource held by the instance. More...
 
any get (string path)
 Retrieves a value from the TreeMap. More...
 
*hash getAll ()
 Retrieves the entire TreeMap as a hash; returns NOTHING if the TreeMap is empty. More...
 
nothing put (string path, any value)
 Puts the mapping of path to value into the container. More...
 
any take (string path)
 Removes a value from the TreeMap and returns the value removed. More...
 

Detailed Description

A container for efficient path prefix lookup.

The primary use of this class is in HttpServer for matching request URIs to handlers.

Example:

1 TreeMap tm();
2 
3 tm.put("path/to/resource", handler1);
4 tm.put("scripts", handler2);
5 tm.put("scripts/special", handler3);
6 
7 tm.get("path/to/resource/x"); # returns handler1
8 tm.get("path/to/resource?arg=1"); # returns handler1
9 tm.get("path/to/res"); # returns NOTHING
10 tm.get("path/to/resourcex"); # returns NOTHING
11 tm.get("path"); # returns NOTHING
12 
13 tm.get("scripts/special/main.js"); # returns handler3
14 tm.get("scripts/normal/main.js"); # returns handler2

Member Function Documentation

Qore::TreeMap::constructor ( )

Creates an empty TreeMap container.

Creates an empty TreeMap container.

Qore::TreeMap::copy ( )

Throws an exception; objects of this class cannot be copied.

Exceptions
TREEMAP-COPY-ERRORobjects of this class cannot be copied
Qore::TreeMap::destructor ( )

Releases any resource held by the instance.

Releases any resource held by the instance.

any Qore::TreeMap::get ( string  path)

Retrieves a value from the TreeMap.

Looks for an entry whose key is the longest prefix of path.

Code Flags:
RET_VALUE_ONLY
Parameters
paththe path to lookup
Returns
the value pointed to by the longest prefix of path or NOTHING if no such mapping exists
*hash Qore::TreeMap::getAll ( )

Retrieves the entire TreeMap as a hash; returns NOTHING if the TreeMap is empty.

Code Flags:
CONSTANT
Returns
the entire TreeMap as a hash or returns NOTHING if the TreeMap is empty
nothing Qore::TreeMap::put ( string  path,
any  value 
)

Puts the mapping of path to value into the container.

Parameters
paththe path to which value will be mapped
valuethe value to put into the TreeMap
See Also
TreeMap::remove()
any Qore::TreeMap::take ( string  path)

Removes a value from the TreeMap and returns the value removed.

The path must be an exact match

Parameters
paththe path to remove
Returns
the value removed from the TreeMap or NOTHING if no exact match was found
See Also
TreeMap::put()