Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members

s11n::property_server< ContextType, ObjIDType, KeyType > Class Template Reference

property_server is an experimental class for tying arbitrary properties to arbitrary objects. More...

#include <property_server.h>

List of all members.

Public Types

typedef ContextType context_type
 The "sharing context" used by this type.

typedef ObjIDType object_id_type
 The type used to key objects to their properties.

typedef KeyType key_type
 The key type used for properties.

typedef std::map< key_type,
std::string > 
property_map_type
 The underlying data store for properties.


Static Public Member Functions

template<typename ValueType> void set (const object_id_type objid, const key_type &key, const ValueType &val)
 Sets the property key to val for objid.

template<typename ValueType> ValueType get (const object_id_type objid, const key_type &key, const ValueType &defaultval)
 Returns the property key for objid.

void unset (const object_id_type objid, const key_type &key)
 Removes the given property from the given object.

void clear (const object_id_type objid)
 Removes the property map for objid, freeing up any resources it consumed.

void clear_all ()
 Removes all properties for all objects.

property_map_typeget_map (const object_id_type objid)
 Returns a pointer to the given object's property map, or 0 if no properties have been set for the object (or if clear(objid) has been called).


Detailed Description

template<typename ContextType, typename ObjIDType = ContextType *, typename KeyType = std::string>
class s11n::property_server< ContextType, ObjIDType, KeyType >

property_server is an experimental class for tying arbitrary properties to arbitrary objects.

It supports, as values, any data types which are i/ostreamable using their >>istream or ostream<< operators.

License: Do As You Damned Well Please Author: stephan@s11n.net

Definition at line 23 of file property_server.h.


Member Function Documentation

template<typename ContextType, typename ObjIDType = ContextType *, typename KeyType = std::string>
template<typename ValueType>
ValueType s11n::property_server< ContextType, ObjIDType, KeyType >::get const object_id_type  objid,
const key_type key,
const ValueType &  defaultval
[inline, static]
 

Returns the property key for objid.

If there is an error converting the value to ValueType, or if the property does not exist, defaultval is returned. This can be used to implement custom error handling by passing a known-invalid value as defaultval and interpretting it as an error value. If there is *no* known-invalid combinations then you can check twice with two different defaulvals. If defaultval is returned both times then there is definately an error, because valid data would only be interpretted one way and you've checked against two different defaultvals.

Definition at line 63 of file property_server.h.

References s11n::property_server< ContextType, ObjIDType, KeyType >::get(), and s11n::property_server< ContextType, ObjIDType, KeyType >::property_map_type.

Referenced by s11n::property_server< ContextType, ObjIDType, KeyType >::get().

template<typename ContextType, typename ObjIDType = ContextType *, typename KeyType = std::string>
property_map_type* s11n::property_server< ContextType, ObjIDType, KeyType >::get_map const object_id_type  objid  )  [inline, static]
 

Returns a pointer to the given object's property map, or 0 if no properties have been set for the object (or if clear(objid) has been called).

The caller does not own the returned pointer and (ideally) should not modify the map directly (prefer get() and set()). It is provided here primarily for serialization purposes: so the map can be saved and loaded using arbitrary serialization techniques.

Definition at line 117 of file property_server.h.

References s11n::property_server< ContextType, ObjIDType, KeyType >::get_map(), and s11n::property_server< ContextType, ObjIDType, KeyType >::property_map_type.

Referenced by s11n::property_server< ContextType, ObjIDType, KeyType >::get_map().


The documentation for this class was generated from the following file:
Generated on Tue Jul 20 10:46:49 2004 for s11n by doxygen 1.3.7