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: nametreenode.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_NAMETREENODE_HXX
32 #define ARY_NAMETREENODE_HXX
33 // KORR_DEPRECATED_3.0
34 // Replace by ::ary::symtree::Node.
37 #include <cosv/tpl/tpltools.hxx>
38 #include <sci_impl.hxx>
39 // HACK because of SunPro 5.2 compiler bug with templates:
40 #include <ary/idl/i_module.hxx>
49 /** Implementation of a node in a namespace-tree.
51 template<class ITEM_ID
>
55 typedef NameTreeNode self
;
56 typedef ITEM_ID item_id
;
57 typedef StringVector::const_iterator name_iterator
;
58 typedef std::map
<String
, item_id
> Map_LocalNames
;
63 const String
& i_sName
,
64 const self
& i_rParent
,
65 ITEM_ID i_nParentId
);
66 virtual ~NameTreeNode();
70 const String
& i_sName
,
73 const String
& Name() const { return Depth() > 0 ? aCompleteNameChain
.back() : String::Null_(); }
74 item_id
Parent() const { return nParent
; }
75 intt
Depth() const { return aCompleteNameChain
.size(); }
80 name_iterator
NameChain_Begin() const { return aCompleteNameChain
.begin(); }
81 name_iterator
NameChain_End() const { return aCompleteNameChain
.end(); }
84 const String
& i_sName
) const;
86 Dyn_StdConstIterator
<ITEM_ID
> &
88 const Map_LocalNames
&
89 LocalNames() const { return aLocalNames
; }
92 Map_LocalNames
& LocalNames() { return aLocalNames
; }
95 Map_LocalNames aLocalNames
;
96 StringVector aCompleteNameChain
;
104 template<class ITEM_ID
>
105 NameTreeNode
<ITEM_ID
>::NameTreeNode()
107 aCompleteNameChain(),
112 template<class ITEM_ID
>
113 NameTreeNode
<ITEM_ID
>::NameTreeNode( const String
& i_sName
,
114 const self
& i_rParent
,
115 ITEM_ID i_nParentId
)
117 aCompleteNameChain(),
120 aCompleteNameChain
.reserve(i_rParent
.Depth()+1);
121 for ( name_iterator it
= i_rParent
.NameChain_Begin();
122 it
!= i_rParent
.NameChain_End();
125 aCompleteNameChain
.push_back(*it
);
127 aCompleteNameChain
.push_back(i_sName
);
130 template<class ITEM_ID
>
131 NameTreeNode
<ITEM_ID
>::~NameTreeNode()
136 template<class ITEM_ID
>
138 NameTreeNode
<ITEM_ID
>::Add_Name( const String
& i_sName
,
141 LocalNames().insert( typename
Map_LocalNames::value_type(i_sName
, i_nId
) );
145 template<class ITEM_ID
>
147 NameTreeNode
<ITEM_ID
>::IsEquivalent( const NameTreeNode
& i_rNode
) const
149 return aCompleteNameChain
== i_rNode
.aCompleteNameChain
;
152 template<class ITEM_ID
>
154 NameTreeNode
<ITEM_ID
>::Search_Name( const String
& i_sName
) const
156 return csv::value_from_map(LocalNames(),i_sName
, ITEM_ID(0));
159 template<class ITEM_ID
>
161 NameTreeNode
<ITEM_ID
>::Get_Names( Dyn_StdConstIterator
<ITEM_ID
> & o_rResult
) const
163 o_rResult
= new SCI_DataInMap
<String
,item_id
>(LocalNames());
167 // HACK because of SunPro 5.2 compiler bug with templates:
168 // ary::idl::Module has to be "FIND_NODE::node_type"
169 // must be solved later somehow.
170 template <class FIND_NODE
>
171 typename
FIND_NODE::id_type
172 Search_SubTree( const ary::idl::Module
& i_rStart
,
173 const FIND_NODE
& i_rNodeFinder
)
175 const ary::idl::Module
*
178 for ( StringVector::const_iterator it
= i_rNodeFinder
.Begin();
179 it
!= i_rNodeFinder
.End() AND ret
!= 0;
182 ret
= i_rNodeFinder(ret
->Search_Name(*it
));
185 typename
FIND_NODE::id_type
nret(0);
187 ? ret
->Search_Name(i_rNodeFinder
.Name2Search())
191 template <class FIND_NODE
>
192 typename
FIND_NODE::id_type
193 Search_SubTree_UpTillRoot( const ary::idl::Module
& i_rStart
,
194 const FIND_NODE
& i_rNodeFinder
)
196 typename
FIND_NODE::id_type
198 for ( const ary::idl::Module
* start
= &i_rStart
;
199 start
!= 0 AND NOT ret
.IsValid();
200 start
= i_rNodeFinder(start
->Owner()) )
202 ret
= Search_SubTree( *start
,
207 // END Hack for SunPro 5.2 compiler bug.