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:

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-ERROR | objects 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

  path | the 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

  path | the path to which `value` will be mapped
  value | the 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

  path | the path to remove

Returns
  the value removed from the TreeMap or NOTHING if no exact match was found

See Also
  TreeMap::put()