xref: /AOO41X/main/autodoc/source/ary/inc/nametreenode.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef ARY_NAMETREENODE_HXX
29*cdf0e10cSrcweir #define ARY_NAMETREENODE_HXX
30*cdf0e10cSrcweir //  KORR_DEPRECATED_3.0
31*cdf0e10cSrcweir //      Replace by ::ary::symtree::Node.
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir // USED SERVICES
34*cdf0e10cSrcweir #include <cosv/tpl/tpltools.hxx>
35*cdf0e10cSrcweir #include <sci_impl.hxx>
36*cdf0e10cSrcweir // HACK because of SunPro 5.2 compiler bug with templates:
37*cdf0e10cSrcweir #include <ary/idl/i_module.hxx>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir namespace ary
43*cdf0e10cSrcweir {
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir /** Implementation of a node in a namespace-tree.
47*cdf0e10cSrcweir */
48*cdf0e10cSrcweir template<class ITEM_ID>
49*cdf0e10cSrcweir class NameTreeNode
50*cdf0e10cSrcweir {
51*cdf0e10cSrcweir   public:
52*cdf0e10cSrcweir     typedef NameTreeNode                    self;
53*cdf0e10cSrcweir     typedef ITEM_ID                         item_id;
54*cdf0e10cSrcweir     typedef StringVector::const_iterator    name_iterator;
55*cdf0e10cSrcweir     typedef std::map<String, item_id>       Map_LocalNames;
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir     // LIFECYCLE
58*cdf0e10cSrcweir                         NameTreeNode();
59*cdf0e10cSrcweir                         NameTreeNode(
60*cdf0e10cSrcweir                             const String &      i_sName,
61*cdf0e10cSrcweir                             const self &        i_rParent,
62*cdf0e10cSrcweir                             ITEM_ID             i_nParentId );
63*cdf0e10cSrcweir     virtual             ~NameTreeNode();
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir     // OPERATIONS
66*cdf0e10cSrcweir     void                Add_Name(
67*cdf0e10cSrcweir                             const String &      i_sName,
68*cdf0e10cSrcweir                             item_id             i_nId );
69*cdf0e10cSrcweir     // INQUIRY
70*cdf0e10cSrcweir     const String &      Name() const            { return Depth() > 0 ? aCompleteNameChain.back() : String::Null_(); }
71*cdf0e10cSrcweir     item_id             Parent() const          { return nParent; }
72*cdf0e10cSrcweir     intt                Depth() const           { return aCompleteNameChain.size(); }
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir     bool                IsEquivalent(
75*cdf0e10cSrcweir                             const NameTreeNode &
76*cdf0e10cSrcweir                                                 i_rNode ) const;
77*cdf0e10cSrcweir     name_iterator       NameChain_Begin() const { return aCompleteNameChain.begin(); }
78*cdf0e10cSrcweir     name_iterator       NameChain_End() const   { return aCompleteNameChain.end(); }
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir     item_id             Search_Name(
81*cdf0e10cSrcweir                             const String &      i_sName ) const;
82*cdf0e10cSrcweir     void                Get_Names(
83*cdf0e10cSrcweir                             Dyn_StdConstIterator<ITEM_ID> &
84*cdf0e10cSrcweir                                                 o_rResult ) const;
85*cdf0e10cSrcweir     const Map_LocalNames &
86*cdf0e10cSrcweir                         LocalNames() const      { return aLocalNames; }
87*cdf0e10cSrcweir   private:
88*cdf0e10cSrcweir     // Locals
89*cdf0e10cSrcweir     Map_LocalNames &    LocalNames()            { return aLocalNames; }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir     // DATA
92*cdf0e10cSrcweir     Map_LocalNames      aLocalNames;
93*cdf0e10cSrcweir     StringVector        aCompleteNameChain;
94*cdf0e10cSrcweir     item_id             nParent;
95*cdf0e10cSrcweir };
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir // IMPLEMENTATION
101*cdf0e10cSrcweir template<class ITEM_ID>
102*cdf0e10cSrcweir NameTreeNode<ITEM_ID>::NameTreeNode()
103*cdf0e10cSrcweir     :   aLocalNames(),
104*cdf0e10cSrcweir         aCompleteNameChain(),
105*cdf0e10cSrcweir         nParent(0)
106*cdf0e10cSrcweir {
107*cdf0e10cSrcweir }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir template<class ITEM_ID>
110*cdf0e10cSrcweir NameTreeNode<ITEM_ID>::NameTreeNode( const String &      i_sName,
111*cdf0e10cSrcweir                                      const self &        i_rParent,
112*cdf0e10cSrcweir                                      ITEM_ID             i_nParentId )
113*cdf0e10cSrcweir     :   aLocalNames(),
114*cdf0e10cSrcweir         aCompleteNameChain(),
115*cdf0e10cSrcweir         nParent(i_nParentId)
116*cdf0e10cSrcweir {
117*cdf0e10cSrcweir     aCompleteNameChain.reserve(i_rParent.Depth()+1);
118*cdf0e10cSrcweir     for ( name_iterator it = i_rParent.NameChain_Begin();
119*cdf0e10cSrcweir           it != i_rParent.NameChain_End();
120*cdf0e10cSrcweir           ++it )
121*cdf0e10cSrcweir     {
122*cdf0e10cSrcweir         aCompleteNameChain.push_back(*it);
123*cdf0e10cSrcweir     }
124*cdf0e10cSrcweir     aCompleteNameChain.push_back(i_sName);
125*cdf0e10cSrcweir }
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir template<class ITEM_ID>
128*cdf0e10cSrcweir NameTreeNode<ITEM_ID>::~NameTreeNode()
129*cdf0e10cSrcweir {
130*cdf0e10cSrcweir }
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir template<class ITEM_ID>
134*cdf0e10cSrcweir inline void
135*cdf0e10cSrcweir NameTreeNode<ITEM_ID>::Add_Name( const String &      i_sName,
136*cdf0e10cSrcweir                                  item_id             i_nId )
137*cdf0e10cSrcweir {
138*cdf0e10cSrcweir     LocalNames().insert( typename Map_LocalNames::value_type(i_sName, i_nId) );
139*cdf0e10cSrcweir }
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir template<class ITEM_ID>
143*cdf0e10cSrcweir inline bool
144*cdf0e10cSrcweir NameTreeNode<ITEM_ID>::IsEquivalent( const NameTreeNode & i_rNode ) const
145*cdf0e10cSrcweir {
146*cdf0e10cSrcweir     return aCompleteNameChain == i_rNode.aCompleteNameChain;
147*cdf0e10cSrcweir }
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir template<class ITEM_ID>
150*cdf0e10cSrcweir inline ITEM_ID
151*cdf0e10cSrcweir NameTreeNode<ITEM_ID>::Search_Name( const String & i_sName ) const
152*cdf0e10cSrcweir {
153*cdf0e10cSrcweir     return csv::value_from_map(LocalNames(),i_sName, ITEM_ID(0));
154*cdf0e10cSrcweir }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir template<class ITEM_ID>
157*cdf0e10cSrcweir inline void
158*cdf0e10cSrcweir NameTreeNode<ITEM_ID>::Get_Names( Dyn_StdConstIterator<ITEM_ID> & o_rResult ) const
159*cdf0e10cSrcweir {
160*cdf0e10cSrcweir     o_rResult = new SCI_DataInMap<String,item_id>(LocalNames());
161*cdf0e10cSrcweir }
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir // HACK because of SunPro 5.2 compiler bug with templates:
165*cdf0e10cSrcweir //   ary::idl::Module has to be "FIND_NODE::node_type"
166*cdf0e10cSrcweir //   must be solved later somehow.
167*cdf0e10cSrcweir template <class FIND_NODE>
168*cdf0e10cSrcweir typename FIND_NODE::id_type
169*cdf0e10cSrcweir Search_SubTree( const ary::idl::Module &    i_rStart,
170*cdf0e10cSrcweir                 const FIND_NODE &           i_rNodeFinder )
171*cdf0e10cSrcweir {
172*cdf0e10cSrcweir     const ary::idl::Module *
173*cdf0e10cSrcweir         ret = &i_rStart;
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir     for ( StringVector::const_iterator  it = i_rNodeFinder.Begin();
176*cdf0e10cSrcweir           it != i_rNodeFinder.End() AND ret != 0;
177*cdf0e10cSrcweir           ++it )
178*cdf0e10cSrcweir     {
179*cdf0e10cSrcweir         ret = i_rNodeFinder(ret->Search_Name(*it));
180*cdf0e10cSrcweir     }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir     typename FIND_NODE::id_type nret(0);
183*cdf0e10cSrcweir     return ret != 0
184*cdf0e10cSrcweir             ?   ret->Search_Name(i_rNodeFinder.Name2Search())
185*cdf0e10cSrcweir             :   nret;
186*cdf0e10cSrcweir }
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir template <class  FIND_NODE>
189*cdf0e10cSrcweir typename FIND_NODE::id_type
190*cdf0e10cSrcweir Search_SubTree_UpTillRoot( const ary::idl::Module &    i_rStart,
191*cdf0e10cSrcweir                            const FIND_NODE &           i_rNodeFinder )
192*cdf0e10cSrcweir {
193*cdf0e10cSrcweir     typename FIND_NODE::id_type
194*cdf0e10cSrcweir         ret(0);
195*cdf0e10cSrcweir     for ( const ary::idl::Module * start = &i_rStart;
196*cdf0e10cSrcweir           start != 0 AND NOT ret.IsValid();
197*cdf0e10cSrcweir           start = i_rNodeFinder(start->Owner()) )
198*cdf0e10cSrcweir     {
199*cdf0e10cSrcweir         ret = Search_SubTree( *start,
200*cdf0e10cSrcweir                               i_rNodeFinder );
201*cdf0e10cSrcweir     }
202*cdf0e10cSrcweir     return ret;
203*cdf0e10cSrcweir }
204*cdf0e10cSrcweir // END Hack for SunPro 5.2 compiler bug.
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir }   // namespace ary
210*cdf0e10cSrcweir #endif
211