UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ObjectsAr.H
1 /* ObjectsAr.H */
2 /* $Id: ObjectsAr.H,v 2.4 2000/09/08 17:29:28 hoh Exp $ */
3 
4 #ifndef __ObjectsAr_H
5 #define __ObjectsAr_H
6 
7 #include <stdio.h>
8 #include <mix/SortedAr.H>
9 
10 
11 /*
12  Template for a set of pointers to objects of desired class
13  AnyType MUST pe a pointer to a some class (or struct, or whatever)
14 
15  Yet most of the AnyAr features are disabled... To be done...
16 
17  For documentation see AnyAr.H (docs are also to be done...)
18  */
19 
20 template <class AnyType>
21 class ObjectsAr : public SortedAr
22 {
23 public:
24 
25  ObjectsAr (const ObjectsAr<AnyType>& pArray)
26  :SortedAr(pArray) {};
27  ObjectsAr (unsigned quant = DEFAULT_QUANT,
28  unsigned volume = START_VOLUME)
29  :SortedAr(sizeof(AnyType), quant, volume) {};
30  ~ObjectsAr(){
31  for(register int i=0;i<count();i++)
32  delete fetch(i);
33  };
34  virtual AnyType& fetch (unsigned i)
35  {return *(AnyType*)item_ptr(i);};
36  virtual AnyType get (unsigned i) const
37  {return *(AnyType*)item_ptr(i);};
38 
39  virtual void insert (unsigned i, const AnyType& val)
40  {SortedAr::insert(i, (const char*)&val);};
41 
42  virtual void addh(const AnyType& val) {SortedAr::addh((const char*)&val);};
43  virtual void addl(const AnyType& val) {SortedAr::addl((const char*)&val);};
44 
45  virtual void addh(const ObjectsAr<AnyType>& pArray){SortedAr::addh(pArray);};
46  virtual void addl(const ObjectsAr<AnyType>& pArray){SortedAr::addl(pArray);};
47 
48  ObjectsAr<AnyType>& assign (const ObjectsAr<AnyType>& pArray)
49  {SortedAr::assign(pArray); return *this;};
50 
51  // Synonyms
52  AnyType& operator[] (unsigned i)
53  {return fetch(i);};
54  AnyType operator() (unsigned i) const
55  {return get(i);};
56  ObjectsAr<AnyType>& operator= (const ObjectsAr<AnyType>& pArray)
57  {return assign(pArray);};
58 
59  // Compare between two elements
60  // If reloaded, allows the array to be sorted...
61  virtual Compar compare (const char* item1, const char* item2) const
62  {return 0;};
63 
64  // Return index of item or -1
65  int find_ascent (AnyType& item) const
66  {return quick_find_ascent((const char*)&item);}
67  int find_descent (AnyType& item) const
68  {return quick_find_descent((const char*)&item);}
69  int find (AnyType& item) const
70  {return slow_find((const char*)&item);}
71 
72 };
73 
74 #endif /* any_elements.H */
75 
76 /* Melnikov George Yu. 23-Apr-1999 */
77 /* Melnikov George Yu. 20-May-1999 */
78 /* Melnikov George Yu. 24-May-1999 */
79 /* Melnikov George Yu. 16-Jun-1999 */
Definition: SortedAr.H:14
Definition: ObjectsAr.H:21