xref: /AOO41X/main/autodoc/source/ary/inc/nametreenode.hxx (revision 1c78a5d6c0093dece4c096ba53051800fbad6e33)
1*1c78a5d6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*1c78a5d6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*1c78a5d6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*1c78a5d6SAndrew Rist  * distributed with this work for additional information
6*1c78a5d6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*1c78a5d6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*1c78a5d6SAndrew Rist  * "License"); you may not use this file except in compliance
9*1c78a5d6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*1c78a5d6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*1c78a5d6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*1c78a5d6SAndrew Rist  * software distributed under the License is distributed on an
15*1c78a5d6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*1c78a5d6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*1c78a5d6SAndrew Rist  * specific language governing permissions and limitations
18*1c78a5d6SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*1c78a5d6SAndrew Rist  *************************************************************/
21*1c78a5d6SAndrew Rist 
22*1c78a5d6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef ARY_NAMETREENODE_HXX
25cdf0e10cSrcweir #define ARY_NAMETREENODE_HXX
26cdf0e10cSrcweir //  KORR_DEPRECATED_3.0
27cdf0e10cSrcweir //      Replace by ::ary::symtree::Node.
28cdf0e10cSrcweir 
29cdf0e10cSrcweir // USED SERVICES
30cdf0e10cSrcweir #include <cosv/tpl/tpltools.hxx>
31cdf0e10cSrcweir #include <sci_impl.hxx>
32cdf0e10cSrcweir // HACK because of SunPro 5.2 compiler bug with templates:
33cdf0e10cSrcweir #include <ary/idl/i_module.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace ary
39cdf0e10cSrcweir {
40cdf0e10cSrcweir 
41cdf0e10cSrcweir 
42cdf0e10cSrcweir /** Implementation of a node in a namespace-tree.
43cdf0e10cSrcweir */
44cdf0e10cSrcweir template<class ITEM_ID>
45cdf0e10cSrcweir class NameTreeNode
46cdf0e10cSrcweir {
47cdf0e10cSrcweir   public:
48cdf0e10cSrcweir     typedef NameTreeNode                    self;
49cdf0e10cSrcweir     typedef ITEM_ID                         item_id;
50cdf0e10cSrcweir     typedef StringVector::const_iterator    name_iterator;
51cdf0e10cSrcweir     typedef std::map<String, item_id>       Map_LocalNames;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir     // LIFECYCLE
54cdf0e10cSrcweir                         NameTreeNode();
55cdf0e10cSrcweir                         NameTreeNode(
56cdf0e10cSrcweir                             const String &      i_sName,
57cdf0e10cSrcweir                             const self &        i_rParent,
58cdf0e10cSrcweir                             ITEM_ID             i_nParentId );
59cdf0e10cSrcweir     virtual             ~NameTreeNode();
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     // OPERATIONS
62cdf0e10cSrcweir     void                Add_Name(
63cdf0e10cSrcweir                             const String &      i_sName,
64cdf0e10cSrcweir                             item_id             i_nId );
65cdf0e10cSrcweir     // INQUIRY
Name() const66cdf0e10cSrcweir     const String &      Name() const            { return Depth() > 0 ? aCompleteNameChain.back() : String::Null_(); }
Parent() const67cdf0e10cSrcweir     item_id             Parent() const          { return nParent; }
Depth() const68cdf0e10cSrcweir     intt                Depth() const           { return aCompleteNameChain.size(); }
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     bool                IsEquivalent(
71cdf0e10cSrcweir                             const NameTreeNode &
72cdf0e10cSrcweir                                                 i_rNode ) const;
NameChain_Begin() const73cdf0e10cSrcweir     name_iterator       NameChain_Begin() const { return aCompleteNameChain.begin(); }
NameChain_End() const74cdf0e10cSrcweir     name_iterator       NameChain_End() const   { return aCompleteNameChain.end(); }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     item_id             Search_Name(
77cdf0e10cSrcweir                             const String &      i_sName ) const;
78cdf0e10cSrcweir     void                Get_Names(
79cdf0e10cSrcweir                             Dyn_StdConstIterator<ITEM_ID> &
80cdf0e10cSrcweir                                                 o_rResult ) const;
81cdf0e10cSrcweir     const Map_LocalNames &
LocalNames() const82cdf0e10cSrcweir                         LocalNames() const      { return aLocalNames; }
83cdf0e10cSrcweir   private:
84cdf0e10cSrcweir     // Locals
LocalNames()85cdf0e10cSrcweir     Map_LocalNames &    LocalNames()            { return aLocalNames; }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     // DATA
88cdf0e10cSrcweir     Map_LocalNames      aLocalNames;
89cdf0e10cSrcweir     StringVector        aCompleteNameChain;
90cdf0e10cSrcweir     item_id             nParent;
91cdf0e10cSrcweir };
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 
96cdf0e10cSrcweir // IMPLEMENTATION
97cdf0e10cSrcweir template<class ITEM_ID>
NameTreeNode()98cdf0e10cSrcweir NameTreeNode<ITEM_ID>::NameTreeNode()
99cdf0e10cSrcweir     :   aLocalNames(),
100cdf0e10cSrcweir         aCompleteNameChain(),
101cdf0e10cSrcweir         nParent(0)
102cdf0e10cSrcweir {
103cdf0e10cSrcweir }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir template<class ITEM_ID>
NameTreeNode(const String & i_sName,const self & i_rParent,ITEM_ID i_nParentId)106cdf0e10cSrcweir NameTreeNode<ITEM_ID>::NameTreeNode( const String &      i_sName,
107cdf0e10cSrcweir                                      const self &        i_rParent,
108cdf0e10cSrcweir                                      ITEM_ID             i_nParentId )
109cdf0e10cSrcweir     :   aLocalNames(),
110cdf0e10cSrcweir         aCompleteNameChain(),
111cdf0e10cSrcweir         nParent(i_nParentId)
112cdf0e10cSrcweir {
113cdf0e10cSrcweir     aCompleteNameChain.reserve(i_rParent.Depth()+1);
114cdf0e10cSrcweir     for ( name_iterator it = i_rParent.NameChain_Begin();
115cdf0e10cSrcweir           it != i_rParent.NameChain_End();
116cdf0e10cSrcweir           ++it )
117cdf0e10cSrcweir     {
118cdf0e10cSrcweir         aCompleteNameChain.push_back(*it);
119cdf0e10cSrcweir     }
120cdf0e10cSrcweir     aCompleteNameChain.push_back(i_sName);
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir template<class ITEM_ID>
~NameTreeNode()124cdf0e10cSrcweir NameTreeNode<ITEM_ID>::~NameTreeNode()
125cdf0e10cSrcweir {
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 
129cdf0e10cSrcweir template<class ITEM_ID>
130cdf0e10cSrcweir inline void
Add_Name(const String & i_sName,item_id i_nId)131cdf0e10cSrcweir NameTreeNode<ITEM_ID>::Add_Name( const String &      i_sName,
132cdf0e10cSrcweir                                  item_id             i_nId )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir     LocalNames().insert( typename Map_LocalNames::value_type(i_sName, i_nId) );
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 
138cdf0e10cSrcweir template<class ITEM_ID>
139cdf0e10cSrcweir inline bool
IsEquivalent(const NameTreeNode & i_rNode) const140cdf0e10cSrcweir NameTreeNode<ITEM_ID>::IsEquivalent( const NameTreeNode & i_rNode ) const
141cdf0e10cSrcweir {
142cdf0e10cSrcweir     return aCompleteNameChain == i_rNode.aCompleteNameChain;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir template<class ITEM_ID>
146cdf0e10cSrcweir inline ITEM_ID
Search_Name(const String & i_sName) const147cdf0e10cSrcweir NameTreeNode<ITEM_ID>::Search_Name( const String & i_sName ) const
148cdf0e10cSrcweir {
149cdf0e10cSrcweir     return csv::value_from_map(LocalNames(),i_sName, ITEM_ID(0));
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir template<class ITEM_ID>
153cdf0e10cSrcweir inline void
Get_Names(Dyn_StdConstIterator<ITEM_ID> & o_rResult) const154cdf0e10cSrcweir NameTreeNode<ITEM_ID>::Get_Names( Dyn_StdConstIterator<ITEM_ID> & o_rResult ) const
155cdf0e10cSrcweir {
156cdf0e10cSrcweir     o_rResult = new SCI_DataInMap<String,item_id>(LocalNames());
157cdf0e10cSrcweir }
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 
160cdf0e10cSrcweir // HACK because of SunPro 5.2 compiler bug with templates:
161cdf0e10cSrcweir //   ary::idl::Module has to be "FIND_NODE::node_type"
162cdf0e10cSrcweir //   must be solved later somehow.
163cdf0e10cSrcweir template <class FIND_NODE>
164cdf0e10cSrcweir typename FIND_NODE::id_type
Search_SubTree(const ary::idl::Module & i_rStart,const FIND_NODE & i_rNodeFinder)165cdf0e10cSrcweir Search_SubTree( const ary::idl::Module &    i_rStart,
166cdf0e10cSrcweir                 const FIND_NODE &           i_rNodeFinder )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir     const ary::idl::Module *
169cdf0e10cSrcweir         ret = &i_rStart;
170cdf0e10cSrcweir 
171cdf0e10cSrcweir     for ( StringVector::const_iterator  it = i_rNodeFinder.Begin();
172cdf0e10cSrcweir           it != i_rNodeFinder.End() AND ret != 0;
173cdf0e10cSrcweir           ++it )
174cdf0e10cSrcweir     {
175cdf0e10cSrcweir         ret = i_rNodeFinder(ret->Search_Name(*it));
176cdf0e10cSrcweir     }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     typename FIND_NODE::id_type nret(0);
179cdf0e10cSrcweir     return ret != 0
180cdf0e10cSrcweir             ?   ret->Search_Name(i_rNodeFinder.Name2Search())
181cdf0e10cSrcweir             :   nret;
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir template <class  FIND_NODE>
185cdf0e10cSrcweir typename FIND_NODE::id_type
Search_SubTree_UpTillRoot(const ary::idl::Module & i_rStart,const FIND_NODE & i_rNodeFinder)186cdf0e10cSrcweir Search_SubTree_UpTillRoot( const ary::idl::Module &    i_rStart,
187cdf0e10cSrcweir                            const FIND_NODE &           i_rNodeFinder )
188cdf0e10cSrcweir {
189cdf0e10cSrcweir     typename FIND_NODE::id_type
190cdf0e10cSrcweir         ret(0);
191cdf0e10cSrcweir     for ( const ary::idl::Module * start = &i_rStart;
192cdf0e10cSrcweir           start != 0 AND NOT ret.IsValid();
193cdf0e10cSrcweir           start = i_rNodeFinder(start->Owner()) )
194cdf0e10cSrcweir     {
195cdf0e10cSrcweir         ret = Search_SubTree( *start,
196cdf0e10cSrcweir                               i_rNodeFinder );
197cdf0e10cSrcweir     }
198cdf0e10cSrcweir     return ret;
199cdf0e10cSrcweir }
200cdf0e10cSrcweir // END Hack for SunPro 5.2 compiler bug.
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 
205cdf0e10cSrcweir }   // namespace ary
206cdf0e10cSrcweir #endif
207