15
15
#define HASHTREE_H
16
16
17
17
#include " hashmap.hpp"
18
+ #include " sharedptr.hpp"
18
19
19
20
template <class K , class V > class hashtree ;
20
21
template <class K , class V > int N (hashtree<K, V> tree);
21
22
template <class K , class V > bool is_nil (hashtree<K, V> tree);
22
23
23
- template <class K , class V > class hashtree_rep : concrete_struct {
24
+ template <class K , class V > class hashtree_rep {
24
25
hashmap<K, hashtree<K, V>> children;
25
26
26
27
public:
@@ -75,38 +76,26 @@ template <class K, class V> class hashtree_rep : concrete_struct {
75
76
* of NULL pointers so to speak). These NULL nodes are created by passing
76
77
* a boolean value to the hashtree constructor. One cannot accidentally
77
78
* obtain a NULL element by e.g. accessing a child (see below).
78
- *
79
- * In general, I tried to imitate the TeXmacs-way of memory management
80
- * as closely as possibly, however the workaround is not that pretty.
81
- * As more elegant way might be to modify the hashmap class so that
82
- * a hashmap contains only a pointer to a function that returns
83
- * a default value instead of a instance of a value-element.
84
- * But I didn't want to modify core TeXmacs code.
85
79
******************************************************************************/
86
80
87
- template <class K , class V > class hashtree {
88
- // CONCRETE_TEMPLATE_2(hashtree,K,V);
89
- hashtree_rep<K, V>* rep;
81
+ template <class K , class V >
82
+ class hashtree : public counted_ptr <hashtree_rep<K, V>, true > {
90
83
91
84
// this constructor always returns a NULL element
92
- inline hashtree (bool ) : rep ( NULL ) {}
85
+ inline hashtree (bool ) : base ( ) {}
93
86
94
87
// ensures that this hashtree has a rep
95
88
void realize ();
96
89
97
90
public:
98
- inline hashtree (const hashtree<K, V>&);
99
- inline ~hashtree ();
100
- inline hashtree<K, V>& operator = (hashtree<K, V> x);
101
-
102
91
// default constructor returns a non-NULL node, which does not have a value
103
- inline hashtree () : rep (tm_new<hashtree_rep<K, V>> ()) {}
92
+ inline hashtree () : base (make ()) {}
104
93
105
94
// returns a non-NULL node, that has value
106
- inline hashtree (V val) : rep (tm_new<hashtree_rep<K, V>> (val)) {}
95
+ inline hashtree (V val) : base (make (val)) {}
107
96
108
97
// returns this node's value
109
- inline hashtree_rep<K, V>* operator ->(void );
98
+ inline hashtree_rep<K, V>* operator ->();
110
99
111
100
// returns this node's child with the label "key". If the node doesn't
112
101
// have such a child, an error is raised.
@@ -120,8 +109,7 @@ template <class K, class V> class hashtree {
120
109
inline hashtree<K, V> operator [] (K key); // rw access
121
110
122
111
friend class hashtree_rep <K, V>;
123
- friend bool is_nil<K, V> (hashtree<K, V> ht);
124
- friend int N<K, V> (hashtree<K, V> ht);
112
+ friend int N<K, V> (hashtree<K, V> ht);
125
113
};
126
114
127
115
#include " hashtree.ipp"
0 commit comments