fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / autodoc / source / display / toolkit / out_node.cxx
blob0d8b561cd085e10b1e4a14d616560706f7a5efdb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <precomp.h>
21 #include <toolkit/out_node.hxx>
24 // NOT FULLY DEFINED SERVICES
25 #include <algorithm>
28 namespace output
32 namespace
35 struct Less_NodePtr
37 bool operator()(
38 Node * p1,
39 Node * p2 ) const
40 { return p1->Name() < p2->Name(); }
43 struct Less_NodePtr C_Less_NodePtr;
46 Node C_aNullNode(Node::null_object);
49 } // namepace anonymous
52 //********************** Node ***************************//
55 Node::Node()
56 : sName(),
57 pParent(0),
58 aChildren(),
59 nDepth(0),
60 nNameRoomId(0)
64 Node::Node( E_NullObject )
65 : sName(),
66 pParent(0),
67 aChildren(),
68 nDepth(-1),
69 nNameRoomId(0)
73 Node::Node(
74 const String & i_name,
75 Node & i_parent
76 ) :
77 sName(i_name),
78 pParent(&i_parent),
79 aChildren(),
80 nDepth(i_parent.Depth()+1),
81 nNameRoomId(0)
85 Node::~Node()
87 for ( NodeList::iterator it = aChildren.begin();
88 it != aChildren.end();
89 ++it )
91 delete *it;
95 Node& Node::Provide_Child( const String & i_name )
97 Node* ret = find_Child(i_name);
98 if (ret != 0)
99 return *ret;
100 return add_Child(i_name);
103 void Node::Get_Path(
104 StreamStr& o_result,
105 intt i_maxDepth
106 ) const
108 // Intentionally 'i_maxDepth != 0', so max_Depth == -1 sets no limit:
109 if (i_maxDepth != 0)
111 if (pParent != 0)
112 pParent->Get_Path(o_result, i_maxDepth-1);
113 o_result << sName << '/';
117 void Node::Get_Chain(
118 StringVector & o_result,
119 intt i_maxDepth
120 ) const
122 if (i_maxDepth != 0)
124 // This is called also for the toplevel Node,
125 // but there happens nothing:
126 if (pParent != 0)
128 pParent->Get_Chain(o_result, i_maxDepth-1);
129 o_result.push_back(sName);
134 Node* Node::find_Child( const String & i_name )
136 Node aSearch;
137 aSearch.sName = i_name;
139 NodeList::const_iterator
140 ret = std::lower_bound( aChildren.begin(),
141 aChildren.end(),
142 &aSearch,
143 C_Less_NodePtr );
144 if ( ret != aChildren.end() ? (*ret)->Name() == i_name : false )
145 return *ret;
147 return 0;
150 Node& Node::add_Child( const String & i_name )
152 DYN Node* pNew = new Node(i_name,*this);
153 aChildren.insert( std::lower_bound( aChildren.begin(),
154 aChildren.end(),
155 pNew,
156 C_Less_NodePtr ),
157 pNew );
158 return *pNew;
161 Node& Node::provide_Child(
162 StringVector::const_iterator i_next,
163 StringVector::const_iterator i_end
166 if (i_next == i_end)
167 return *this;
168 return Provide_Child(*i_next).provide_Child(i_next+1,i_end);
174 Node& Node::Null_()
176 return C_aNullNode;
180 } // namespace output
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */