update dev300-m58
[ooovba.git] / autodoc / source / display / toolkit / out_node.cxx
blob737e2ef79564f1a2631bb3d2177c5e483d8cc159
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: out_node.cxx,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 #include <precomp.h>
32 #include <toolkit/out_node.hxx>
35 // NOT FULLY DEFINED SERVICES
36 #include <algorithm>
39 namespace output
43 namespace
46 struct Less_NodePtr
48 bool operator()(
49 Node * p1,
50 Node * p2 ) const
51 { return p1->Name() < p2->Name(); }
54 struct Less_NodePtr C_Less_NodePtr;
57 Node C_aNullNode(Node::null_object);
60 } // namepace anonymous
63 //********************** Node ***************************//
66 Node::Node()
67 : sName(),
68 pParent(0),
69 aChildren(),
70 nDepth(0),
71 nNameRoomId(0)
75 Node::Node( E_NullObject )
76 : sName(),
77 pParent(0),
78 aChildren(),
79 nDepth(-1),
80 nNameRoomId(0)
84 Node::Node( const String & i_name,
85 Node & i_parent )
86 : sName(i_name),
87 pParent(&i_parent),
88 aChildren(),
89 nDepth(i_parent.Depth()+1),
90 nNameRoomId(0)
94 Node::~Node()
96 for ( List::iterator it = aChildren.begin();
97 it != aChildren.end();
98 ++it )
100 delete *it;
104 Node &
105 Node::Provide_Child( const String & i_name )
107 Node *
108 ret = find_Child(i_name);
109 if (ret != 0)
110 return *ret;
111 return add_Child(i_name);
114 void
115 Node::Get_Path( StreamStr & o_result,
116 intt i_maxDepth ) const
118 // Intentionally 'i_maxDepth != 0', so max_Depth == -1 sets no limit:
119 if (i_maxDepth != 0)
121 if (pParent != 0)
122 pParent->Get_Path(o_result, i_maxDepth-1);
123 o_result << sName << '/';
127 void
128 Node::Get_Chain( StringVector & o_result,
129 intt i_maxDepth ) const
131 if (i_maxDepth != 0)
133 // This is called also for the toplevel Node,
134 // but there happens nothing:
135 if (pParent != 0)
137 pParent->Get_Chain(o_result, i_maxDepth-1);
138 o_result.push_back(sName);
143 Node *
144 Node::find_Child( const String & i_name )
146 Node aSearch;
147 aSearch.sName = i_name;
149 List::const_iterator
150 ret = std::lower_bound( aChildren.begin(),
151 aChildren.end(),
152 &aSearch,
153 C_Less_NodePtr );
154 if ( ret != aChildren.end() ? (*ret)->Name() == i_name : false )
155 return *ret;
157 return 0;
160 Node &
161 Node::add_Child( const String & i_name )
163 DYN Node *
164 pNew = new Node(i_name,*this);
165 aChildren.insert( std::lower_bound( aChildren.begin(),
166 aChildren.end(),
167 pNew,
168 C_Less_NodePtr ),
169 pNew );
170 return *pNew;
173 Node &
174 Node::provide_Child( StringVector::const_iterator i_next,
175 StringVector::const_iterator i_end )
177 if (i_next == i_end)
178 return *this;
179 return Provide_Child(*i_next).provide_Child(i_next+1,i_end);
185 Node &
186 Node::Null_()
188 return C_aNullNode;
192 } // namespace output