1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: symtreenode.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef ARY_SYMTREE_NODE_HXX
32 #define ARY_SYMTREE_NODE_HXX
48 /** Represents a node in a tree of symbols like a namespace tree or a
52 Needs to define the types:
53 entity_base_type: The type of the entities in that storage,
54 e.g. ->ary::cpp::CodeEntity.
55 id_type: The type of the ids of those entities,
56 e.g. ->ary::cpp::Ce_id.
58 Needs to define the functions:
59 1. static entity_base_type &
62 2. static symtree::Node<LeNode_Traits> *
64 const entity_base_type &
66 3. static const String &
68 const entity_base_type &
70 4. static entity_base_type *
72 const entity_base_type &
74 5. template <class KEY>
76 const entity_base_type &
78 const KEY & i_localKey );
80 template <class NODE_TRAITS
>
84 typedef Node
<NODE_TRAITS
> node_self
;
85 typedef typename
NODE_TRAITS::entity_base_type entity_t
;
86 typedef typename
NODE_TRAITS::id_type id_t
;
90 /// @attention Always needs to be followed by ->Assign_Entity()!
93 entity_t
& i_entity
);
95 entity_t
& i_entity
);
99 const String
Name() const;
101 const entity_t
& Entity() const;
102 const node_self
* Parent() const;
104 /** Gets a child with a specific name and of a specific type.
106 There may be more childs with the same name.
108 @return id_t(0), if no matching child is found.
111 typename
NODE_TRAITS::id_type
113 const KEY
& i_localKey
) const
115 // Inline here to workaround SUNW8 compiler bug, works in SUNW12.
116 return NODE_TRAITS::Search_(Entity(), i_localKey
);
120 /** Gets a child with a specific qualified name below this node.
122 The child may not exists.
126 id_t
& o_return
, // Workaround SUNW8 compiler bug
127 StringVector::const_iterator
128 i_qualifiedSearchedName_begin
,
129 StringVector::const_iterator
130 i_qualifiedSearchedName_end
,
131 const KEY
& i_localKey
) const;
133 /** Gets a child with a specific qualified name, either below this node
134 or below any of the parent nodes.
136 The child may not exists.
140 id_t
& o_return
, // Workaround SUNW8 compiler bug
141 StringVector::const_iterator
142 i_qualifiedSearchedName_begin
,
143 StringVector::const_iterator
144 i_qualifiedSearchedName_end
,
145 const KEY
& i_localKey
) const;
148 node_self
* Parent();
152 Node(const node_self
&);
153 node_self
& operator=(const node_self
&);
157 node_self
* Get_Parent() const;
171 template <class NODE_TRAITS
>
172 inline const typename Node
<NODE_TRAITS
>::entity_t
&
173 Node
<NODE_TRAITS
>::Entity() const
175 csv_assert(pEntity
!= 0);
179 template <class NODE_TRAITS
>
180 inline Node
<NODE_TRAITS
> *
181 Node
<NODE_TRAITS
>::NodeOf(id_t i_id
) const
184 return NODE_TRAITS::NodeOf_(NODE_TRAITS::EntityOf_(i_id
));
188 template <class NODE_TRAITS
>
189 inline Node
<NODE_TRAITS
> *
190 Node
<NODE_TRAITS
>::Get_Parent() const
193 parent
= NODE_TRAITS::ParentOf_(Entity());
195 return NODE_TRAITS::NodeOf_(*parent
);
199 template <class NODE_TRAITS
>
200 Node
<NODE_TRAITS
>::Node()
206 template <class NODE_TRAITS
>
207 Node
<NODE_TRAITS
>::Node(entity_t
& i_entity
)
208 : pEntity(&i_entity
),
214 template <class NODE_TRAITS
>
216 Node
<NODE_TRAITS
>::Assign_Entity(entity_t
& i_entity
)
222 template <class NODE_TRAITS
>
223 Node
<NODE_TRAITS
>::~Node()
227 template <class NODE_TRAITS
>
228 inline typename Node
<NODE_TRAITS
>::id_t
229 Node
<NODE_TRAITS
>::Id()
231 return NODE_TRAITS::IdOf(Entity());
234 template <class NODE_TRAITS
>
236 Node
<NODE_TRAITS
>::Name() const
238 return NODE_TRAITS::LocalNameOf_(Entity());
241 template <class NODE_TRAITS
>
243 Node
<NODE_TRAITS
>::Depth() const
248 template <class NODE_TRAITS
>
249 inline const Node
<NODE_TRAITS
> *
250 Node
<NODE_TRAITS
>::Parent() const
255 template <class NODE_TRAITS
>
258 Node
<NODE_TRAITS
>::SearchBelow(
259 id_t
& o_return
, // Workaround SUNW8 compiler bug
260 StringVector::const_iterator i_qualifiedSearchedName_begin
,
261 StringVector::const_iterator i_qualifiedSearchedName_end
,
262 const KEY
& i_localKey
) const
264 if (i_qualifiedSearchedName_begin
!= i_qualifiedSearchedName_end
)
267 next
= Search(*i_qualifiedSearchedName_begin
);
271 subnode
= NodeOf(next
);
274 subnode
->SearchBelow( o_return
,
275 i_qualifiedSearchedName_begin
+1,
276 i_qualifiedSearchedName_end
,
285 o_return
= Search(i_localKey
);
288 template <class NODE_TRAITS
>
291 Node
<NODE_TRAITS
>::SearchUp(
292 id_t
& o_return
, // Workaround SUNW8 compiler bug
293 StringVector::const_iterator i_qualifiedSearchedName_begin
,
294 StringVector::const_iterator i_qualifiedSearchedName_end
,
295 const KEY
& i_localKey
) const
297 SearchBelow( o_return
,
298 i_qualifiedSearchedName_begin
,
299 i_qualifiedSearchedName_end
,
301 if (o_return
.IsValid())
305 parent
= Get_Parent();
308 parent
->SearchUp( o_return
,
309 i_qualifiedSearchedName_begin
,
310 i_qualifiedSearchedName_end
,
315 template <class NODE_TRAITS
>
316 typename Node
<NODE_TRAITS
>::entity_t
&
317 Node
<NODE_TRAITS
>::Entity()
319 csv_assert(pEntity
!= 0);
323 template <class NODE_TRAITS
>
324 inline Node
<NODE_TRAITS
> *
325 Node
<NODE_TRAITS
>::Parent()
330 template <class NODE_TRAITS
>
332 Node
<NODE_TRAITS
>::InitDepth()
337 nDepth
= pp
->Depth() + 1;
345 } // namespace symtree