/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
/** When the USE_OPTIMIZATIONS symbol is defined then at some optimizations are activated that work only together with XResourceId objects that are implemented by the ResourceId class. For other implementations of when the USE_OPTIMIZATIONS symbol is not defined then alternative code is used instead.
*/ #define USE_OPTIMIZATIONS
ResourceId::ResourceId ( const OUString& rsResourceURL)
: maResourceURLs(1, rsResourceURL)
{ // Handle the special case of an empty resource URL. if (rsResourceURL.isEmpty())
maResourceURLs.clear();
ParseResourceURL();
}
OUString SAL_CALL
ResourceId::getResourceTypePrefix()
{ if (!maResourceURLs.empty() )
{ // Return the "private:resource/<type>/" prefix.
// Get the prefix that ends with the second "/". const OUString& rsResourceURL (maResourceURLs[0]);
sal_Int32 nPrefixEnd (rsResourceURL.indexOf('/')); if (nPrefixEnd >= 0)
nPrefixEnd = rsResourceURL.indexOf('/', nPrefixEnd+1) + 1; else
nPrefixEnd = 0;
if ( ! rxResourceId.is())
{ // The empty reference is interpreted as empty resource id object. if (!maResourceURLs.empty())
nResult = +1; else
nResult = 0;
} else
{
ResourceId* pId = nullptr; #ifdef USE_OPTIMIZATIONS
pId = dynamic_cast<ResourceId*>(rxResourceId.get()); #endif if (pId != nullptr)
{ // We have direct access to the implementation of the given // resource id object.
nResult = CompareToLocalImplementation(*pId);
} else
{ // We have to do the comparison via the UNO interface of the // given resource id object.
nResult = CompareToExternalImplementation(rxResourceId);
}
}
// Start comparison with the top most anchors. for (sal_Int32 nIndex=nURLCount-1,nLocalIndex=nLocalURLCount-1;
nIndex>=0 && nLocalIndex>=0;
--nIndex,--nLocalIndex)
{ const OUString sLocalURL (maResourceURLs[nLocalIndex]); const OUString sURL (rId.maResourceURLs[nIndex]); const sal_Int32 nLocalResult (sURL.compareTo(sLocalURL)); if (nLocalResult != 0)
{ if (nLocalResult < 0)
nResult = -1; else
nResult = +1; break;
}
}
if (nResult == 0)
{ // No difference found yet. When the lengths are the same then the // two resource ids are equivalent. Otherwise the shorter comes // first. if (nLocalURLCount != nURLCount)
{ if (nLocalURLCount < nURLCount)
nResult = -1; else
nResult = +1;
}
}
// Start comparison with the top most anchors.
sal_Int32 nLocalResult (0); for (sal_Int32 nIndex=nURLCount-1,nLocalIndex=nLocalURLCount-1;
nIndex>=0&&nLocalIndex>=0;
--nIndex,--nLocalIndex)
{ if (nIndex == 0 )
nLocalResult = maResourceURLs[nIndex].compareTo(rxId->getResourceURL()); else
nLocalResult = maResourceURLs[nIndex].compareTo(aAnchorURLs[nIndex-1]); if (nLocalResult != 0)
{ if (nLocalResult < 0)
nResult = -1; else
nResult = +1; break;
}
}
if (nResult == 0)
{ // No difference found yet. When the lengths are the same then the // two resource ids are equivalent. Otherwise the shorter comes // first. if (nLocalURLCount != nURLCount)
{ if (nLocalURLCount < nURLCount)
nResult = -1; else
nResult = +1;
}
}
return nResult;
}
sal_Bool SAL_CALL
ResourceId::isBoundTo ( const Reference<XResourceId>& rxResourceId,
AnchorBindingMode eMode)
{ if ( ! rxResourceId.is())
{ // An empty reference is interpreted as empty resource id. return IsBoundToAnchor(nullptr, nullptr, eMode);
}
/** When eMode is DIRECTLY then the anchor of the called object and the anchor represented by the given sequence of anchor URLs have to be identical. When eMode is RECURSIVE then the anchor of the called object has to start with the given anchor URLs.
*/ bool ResourceId::IsBoundToAnchor ( const OUString* psFirstAnchorURL, const Sequence<OUString>* paAnchorURLs,
AnchorBindingMode eMode) const
{ const sal_uInt32 nLocalAnchorURLCount (maResourceURLs.size() - 1); constbool bHasFirstAnchorURL (psFirstAnchorURL!=nullptr); const sal_uInt32 nAnchorURLCount ((bHasFirstAnchorURL?1:0)
+ (paAnchorURLs!=nullptr ? paAnchorURLs->getLength() : 0));
// Check the lengths. if (nLocalAnchorURLCount<nAnchorURLCount ||
(eMode==AnchorBindingMode_DIRECT && nLocalAnchorURLCount!=nAnchorURLCount))
{ returnfalse;
}
// Compare the nAnchorURLCount bottom-most anchor URLs of this resource // id and the given anchor.
sal_uInt32 nOffset = 0; if (paAnchorURLs != nullptr)
{
sal_uInt32 nCount = paAnchorURLs->getLength(); while (nOffset < nCount)
{ if ( maResourceURLs[nLocalAnchorURLCount - nOffset] !=
(*paAnchorURLs)[nCount - 1 - nOffset] )
{ returnfalse;
}
++nOffset;
}
} if (bHasFirstAnchorURL)
{ if ( *psFirstAnchorURL != maResourceURLs[nLocalAnchorURLCount - nOffset] ) returnfalse;
}
// Check the lengths. if (nLocalAnchorURLCount<nAnchorURLCount ||
(eMode==AnchorBindingMode_DIRECT && nLocalAnchorURLCount!=nAnchorURLCount))
{ returnfalse;
}
// Compare the nAnchorURLCount bottom-most anchor URLs of this resource // id and the given anchor. for (sal_uInt32 nOffset=0; nOffset<nAnchorURLCount; ++nOffset)
{ if ( maResourceURLs[nLocalAnchorURLCount - nOffset] !=
rAnchorURLs[nAnchorURLCount - 1 - nOffset] )
{ returnfalse;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.