fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / autodoc / source / display / toolkit / out_position.cxx
blob5d222bfd8be5c8dbf8912eb8fb8606c6903844c9
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_position.hxx>
24 // NOT FULLY DEFINED SERVICES
28 namespace output
33 namespace
36 const int C_nAssumedMaxLinkLength = 500;
38 void move_ToParent(
39 Node * & io_node,
40 intt i_levels = 1 );
42 void
43 move_ToParent( Node * & io_node,
44 intt i_levels )
46 for ( intt n = 0; n < i_levels; ++n )
48 csv_assert(io_node != 0);
49 io_node = io_node->Parent();
55 } // namepace anonymous
59 Position::Position()
60 : sFile(),
61 pDirectory(&Node::Null_())
66 Position::Position( Node & i_directory,
67 const String & i_file )
68 : sFile(i_file),
69 pDirectory(&i_directory)
73 Position::Position( const Position & i_directory,
74 const String & i_sDifferentFile )
75 : sFile(i_sDifferentFile),
76 pDirectory(i_directory.pDirectory)
81 Position::~Position()
86 Position &
87 Position::operator=( Node & i_node )
89 pDirectory = &i_node;
90 sFile.clear();
91 return *this;
94 Position &
95 Position::operator+=( const String & i_nodeName )
97 csv_assert(pDirectory != 0);
99 pDirectory = &pDirectory->Provide_Child(i_nodeName);
100 sFile.clear();
102 return *this;
105 Position &
106 Position::operator-=( intt i_levels )
108 csv_assert(pDirectory != 0);
110 for ( intt i = i_levels; i > 0; --i )
112 pDirectory = pDirectory->Parent();
113 if (pDirectory == 0)
115 pDirectory = &Node::Null_();
116 i = 0;
119 sFile.clear();
121 return *this;
124 String
125 Position::LinkToRoot() const
127 StreamLock sl(C_nAssumedMaxLinkLength);
128 return sl() << get_UpLink(Depth()) << c_str;
131 void
132 Position::Get_LinkTo( StreamStr & o_result,
133 const Position & i_destination,
134 const String & i_localLabel ) const
136 Node * p1 = pDirectory;
137 Node * p2 = i_destination.pDirectory;
139 intt diff = Depth() - i_destination.Depth();
140 intt pathLength1 = 0;
141 intt pathLength2 = 0;
143 if ( diff > 0 )
145 pathLength1 = diff;
146 move_ToParent(p1,pathLength1);
148 else if ( diff < 0 )
150 pathLength2 = -diff;
151 move_ToParent(p2,pathLength2);
154 while ( p1 != p2 )
156 move_ToParent(p1);
157 move_ToParent(p2);
158 ++pathLength1;
159 ++pathLength2;
162 o_result << get_UpLink(pathLength1);
163 i_destination.pDirectory->Get_Path(o_result, pathLength2);
164 o_result << i_destination.sFile;
165 if (i_localLabel.length())
166 o_result << "#" << i_localLabel;
169 void
170 Position::Get_LinkToRoot( StreamStr & o_result ) const
172 o_result << get_UpLink(Depth());
175 void
176 Position::Set( Node & i_node,
177 const String & i_file )
179 sFile = i_file;
180 pDirectory = &i_node;
186 const char *
187 get_UpLink(uintt i_depth)
189 static const uintt
190 C_nMaxDepth = 30;
191 static const char
192 C_sUpLinkArray[3*C_nMaxDepth+1] =
193 "../../../../../../../../../../"
194 "../../../../../../../../../../"
195 "../../../../../../../../../../";
196 static const char *
197 C_sUpLink = &C_sUpLinkArray[0];
199 if ( i_depth <= C_nMaxDepth )
201 return C_sUpLink + 3*(C_nMaxDepth - i_depth);
203 else
204 { // not THREAD fast
205 static std::vector<char>
206 aRet;
207 uintt nNeededSize = i_depth * 3 + 1;
209 if (aRet.size() < nNeededSize)
211 aRet.resize(nNeededSize);
212 char * pEnd = &aRet[nNeededSize-1];
213 *pEnd = '\0';
215 for ( char * pFill = &(*aRet.begin());
216 pFill != pEnd;
217 pFill += 3 )
219 memcpy(pFill, C_sUpLink, 3);
221 } // end if
223 return &aRet[aRet.size() - 1 - 3*i_depth];
230 } // namespace output
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */