xref: /aoo41x/main/xml2cmp/source/support/heap.hxx (revision dd7bc091)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef X2C_HEAP_HXX
25 #define X2C_HEAP_HXX
26 
27 #include "sistr.hxx"
28 
29 class HeapItem;
30 
31 class Heap
32 {
33   public:
34 						Heap(
35 							unsigned			i_nWidth );
36 						~Heap();
37 
38 	void				InsertValue(
39 							const char *		i_sKey,
40 							const char *	   	i_sValue );
41 	HeapItem *		    ReleaseTop();   		/// @return must be deleted by caller of method.
42 
43   private:
44 	typedef HeapItem * Column;
45 
46 	void				IncColumn();
ActiveColumn()47 	Column &			ActiveColumn()			{ return dpColumnsArray[nActiveColumn]; }
48 
49 	Column *			dpColumnsArray;
50 	unsigned			nColumnsArraySize;
51 	unsigned			nActiveColumn;
52 };
53 
54 
55 class HeapItem
56 {
57   public:
58 						HeapItem(
59 							const char *		i_sKey,
60 							const char *	   	i_sValue );
61 						~HeapItem(  );
62 
63 	bool				operator<(
64 							const HeapItem &  	i_rOther ) const;
operator <=(const HeapItem & i_rOther) const65 	bool				operator<=(
66 							const HeapItem &  	i_rOther ) const
67 												{ return ! (i_rOther < *this); }
68 	const Simstr &		Value() const;
69 	const Simstr &		Key() const;
70 	HeapItem * 		    Next() const;
71 
72 	void        		SetNext(
73 							HeapItem *			i_pNext );
74   private:
75 	Simstr				sValue;
76 	Simstr              sKey;
77 	HeapItem *			pNext;
78 };
79 
80 
81 
82 
83 
84 
85 #endif
86 
87 
88