![]() |
|||
|
|
// track variable count usage class Counter : public Listable
{ public: INLINE Counter() { _count = 1; } INLINE ~Counter() {} // object classes to do work INLINE incr() { _count++;} INLINE int number() { return _count; } // for Listable Counter & operator = (const Counter & counter); INLINE Counter *clone() const { return new Counter( *this ); } INLINE Listable *listable_clone() const { return (Listable *) clone(); } INLINE void print(ostream &o) const { o << "Counter : " << _count; } private: int _count; }; // for usage in constructs template class TypedCollection; template class List; template class Iterator; template class Assign; template class RefSet;
template class Map<symbol ,counter=""> template class KeyIterator<symbol ,counter=""> template class ProtoMap<symbol ,counter=""> template class TypedBaseMap<symbol ,counter="">Then you can use the Map as follows:
Map<symbol ,counter=""> * ct_map = new Map<symbol ,counter=""> Symbol sym;
Counter count;
// notice count is cloned as Map takes ownership ct_map->ins(sym, count.clone());
KeyIteratorout(*ct_map, STOP_ON_GHOSTS); for (; out.valid(); ++out) { Symbol & sym = out.current_key(); Counter & ct = out.current_data(); cout << sym << " "; ct.print(cout); cout << endl; }
One allows change and one does not. Do not mix the two. Also in deleting an object on a list be careful not to blow up the Iterator.A RefList just points to a real List, you cannot delete in a RefList.
There are DominanceFrontiers and other goodies.
It has some good examples of manipulating the code.
However, do not depend solely on them. MAN pages are woefully incomplete.
Asserts will bite you. Read them very carefully and hope you changed very little code.
Parasol Home | Research | People | General info | Seminars | Resources Parasol Lab, 301 Harvey R. Bright Bldg, 3112 TAMU, College Station, TX 77843-3112 Contact Webmaster Phone 979.458.0722 Fax 979.458.0718
Department of Computer Science and Engineering | Dwight Look College of Engineering | Texas A&M University Privacy statement: Computer Science and Engineering Engineering TAMU |