Qore Programming Language Reference Manual  0.8.11.1
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...
 
nothing put (string path, any value)
 Puts the mapping of path to value into the container. 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:

TreeMap tm();
tm.put("path/to/resource", handler1);
tm.put("scripts", handler2);
tm.put("scripts/special", handler3);
tm.get("path/to/resource/x"); # returns handler1
tm.get("path/to/resource?arg=1"); # returns handler1
tm.get("path/to/res"); # returns NOTHING
tm.get("path/to/resourcex"); # returns NOTHING
tm.get("path"); # returns NOTHING
tm.get("scripts/special/main.js"); # returns handler3
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:
CONSTANT
Parameters
paththe path to lookup
Returns
the value pointed to by the longest prefix of path or NOTHING if no such mapping exists
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