/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column:100 -*- */ /* * 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 .
*/
namespace com::sun::star::uno { template <typename > class Sequence; }
class ScDocument;
/** size_t typedef to be able to find places where code was changed from USHORT
to size_t and is used to read/write from/to streams. */ typedef size_t SCSIZE;
// Maximum possible value of data type, NOT maximum row value. // MSC confuses numeric_limit max() with macro max() if vcl/wintypes.hxx is // included, we should not be using those stupid macros anyway. #undef min #undef max const SCROW SCROW_MAX = ::std::numeric_limits<SCROW>::max(); const SCCOL SCCOL_MAX = ::std::numeric_limits<SCCOL>::max(); const SCTAB SCTAB_MAX = ::std::numeric_limits<SCTAB>::max(); const SCCOLROW SCCOLROW_MAX = ::std::numeric_limits<SCCOLROW>::max(); const SCSIZE SCSIZE_MAX = ::std::numeric_limits<SCSIZE>::max();
// Count values const SCROW MAXROWCOUNT = 1048576; const SCCOL MAXCOLCOUNT = 16384; const SCCOL INITIALCOLCOUNT = 1; // initial number of columns we allocate memory for /// limiting to 10000 for now, problem with 32 bit builds for now const SCTAB MAXTABCOUNT = 10000; // Maximum values const SCROW MAXROW = MAXROWCOUNT - 1; const SCCOL MAXCOL = MAXCOLCOUNT - 1; const SCTAB MAXTAB = MAXTABCOUNT - 1; const SCCOLROW MAXCOLROW = MAXROW; const SCROW MAXROWCOUNT_JUMBO = 16 * 1024 * 1024; const SCCOL MAXCOLCOUNT_JUMBO = 16384; const SCROW MAXROW_JUMBO = MAXROWCOUNT_JUMBO - 1; const SCCOL MAXCOL_JUMBO = MAXCOLCOUNT_JUMBO - 1; // Maximum tiled rendering values const SCROW MAXTILEDROW = MAXROW; // Limit the initial tab count to prevent users to set the count too high, // which could cause the memory usage of blank documents to exceed the // available system memory. const SCTAB MAXINITTAB = 1024; const SCTAB MININITTAB = 1;
// The result of ConvertRef() is a bit group of the following: enumclass ScRefFlags : sal_uInt16
{
ZERO = 0x0000,
COL_ABS = 0x0001,
ROW_ABS = 0x0002,
TAB_ABS = 0x0004,
TAB_3D = 0x0008,
COL2_ABS = 0x0010,
ROW2_ABS = 0x0020,
TAB2_ABS = 0x0040,
TAB2_3D = 0x0080,
ROW_VALID = 0x0100,
COL_VALID = 0x0200,
TAB_VALID = 0x0400, // BITS for convenience
BITS = COL_ABS | ROW_ABS | TAB_ABS | TAB_3D
| ROW_VALID | COL_VALID | TAB_VALID, // somewhat cheesy kludge to force the display of the document name even for // local references. Requires TAB_3D to be valid
FORCE_DOC = 0x0800,
ROW2_VALID = 0x1000,
COL2_VALID = 0x2000,
TAB2_VALID = 0x4000,
VALID = 0x8000,
// ScAddress class SAL_WARN_UNUSED ScAddress
{ private: // Even if the fields are in the order "row, column, tab", in all (?) the ScAddress and // ScDocument APIs that take separate row, column, and tab parameters, the parameters are in the // order "column, row, tab", which matches the most common (A1) address syntax, if you ignore // the sheet (tab). Don't let this confuse you, like it confused me for a while.
/** @param pSheetEndPos If given and Parse() successfully parsed a sheet name it returns the end position (exclusive) behind the sheet name AND a following sheet name separator. This independent of whether the resulting reference is fully valid or not.
*/
SC_DLLPUBLIC ScRefFlags Parse( const OUString&, const ScDocument&, const Details& rDetails = detailsOOOa1,
ExternalInfo* pExtInfo = nullptr, const css::uno::Sequence<css::sheet::ExternalLinkInfo>* pExternalLinks = nullptr,
sal_Int32* pSheetEndPos = nullptr, const OUString* pErrRef = nullptr );
/** @param rErrorPos If FALSE is returned, the positions contain <0 or >MAX... values if shifted out of bounds. @param pDocument The document for the maximum defined sheet number.
*/
[[nodiscard]] SC_DLLPUBLIC bool Move( SCCOL nDeltaX, SCROW nDeltaY, SCTAB nDeltaZ,
ScAddress& rErrorPos, const ScDocument& rDoc );
/** * Create a human-readable string representation of the cell address. You * cannot specify precise formatting with this method; use Format() if you * need to specify how the address needs to be formatted. * * The address string does not display sheet name. * * @return human-readable string representation of the cell address.
*/
OUString GetColRowString() const;
};
// For use in SAL_DEBUG etc. Output format not guaranteed to be stable. template<typename charT, typename traits> inline std::basic_ostream<charT, traits> & operator <<(std::basic_ostream<charT, traits> & stream, const ScAddress& rAddress)
{
stream <<
rAddress.Tab()+1 << "!" "R" << rAddress.Row()+1 << "C" << rAddress.Col()+1;
/** Less than ordered by tab,row,col as needed by row-wise import/export */ inlinebool ScAddress::lessThanByRow( const ScAddress& rAddress ) const
{ if (nTab == rAddress.nTab)
{ if (nRow == rAddress.nRow) return nCol < rAddress.nCol; else return nRow < rAddress.nRow;
} else return nTab < rAddress.nTab;
}
inline size_t ScAddress::hash() const
{ #if SAL_TYPES_SIZEOFPOINTER == 8 // 16 bits for the columns, and 20 bits for the rows return (static_cast<size_t>(nTab) << 36) ^
(static_cast<size_t>(nCol) << 20) ^ static_cast<size_t>(nRow); #else // Assume that there are not that many addresses with row > 2^16 AND column // > 2^8 AND sheet > 2^8 so we won't have too many collisions. if (nRow <= 0xffff) return (static_cast<size_t>(nTab) << 24) ^
(static_cast<size_t>(nCol) << 16) ^ static_cast<size_t>(nRow); else return (static_cast<size_t>(nTab) << 28) ^
(static_cast<size_t>(nCol) << 24) ^ static_cast<size_t>(nRow); #endif
}
/** Parse an Excel style reference up to and including the sheet name separator '!', including detection of external documents and sheet names, and in case of MOOXML import the bracketed index is used to determine the actual document name passed in pExternalLinks. For internal references (resulting rExternDocName empty), aStart.nTab and aEnd.nTab are set, or -1 if sheet name not found. @param bOnlyAcceptSingle If <TRUE/>, a 3D reference (Sheet1:Sheet2) encountered results in an error (NULL returned). @param pExternalLinks pointer to ExternalLinkInfo sequence, may be NULL for non-filter usage, in which case indices such as [1] are not resolved. @param pErrRef pointer to "#REF!" string if to be accepted. @returns Pointer to the position after '!' if successfully parsed, and rExternDocName, rStartTabName and/or rEndTabName filled if applicable. ScRefFlags::... flags set in nFlags. Or if no valid document and/or sheet header could be parsed the start position passed with pString. Or NULL if a 3D sheet header could be parsed but bOnlyAcceptSingle==true was given.
*/ const sal_Unicode* Parse_XL_Header( const sal_Unicode* pString, const ScDocument& rDocument,
OUString& rExternDocName, OUString& rStartTabName,
OUString& rEndTabName, ScRefFlags& nFlags, bool bOnlyAcceptSingle, const css::uno::Sequence<css::sheet::ExternalLinkInfo>* pExternalLinks = nullptr, const OUString* pErrRef = nullptr );
/** Returns string with formatted cell range from aStart to aEnd, according to provided address convention. @param nFlags Cell reference flags @param rDocument Reference to document which is used for example to get tab names. @param rDetails Provide information about required address convention. Supported address conventions are: CONV_OOO 'doc'#sheet.A1:sheet2.B2 CONV_XL_A1, [doc]sheet:sheet2!A1:B2 CONV_XL_OOX, [#]sheet:sheet2!A1:B2 CONV_XL_R1C1, [doc]sheet:sheet2!R1C1:R2C2 @param bFullAddressNotation If TRUE, the full address notation will be used. For example in case all columns are used, "A1:AMJ177" is full address notation and "1:177" is shortened address notation. @returns String contains formatted cell range in address convention
*/
OUString Format( const ScDocument& rDocument,
ScRefFlags nFlags = ScRefFlags::ZERO, const ScAddress::Details& rDetails = ScAddress::detailsOOOa1, bool bFullAddressNotation = false ) const;
/** @param rErrorRange If FALSE is returned, the positions contain <0 or >MAX... values if shifted out of bounds. @param pDocument The document for the maximum defined sheet number.
*/
[[nodiscard]] bool Move( SCCOL aDeltaX, SCROW aDeltaY, SCTAB aDeltaZ,
ScRange& rErrorRange, const ScDocument& rDoc );
/** Same as Move() but with sticky end col/row anchors. */
[[nodiscard]] bool MoveSticky( const ScDocument& rDoc, SCCOL aDeltaX, SCROW aDeltaY, SCTAB aDeltaZ,
ScRange& rErrorRange );
/// If maximum end column should not be adapted during reference update. bool IsEndColSticky( const ScDocument& rDoc ) const; /// If maximum end row should not be adapted during reference update. bool IsEndRowSticky( const ScDocument& rDoc ) const;
/** Increment or decrement end column unless sticky or until it becomes sticky. Checks if the range encompasses at least two columns so should
be called before adjusting the start column. */ void IncEndColSticky( const ScDocument& rDoc, SCCOL nDelta );
/** Increment or decrement end row unless sticky or until it becomes sticky. Checks if the range encompasses at least two rows so should
be called before adjusting the start row. */ void IncEndRowSticky( const ScDocument& rDoc, SCROW nDelta );
inline size_t ScRange::hashArea() const
{ #if SAL_TYPES_SIZEOFPOINTER == 8 // 12 bits for the columns and 20 bits for the rows return
(static_cast<size_t>(aStart.Row()) << 44) ^
(static_cast<size_t>(aStart.Col()) << 32) ^
(static_cast<size_t>(aEnd.Col()) << 20) ^ static_cast<size_t>(aEnd.Row()); #else // Assume that there are not that many ranges with identical corners so we // won't have too many collisions. Also assume that more lower row and // column numbers are used so that there are not too many conflicts with // the columns hashed into the values, and that start row and column // usually don't exceed certain values. High bits are not masked off and // may overlap with lower bits of other values, e.g. if start column is // greater than assumed. return
(static_cast<size_t>(aStart.Row()) << 26) ^ // start row <= 2^6
(static_cast<size_t>(aStart.Col()) << 21) ^ // start column <= 2^5
(static_cast<size_t>(aEnd.Col()) << 15) ^ // end column <= 2^6 static_cast<size_t>(aEnd.Row()); // end row <= 2^15 #endif
}
inline size_t ScRange::hashStartColumn() const
{ #if SAL_TYPES_SIZEOFPOINTER == 8 // 20 bits for the rows return
(static_cast<size_t>(aStart.Col()) << 40) ^
(static_cast<size_t>(aStart.Row()) << 20) ^ static_cast<size_t>(aEnd.Row()); #else // Assume that for the start row more lower row numbers are used so that // there are not too many conflicts with the column hashed into the higher // values. return
(static_cast<size_t>(aStart.Col()) << 24) ^ // start column <= 2^8
(static_cast<size_t>(aStart.Row()) << 16) ^ // start row <= 2^8 static_cast<size_t>(aEnd.Row()); #endif
}
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.