merge the formfield patch from ooo-build
[ooovba.git] / autodoc / source / ary / inc / nametreenode.hxx
blobcef4af711f5ce36c5cbec52092353585dff0d380
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: nametreenode.hxx,v $
10 * $Revision: 1.7 $
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.
36 // USED SERVICES
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>
45 namespace ary
49 /** Implementation of a node in a namespace-tree.
51 template<class ITEM_ID>
52 class NameTreeNode
54 public:
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;
60 // LIFECYCLE
61 NameTreeNode();
62 NameTreeNode(
63 const String & i_sName,
64 const self & i_rParent,
65 ITEM_ID i_nParentId );
66 virtual ~NameTreeNode();
68 // OPERATIONS
69 void Add_Name(
70 const String & i_sName,
71 item_id i_nId );
72 // INQUIRY
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(); }
77 bool IsEquivalent(
78 const NameTreeNode &
79 i_rNode ) const;
80 name_iterator NameChain_Begin() const { return aCompleteNameChain.begin(); }
81 name_iterator NameChain_End() const { return aCompleteNameChain.end(); }
83 item_id Search_Name(
84 const String & i_sName ) const;
85 void Get_Names(
86 Dyn_StdConstIterator<ITEM_ID> &
87 o_rResult ) const;
88 const Map_LocalNames &
89 LocalNames() const { return aLocalNames; }
90 private:
91 // Locals
92 Map_LocalNames & LocalNames() { return aLocalNames; }
94 // DATA
95 Map_LocalNames aLocalNames;
96 StringVector aCompleteNameChain;
97 item_id nParent;
103 // IMPLEMENTATION
104 template<class ITEM_ID>
105 NameTreeNode<ITEM_ID>::NameTreeNode()
106 : aLocalNames(),
107 aCompleteNameChain(),
108 nParent(0)
112 template<class ITEM_ID>
113 NameTreeNode<ITEM_ID>::NameTreeNode( const String & i_sName,
114 const self & i_rParent,
115 ITEM_ID i_nParentId )
116 : aLocalNames(),
117 aCompleteNameChain(),
118 nParent(i_nParentId)
120 aCompleteNameChain.reserve(i_rParent.Depth()+1);
121 for ( name_iterator it = i_rParent.NameChain_Begin();
122 it != i_rParent.NameChain_End();
123 ++it )
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>
137 inline void
138 NameTreeNode<ITEM_ID>::Add_Name( const String & i_sName,
139 item_id i_nId )
141 LocalNames().insert( typename Map_LocalNames::value_type(i_sName, i_nId) );
145 template<class ITEM_ID>
146 inline bool
147 NameTreeNode<ITEM_ID>::IsEquivalent( const NameTreeNode & i_rNode ) const
149 return aCompleteNameChain == i_rNode.aCompleteNameChain;
152 template<class ITEM_ID>
153 inline 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>
160 inline void
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 *
176 ret = &i_rStart;
178 for ( StringVector::const_iterator it = i_rNodeFinder.Begin();
179 it != i_rNodeFinder.End() AND ret != 0;
180 ++it )
182 ret = i_rNodeFinder(ret->Search_Name(*it));
185 typename FIND_NODE::id_type nret(0);
186 return ret != 0
187 ? ret->Search_Name(i_rNodeFinder.Name2Search())
188 : nret;
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
197 ret(0);
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,
203 i_rNodeFinder );
205 return ret;
207 // END Hack for SunPro 5.2 compiler bug.
212 } // namespace ary
213 #endif