rasdaman complete source
collection.hh
Go to the documentation of this file.
1 /*
2 * This file is part of rasdaman community.
3 *
4 * Rasdaman community is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Rasdaman community is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
18 rasdaman GmbH.
19 *
20 * For more information please see <http://www.rasdaman.org>
21 * or contact Peter Baumann via <baumann@rasdaman.com>.
22 /
33 #ifndef _D_COLLECTION_
34 #define _D_COLLECTION_
35 
36 #include "raslib/error.hh"
37 #include "rasodmg/object.hh"
38 
39 template <class T>
40 class r_Iterator;
41 
42 //@ManMemo: Module: {\bf rasodmg}
43 
44 /*@Doc:
45 
46  Basic class of a collection. Possible subclasses are \Ref{r_Set},
47  \Ref{r_Bag} and \Ref{r_List}. The protected members isOrdered and
48  allowsDuplicates are not initialized here, they have to be initialized
49  in the respective subclasses.
50 
51 */
52 
56 template <class T>
57 class r_Collection : public r_Object
58 {
59  friend class r_Iterator<T>;
60 
61 public:
63  r_Collection() throw(r_Error);
65  r_Collection( const r_Collection<T>& collection ) throw(r_Error);
67  virtual ~r_Collection();
68 
70  virtual void r_deactivate();
71 
73  inline unsigned long cardinality() const;
74 
76  inline int is_empty() const;
78  inline int is_ordered() const;
80  inline int allows_duplicates() const;
81 
83  int contains_element( const T& element ) const;
85  virtual void insert_element( const T& element, int no_modification = 0 );
91  virtual void remove_element( const T& element );
94  void remove_all();
95 
97  const r_Collection<T>& operator=( const r_Collection<T>& collection );
98 
101 
104 
105  //@Man: Methods for database communication (internal use only):
107 
110  virtual void insert_obj_into_db();
111 
113  virtual void insert_obj_into_db( const char* )
114  {
115  ;
116  };
122  virtual void update_obj_in_db();
124 
126 
127 
128  //@Man: Constructors/Methods for internal use only:
130 
133  r_Collection( const void* node1 );
135  inline void* get_internal_representation() const;
137  void set_internal_representation( const void* node1 );
138 
140 
141 
142 protected:
144  struct CNode
145  {
147  T* elem;
148  };
149 
150  //@Man: Methods/Attributes for maintainance of removed objects
152 
156 
160 
162 
163 
164  //@Man: Attributes storing some state information
166  int isOrdered;
172  unsigned long card;
174 
175 
176  // Normally, we would have used the following class to implement the
177  // internal structure of a r_Collection. But for RPC's sake, we use
178  // a simple structure. (RPC is not able to transfer C++ objects.)
179  //
180  // template <class T>
181  // class CNode
182  // {
183  // public:
184  // CNode();
185  // CNode( const CNode& cnode );
186  // ~CNode();
187  //
188  // inline CNode* get_next() const;
189  // inline void set_next( const CNode& cnode );
190  // inline T* get_elem() const;
191  // inline void set_elem( const T& element);
192  //
193  // private:
194  // CNode* next;
195  // T* elem;
196  // }
197 
198  //@Man: Methods for manipulating CNode lists
200 
203  void add_node( CNode* &root, const T& element );
205  int remove_node( CNode* &root, const T& element );
207  void remove_all_nodes( CNode* &root );
209  void init_node_list( CNode* &root );
210 
212 
213 
215  CNode* coll;
216 };
217 
218 #include "rasodmg/collection.icc"
219 
220 #ifdef EARLY_TEMPLATE
221 #ifdef __EXECUTABLE__
222 #ifdef __VISUALC__
223 #include "collection.cpp"
224 #else
225 #include "collection.cc"
226 #endif
227 #endif
228 #endif
229 
230 #endif
T * elem
Definition: collection.hh:147
r_Iterator< T > create_iterator()
create an iterator pointing at the first element in the collection
virtual void r_deactivate()
it is called when an object leaves transient memory
void remove_all_nodes(CNode *&root)
Definition: collection.hh:40
Definition: error.hh:88
Definition: raslib/type.hh:56
int is_empty() const
tells if the collection is empty or not
void set_internal_representation(const void *node1)
int allows_duplicates() const
tells if the collections allowes duplicates or not
CNode * coll
pointer to collection elements
Definition: collection.hh:215
virtual void insert_element(const T &element, int no_modification=0)
inserts an alement at the beginning
void * get_internal_representation() const
virtual void insert_obj_into_db()
insert myself into the database
Definition: collection.hh:144
int is_ordered() const
tells if the collection is ordered or not
Definition: collection.hh:57
Definition: object.hh:64
CNode * next
Definition: collection.hh:146
unsigned long cardinality() const
get number of elements
void init_node_list(CNode *&root)
int remove_node(CNode *&root, const T &element)
const r_Type * get_element_type_schema()
get base type schema
virtual void remove_element(const T &element)
removes an element
r_Collection()
default constructor
int contains_element(const T &element) const
asks about the containment of a specific element
virtual void update_obj_in_db()
update myself
int allowsDuplicates
Definition: collection.hh:170
unsigned long card
Definition: collection.hh:172
CNode * removed_objects
pointer to list of removed elements
Definition: collection.hh:159
void remove_all()
removes all elements
void add_node(CNode *&root, const T &element)
r_Iterator< T > create_removed_iterator()
create an iterator for removed objects
int isOrdered
Definition: collection.hh:168