Merge branch 'master' into jwi-bcc64xsingletonwarning
[ACE_TAO.git] / ACE / apps / JAWS2 / JAWS / Assoc_Array.h
blob1890efb101835d97baec61076d9553b8ddb1a20b
1 /* -*- c++ -*- */
2 #ifndef JAWS_ASSOC_ARRAY_H
3 #define JAWS_ASSOC_ARRAY_H
5 template <class KEY, class DATA> class JAWS_Assoc_Array_Iterator;
7 template <class KEY, class DATA>
8 class JAWS_Assoc_Array
10 friend class JAWS_Assoc_Array_Iterator<KEY, DATA>;
12 public:
13 JAWS_Assoc_Array (int maxsize = 1024);
14 ~JAWS_Assoc_Array ();
16 int index (const KEY &k);
17 // Returns the index into the array associated with key k
18 // Returns -1 if not found.
20 DATA * find (const KEY &k);
21 // Returns the data associated with key k. 0 if not found.
23 DATA * find_by_index (int i);
24 // Returns the data associated with array index i. Returns 0 if the
25 // index is invalid.
27 DATA * insert (const KEY &k, const DATA &d);
28 // Inserts a *copy* of the key and data into the associated array.
29 // Both KEY and DATA must have well defined semantics for copy
30 // construction. This method returns a pointer to the inserted item
31 // copy, or 0 if an error occurred. NOTE: if an identical key
32 // already exists in the tree, no new item is created, and the
33 // returned pointer addresses the existing item associated with the
34 // existing key.
36 int remove (const KEY &k);
37 // Removes the item associated with the given key from the
38 // tree and destroys it. Returns 1 if it found the item
39 // and successfully destroyed it, 0 if it did not find the
40 // item, or -1 if an error occurred.
42 void clear ();
43 // Destroys all keys and associated data.
45 protected:
46 int find_i (const KEY &k);
47 // If k points to an associated data item, then this function
48 // returns the index into the arrays that hold it. Otherwise, it
49 // returns an index suitable to insert the item. If the item is not
50 // found and the table is full, maxsize_ is returned.
52 private:
53 KEY **k_array_;
54 DATA **d_array_;
55 int maxsize_;
58 template <class KEY, class DATA>
59 class JAWS_Assoc_Array_Iterator
61 public:
62 JAWS_Assoc_Array_Iterator (const JAWS_Assoc_Array<KEY, DATA> &aa);
63 ~JAWS_Assoc_Array_Iterator ();
65 KEY * key ();
66 DATA * data ();
68 int first ();
69 int last ();
70 int next ();
71 int previous ();
72 int is_done ();
74 private:
75 // declare private and do not define: explicitly
76 // prevent assignment and copy construction of iterators
77 JAWS_Assoc_Array_Iterator (const JAWS_Assoc_Array_Iterator<KEY, DATA> &);
78 void operator= (const JAWS_Assoc_Array_Iterator<KEY, DATA> &);
80 private:
81 const JAWS_Assoc_Array<KEY, DATA> &aa_;
83 int i_;
84 // The current item pointed by iterator.
86 int j_;
87 // The next item to be pointed to by iterator.
90 #include "JAWS/Assoc_Array.cpp"
92 #endif /* !defined (JAWS_ASSOC_ARRAY_H) */