item_collection Class Template Reference

An item collection is a mapping from tags to items. More...

List of all members.

Public Types

typedef Tag tag_ype
 the tag type

Public Member Functions

template<class Derived>
 item_collection (context< Derived > *ctxt)
 constructor which registers collection with given context
void put (const Tag &tag, const Item &item, int get_count=-1)
 make copies of the item and the tag and store them in the collection.
void get (const Tag &tag, Item &item) const
 get an item
bool unsafe_get (const Tag &t, Item &i) const
 try to get an item and store it in given object (non-blocking)
const_iterator begin () const
 returns begin() as in STL containers
const_iterator end () const
 returns end() as in STL containers
void reset ()
 removes all of the item instances from the collection
size_t size ()
 returns number of elements in collection
bool empty ()
 returns true if size()==0, false otherwise


Detailed Description

template<typename Tag, typename Item, typename hash_compare = cnc_tag_hash_compare< Tag >>
class CnC::item_collection< Tag, Item, hash_compare >

An item collection is a mapping from tags to items.

Tag and Item must provide copy and default constructors and the assigment operator.

If Tag is not convertable into size_t, a suitable cnc_tag_hash_compare struct must be provided which satisifies the requirements for tbb::concurrent_hash_map. The default cnc_tag_hash_compare works for types that can be converted to size_t and have an operator==. You can provide a specialized template for cnc_tag_hash_compare or specify and implement your own compatible class.

The CnC runtime will make a copy of your item when it is 'put' into the item_collection. The CnC runtime will delete the copied item copy once the get-count reaches 0 (or, if no get-count was provided, once the collection is destroyed). If the item-type is a pointer type, the runtime will not delete the memory the item points to.

Definition at line 166 of file cnc.h.


Constructor & Destructor Documentation

item_collection ( context< Derived > *  ctxt  )  [inline]

constructor which registers collection with given context

Parameters:
ctxt the context this collection belongs to


Member Function Documentation

void put ( const Tag &  tag,
const Item &  item,
int  get_count = -1 
)

make copies of the item and the tag and store them in the collection.

Parameters:
tag the tag identifying the item
item the item to be copied and stored
get_count after get_count many 'get()'s the item can be removed by default, the item is not removed until the collection is deleted.

void get ( const Tag &  tag,
Item &  item 
) const

get an item

Parameters:
tag the tag identifying the item
item reference to item to store result in
Exceptions:
DataNotReady throws exception if data not yet available.

bool unsafe_get ( const Tag &  t,
Item &  i 
) const

try to get an item and store it in given object (non-blocking)

Attention:
This method is unsafe: you can create non-deterministic results if you decide to to perform semantically relevant actions if an item is unavailable (returns false)
If the item is unavailable, it does not change item. Make sure you call flush_gets() after last call to this method (of any item collection) within a step. In any case, you must check the return value before accessing the item.
Parameters:
tat the tag identifying the item
item reference to item to store result in
Returns:
true if item is available
Exceptions:
DataNotReady might throw exception if data not available (yet)

const_iterator begin (  )  const

returns begin() as in STL containers

Note:
iteration through collections is not thread safe, use it only between calls to CnC::context::wait() and putting tags

const_iterator end (  )  const

returns end() as in STL containers

Note:
iteration through collections is not thread safe, use it only between calls to CnC::context::wait() and putting tags


The documentation for this class was generated from the following file:

Generated on Tue Aug 31 15:30:28 2010 for CnC by  doxygen 1.5.6