LibreOffice Module sc (master) 1
xladdress.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <xladdress.hxx>
21#include <xestream.hxx>
22#include <xltracer.hxx>
23#include <xistream.hxx>
24
25#include <o3tl/safeint.hxx>
26#include <osl/diagnose.h>
27
29{
30 mnRow = rStrm.ReaduInt16();
31 mnCol = rStrm.ReaduInt16();
32}
33
34void XclAddress::Write( XclExpStream& rStrm ) const
35{
36 rStrm << static_cast<sal_uInt16> (mnRow);
37 rStrm << mnCol;
38}
39
40bool XclRange::Contains( const XclAddress& rPos ) const
41{
42 return (maFirst.mnCol <= rPos.mnCol) && (rPos.mnCol <= maLast.mnCol) &&
43 (maFirst.mnRow <= rPos.mnRow) && (rPos.mnRow <= maLast.mnRow);
44}
45
46void XclRange::Read( XclImpStream& rStrm, bool bCol16Bit )
47{
48 maFirst.mnRow = rStrm.ReaduInt16();
49 maLast.mnRow = rStrm.ReaduInt16();
50
51 if( bCol16Bit )
52 {
53 maFirst.mnCol = rStrm.ReaduInt16();
54 maLast.mnCol = rStrm.ReaduInt16();
55 }
56 else
57 {
58 maFirst.mnCol = rStrm.ReaduInt8();
59 maLast.mnCol = rStrm.ReaduInt8();
60 }
61}
62
63void XclRange::Write( XclExpStream& rStrm, bool bCol16Bit ) const
64{
65 rStrm << static_cast<sal_uInt16>(maFirst.mnRow) << static_cast<sal_uInt16>(maLast.mnRow);
66 if( bCol16Bit )
68 else
69 rStrm << static_cast< sal_uInt8 >( maFirst.mnCol ) << static_cast< sal_uInt8 >( maLast.mnCol );
70}
71
73{
74 XclRange aXclRange;
75 if( !mRanges.empty() )
76 {
77 XclRangeVector::const_iterator aIt = mRanges.begin(), aEnd = mRanges.end();
78 aXclRange = *aIt;
79 for( ++aIt; aIt != aEnd; ++aIt )
80 {
81 aXclRange.maFirst.mnCol = ::std::min( aXclRange.maFirst.mnCol, aIt->maFirst.mnCol );
82 aXclRange.maFirst.mnRow = ::std::min( aXclRange.maFirst.mnRow, aIt->maFirst.mnRow );
83 aXclRange.maLast.mnCol = ::std::max( aXclRange.maLast.mnCol, aIt->maLast.mnCol );
84 aXclRange.maLast.mnRow = ::std::max( aXclRange.maLast.mnRow, aIt->maLast.mnRow );
85 }
86 }
87 return aXclRange;
88}
89
90void XclRangeList::Read( XclImpStream& rStrm, bool bCol16Bit, sal_uInt16 nCountInStream )
91{
92 sal_uInt16 nCount;
93 if (nCountInStream)
94 nCount = nCountInStream;
95 else
96 nCount = rStrm.ReaduInt16();
97
98 if (!nCount)
99 return;
100
101 XclRange aRange;
102 while (true)
103 {
104 aRange.Read(rStrm, bCol16Bit);
105 if (!rStrm.IsValid())
106 break;
107 mRanges.emplace_back(aRange);
108 --nCount;
109 if (!nCount)
110 break;
111 }
112}
113
114void XclRangeList::Write( XclExpStream& rStrm, bool bCol16Bit, sal_uInt16 nCountInStream ) const
115{
116 WriteSubList( rStrm, 0, mRanges.size(), bCol16Bit, nCountInStream );
117}
118
119void XclRangeList::WriteSubList( XclExpStream& rStrm, size_t nBegin, size_t nCount, bool bCol16Bit,
120 sal_uInt16 nCountInStream ) const
121{
122 OSL_ENSURE( nBegin <= mRanges.size(), "XclRangeList::WriteSubList - invalid start position" );
123 size_t nEnd = ::std::min< size_t >( nBegin + nCount, mRanges.size() );
124 if (!nCountInStream)
125 {
126 sal_uInt16 nXclCount = ulimit_cast< sal_uInt16 >( nEnd - nBegin );
127 rStrm << nXclCount;
128 }
129 rStrm.SetSliceSize( bCol16Bit ? 8 : 6 );
130 std::for_each(mRanges.begin() + nBegin, mRanges.begin() + nEnd,
131 [&rStrm, &bCol16Bit](const XclRange& rRange) { rRange.Write(rStrm, bCol16Bit); });
132}
133
135 mrTracer( rTracer ),
136 maMaxPos( rMaxPos ),
137 mnMaxCol( static_cast< sal_uInt16 >( rMaxPos.Col() ) ),
138 mnMaxRow( static_cast< sal_uInt16 >( rMaxPos.Row() ) ),
139 mbColTrunc( false ),
140 mbRowTrunc( false ),
141 mbTabTrunc( false )
142{
143 OSL_ENSURE( o3tl::make_unsigned( rMaxPos.Col() ) <= SAL_MAX_UINT16, "XclAddressConverterBase::XclAddressConverterBase - invalid max column" );
144 OSL_ENSURE( o3tl::make_unsigned( rMaxPos.Row() ) <= SAL_MAX_UINT32, "XclAddressConverterBase::XclAddressConverterBase - invalid max row" );
145}
146
148{
149}
150
152{
153 bool bValid = (0 <= nScTab) && (nScTab <= maMaxPos.Tab());
154 if( !bValid )
155 {
156 mbTabTrunc |= (nScTab > maMaxPos.Tab()); // do not warn for deleted refs
158 }
159}
160
161/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SCTAB Tab() const
Definition: address.hxx:283
SCROW Row() const
Definition: address.hxx:274
SCCOL Col() const
Definition: address.hxx:279
bool mbTabTrunc
Flag for "rows truncated" warning box.
Definition: xladdress.hxx:166
void CheckScTab(SCTAB nScTab)
Checks if the passed sheet index is valid.
Definition: xladdress.cxx:151
XclAddressConverterBase(XclTracer &rTracer, const ScAddress &rMaxPos)
Definition: xladdress.cxx:134
virtual ~XclAddressConverterBase()
Definition: xladdress.cxx:147
ScAddress maMaxPos
Tracer for invalid addresses.
Definition: xladdress.hxx:161
This class is used to export Excel record streams.
Definition: xestream.hxx:73
This class is used to import record oriented streams.
Definition: xistream.hxx:278
void Write(XclExpStream &rStrm, bool bCol16Bit=true, sal_uInt16 nCountInStream=0) const
Definition: xladdress.cxx:114
void Read(XclImpStream &rStrm, bool bCol16Bit=true, sal_uInt16 nCountInStream=0)
Definition: xladdress.cxx:90
XclRange GetEnclosingRange() const
Definition: xladdress.cxx:72
XclRangeVector mRanges
Definition: xladdress.hxx:104
void WriteSubList(XclExpStream &rStrm, size_t nBegin, size_t nCount, bool bCol16Bit=true, sal_uInt16 nCountInStream=0) const
Definition: xladdress.cxx:119
This class wraps an MSFilterTracer to create trace logs for import/export filters.
Definition: xltracer.hxx:51
void TraceInvalidTab(SCTAB nTab, SCTAB nMaxTab)
Definition: xltracer.cxx:53
int nCount
void SvStream & rStrm
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
A 2D cell address struct with Excel column and row indexes.
Definition: xladdress.hxx:30
sal_uInt16 mnCol
Definition: xladdress.hxx:31
sal_uInt32 mnRow
Definition: xladdress.hxx:32
void Write(XclExpStream &rStrm) const
Definition: xladdress.cxx:34
void Read(XclImpStream &rStrm)
Definition: xladdress.cxx:28
A 2D cell range address struct with Excel column and row indexes.
Definition: xladdress.hxx:59
XclAddress maFirst
Definition: xladdress.hxx:60
bool Contains(const XclAddress &rPos) const
Definition: xladdress.cxx:40
void Write(XclExpStream &rStrm, bool bCol16Bit=true) const
Definition: xladdress.cxx:63
XclAddress maLast
Definition: xladdress.hxx:61
void Read(XclImpStream &rStrm, bool bCol16Bit=true)
Definition: xladdress.cxx:46
unsigned char sal_uInt8
#define SAL_MAX_UINT16
#define SAL_MAX_UINT32
sal_Int16 SCTAB
Definition: types.hxx:22