1*0841af79SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*0841af79SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*0841af79SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*0841af79SAndrew Rist * distributed with this work for additional information
6*0841af79SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*0841af79SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*0841af79SAndrew Rist * "License"); you may not use this file except in compliance
9*0841af79SAndrew Rist * with the License. You may obtain a copy of the License at
10*0841af79SAndrew Rist *
11*0841af79SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*0841af79SAndrew Rist *
13*0841af79SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*0841af79SAndrew Rist * software distributed under the License is distributed on an
15*0841af79SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*0841af79SAndrew Rist * KIND, either express or implied. See the License for the
17*0841af79SAndrew Rist * specific language governing permissions and limitations
18*0841af79SAndrew Rist * under the License.
19*0841af79SAndrew Rist *
20*0841af79SAndrew Rist *************************************************************/
21cdf0e10cSrcweir
22cdf0e10cSrcweir #include <precomp.h>
23cdf0e10cSrcweir #include <toolkit/out_node.hxx>
24cdf0e10cSrcweir
25cdf0e10cSrcweir
26cdf0e10cSrcweir // NOT FULLY DEFINED SERVICES
27cdf0e10cSrcweir #include <algorithm>
28cdf0e10cSrcweir
29cdf0e10cSrcweir
30cdf0e10cSrcweir namespace output
31cdf0e10cSrcweir {
32cdf0e10cSrcweir
33cdf0e10cSrcweir
34cdf0e10cSrcweir namespace
35cdf0e10cSrcweir {
36cdf0e10cSrcweir
37cdf0e10cSrcweir struct Less_NodePtr
38cdf0e10cSrcweir {
operator ()output::__anon279e266d0111::Less_NodePtr39cdf0e10cSrcweir bool operator()(
40cdf0e10cSrcweir Node * p1,
41cdf0e10cSrcweir Node * p2 ) const
42cdf0e10cSrcweir { return p1->Name() < p2->Name(); }
43cdf0e10cSrcweir };
44cdf0e10cSrcweir
45cdf0e10cSrcweir struct Less_NodePtr C_Less_NodePtr;
46cdf0e10cSrcweir
47cdf0e10cSrcweir
48cdf0e10cSrcweir Node C_aNullNode(Node::null_object);
49cdf0e10cSrcweir
50cdf0e10cSrcweir
51cdf0e10cSrcweir } // namepace anonymous
52cdf0e10cSrcweir
53cdf0e10cSrcweir
54cdf0e10cSrcweir //********************** Node ***************************//
55cdf0e10cSrcweir
56cdf0e10cSrcweir
Node()57cdf0e10cSrcweir Node::Node()
58cdf0e10cSrcweir : sName(),
59cdf0e10cSrcweir pParent(0),
60cdf0e10cSrcweir aChildren(),
61cdf0e10cSrcweir nDepth(0),
62cdf0e10cSrcweir nNameRoomId(0)
63cdf0e10cSrcweir {
64cdf0e10cSrcweir }
65cdf0e10cSrcweir
Node(E_NullObject)66cdf0e10cSrcweir Node::Node( E_NullObject )
67cdf0e10cSrcweir : sName(),
68cdf0e10cSrcweir pParent(0),
69cdf0e10cSrcweir aChildren(),
70cdf0e10cSrcweir nDepth(-1),
71cdf0e10cSrcweir nNameRoomId(0)
72cdf0e10cSrcweir {
73cdf0e10cSrcweir }
74cdf0e10cSrcweir
Node(const String & i_name,Node & i_parent)75cdf0e10cSrcweir Node::Node( const String & i_name,
76cdf0e10cSrcweir Node & i_parent )
77cdf0e10cSrcweir : sName(i_name),
78cdf0e10cSrcweir pParent(&i_parent),
79cdf0e10cSrcweir aChildren(),
80cdf0e10cSrcweir nDepth(i_parent.Depth()+1),
81cdf0e10cSrcweir nNameRoomId(0)
82cdf0e10cSrcweir {
83cdf0e10cSrcweir }
84cdf0e10cSrcweir
~Node()85cdf0e10cSrcweir Node::~Node()
86cdf0e10cSrcweir {
87cdf0e10cSrcweir for ( List::iterator it = aChildren.begin();
88cdf0e10cSrcweir it != aChildren.end();
89cdf0e10cSrcweir ++it )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir delete *it;
92cdf0e10cSrcweir }
93cdf0e10cSrcweir }
94cdf0e10cSrcweir
95cdf0e10cSrcweir Node &
Provide_Child(const String & i_name)96cdf0e10cSrcweir Node::Provide_Child( const String & i_name )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir Node *
99cdf0e10cSrcweir ret = find_Child(i_name);
100cdf0e10cSrcweir if (ret != 0)
101cdf0e10cSrcweir return *ret;
102cdf0e10cSrcweir return add_Child(i_name);
103cdf0e10cSrcweir }
104cdf0e10cSrcweir
105cdf0e10cSrcweir void
Get_Path(StreamStr & o_result,intt i_maxDepth) const106cdf0e10cSrcweir Node::Get_Path( StreamStr & o_result,
107cdf0e10cSrcweir intt i_maxDepth ) const
108cdf0e10cSrcweir {
109cdf0e10cSrcweir // Intentionally 'i_maxDepth != 0', so max_Depth == -1 sets no limit:
110cdf0e10cSrcweir if (i_maxDepth != 0)
111cdf0e10cSrcweir {
112cdf0e10cSrcweir if (pParent != 0)
113cdf0e10cSrcweir pParent->Get_Path(o_result, i_maxDepth-1);
114cdf0e10cSrcweir o_result << sName << '/';
115cdf0e10cSrcweir }
116cdf0e10cSrcweir }
117cdf0e10cSrcweir
118cdf0e10cSrcweir void
Get_Chain(StringVector & o_result,intt i_maxDepth) const119cdf0e10cSrcweir Node::Get_Chain( StringVector & o_result,
120cdf0e10cSrcweir intt i_maxDepth ) const
121cdf0e10cSrcweir {
122cdf0e10cSrcweir if (i_maxDepth != 0)
123cdf0e10cSrcweir {
124cdf0e10cSrcweir // This is called also for the toplevel Node,
125cdf0e10cSrcweir // but there happens nothing:
126cdf0e10cSrcweir if (pParent != 0)
127cdf0e10cSrcweir {
128cdf0e10cSrcweir pParent->Get_Chain(o_result, i_maxDepth-1);
129cdf0e10cSrcweir o_result.push_back(sName);
130cdf0e10cSrcweir }
131cdf0e10cSrcweir }
132cdf0e10cSrcweir }
133cdf0e10cSrcweir
134cdf0e10cSrcweir Node *
find_Child(const String & i_name)135cdf0e10cSrcweir Node::find_Child( const String & i_name )
136cdf0e10cSrcweir {
137cdf0e10cSrcweir Node aSearch;
138cdf0e10cSrcweir aSearch.sName = i_name;
139cdf0e10cSrcweir
140cdf0e10cSrcweir List::const_iterator
141cdf0e10cSrcweir ret = std::lower_bound( aChildren.begin(),
142cdf0e10cSrcweir aChildren.end(),
143cdf0e10cSrcweir &aSearch,
144cdf0e10cSrcweir C_Less_NodePtr );
145cdf0e10cSrcweir if ( ret != aChildren.end() ? (*ret)->Name() == i_name : false )
146cdf0e10cSrcweir return *ret;
147cdf0e10cSrcweir
148cdf0e10cSrcweir return 0;
149cdf0e10cSrcweir }
150cdf0e10cSrcweir
151cdf0e10cSrcweir Node &
add_Child(const String & i_name)152cdf0e10cSrcweir Node::add_Child( const String & i_name )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir DYN Node *
155cdf0e10cSrcweir pNew = new Node(i_name,*this);
156cdf0e10cSrcweir aChildren.insert( std::lower_bound( aChildren.begin(),
157cdf0e10cSrcweir aChildren.end(),
158cdf0e10cSrcweir pNew,
159cdf0e10cSrcweir C_Less_NodePtr ),
160cdf0e10cSrcweir pNew );
161cdf0e10cSrcweir return *pNew;
162cdf0e10cSrcweir }
163cdf0e10cSrcweir
164cdf0e10cSrcweir Node &
provide_Child(StringVector::const_iterator i_next,StringVector::const_iterator i_end)165cdf0e10cSrcweir Node::provide_Child( StringVector::const_iterator i_next,
166cdf0e10cSrcweir StringVector::const_iterator i_end )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir if (i_next == i_end)
169cdf0e10cSrcweir return *this;
170cdf0e10cSrcweir return Provide_Child(*i_next).provide_Child(i_next+1,i_end);
171cdf0e10cSrcweir }
172cdf0e10cSrcweir
173cdf0e10cSrcweir
174cdf0e10cSrcweir
175cdf0e10cSrcweir
176cdf0e10cSrcweir Node &
Null_()177cdf0e10cSrcweir Node::Null_()
178cdf0e10cSrcweir {
179cdf0e10cSrcweir return C_aNullNode;
180cdf0e10cSrcweir }
181cdf0e10cSrcweir
182cdf0e10cSrcweir
183cdf0e10cSrcweir } // namespace output
184