bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / filter / excel / xladdress.cxx
blobffc06a095c4294241b049817f827e80873c5a718
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 "xladdress.hxx"
21 #include "xestream.hxx"
22 #include "xltracer.hxx"
23 #include "xistream.hxx"
25 // ============================================================================
27 void XclAddress::Read( XclImpStream& rStrm, bool bCol16Bit )
29 mnRow = rStrm.ReaduInt16();
30 if( bCol16Bit )
31 rStrm >> mnCol;
32 else
33 mnCol = rStrm.ReaduInt8();
36 void XclAddress::Write( XclExpStream& rStrm, bool bCol16Bit ) const
38 rStrm << static_cast<sal_uInt16> (mnRow);
39 if( bCol16Bit )
40 rStrm << mnCol;
41 else
42 rStrm << static_cast< sal_uInt8 >( mnCol );
45 // ----------------------------------------------------------------------------
47 bool XclRange::Contains( const XclAddress& rPos ) const
49 return (maFirst.mnCol <= rPos.mnCol) && (rPos.mnCol <= maLast.mnCol) &&
50 (maFirst.mnRow <= rPos.mnRow) && (rPos.mnRow <= maLast.mnRow);
53 void XclRange::Read( XclImpStream& rStrm, bool bCol16Bit )
55 maFirst.mnRow = rStrm.ReaduInt16();
56 maLast.mnRow = rStrm.ReaduInt16();
58 if( bCol16Bit )
59 rStrm >> maFirst.mnCol >> maLast.mnCol;
60 else
62 maFirst.mnCol = rStrm.ReaduInt8();
63 maLast.mnCol = rStrm.ReaduInt8();
67 void XclRange::Write( XclExpStream& rStrm, bool bCol16Bit ) const
69 rStrm << static_cast<sal_uInt16>(maFirst.mnRow) << static_cast<sal_uInt16>(maLast.mnRow);
70 if( bCol16Bit )
71 rStrm << maFirst.mnCol << maLast.mnCol;
72 else
73 rStrm << static_cast< sal_uInt8 >( maFirst.mnCol ) << static_cast< sal_uInt8 >( maLast.mnCol );
76 // ----------------------------------------------------------------------------
78 XclRange XclRangeList::GetEnclosingRange() const
80 XclRange aXclRange;
81 if( !empty() )
83 const_iterator aIt = begin(), aEnd = end();
84 aXclRange = *aIt;
85 for( ++aIt; aIt != aEnd; ++aIt )
87 aXclRange.maFirst.mnCol = ::std::min( aXclRange.maFirst.mnCol, aIt->maFirst.mnCol );
88 aXclRange.maFirst.mnRow = ::std::min( aXclRange.maFirst.mnRow, aIt->maFirst.mnRow );
89 aXclRange.maLast.mnCol = ::std::max( aXclRange.maLast.mnCol, aIt->maLast.mnCol );
90 aXclRange.maLast.mnRow = ::std::max( aXclRange.maLast.mnRow, aIt->maLast.mnRow );
93 return aXclRange;
96 void XclRangeList::Read( XclImpStream& rStrm, bool bCol16Bit )
98 sal_uInt16 nCount;
99 rStrm >> nCount;
100 size_t nOldSize = size();
101 resize( nOldSize + nCount );
102 for( iterator aIt = begin() + nOldSize; rStrm.IsValid() && (nCount > 0); --nCount, ++aIt )
103 aIt->Read( rStrm, bCol16Bit );
106 void XclRangeList::Write( XclExpStream& rStrm, bool bCol16Bit ) const
108 WriteSubList( rStrm, 0, size(), bCol16Bit );
111 void XclRangeList::WriteSubList( XclExpStream& rStrm, size_t nBegin, size_t nCount, bool bCol16Bit ) const
113 OSL_ENSURE( nBegin <= size(), "XclRangeList::WriteSubList - invalid start position" );
114 size_t nEnd = ::std::min< size_t >( nBegin + nCount, size() );
115 sal_uInt16 nXclCount = ulimit_cast< sal_uInt16 >( nEnd - nBegin );
116 rStrm << nXclCount;
117 rStrm.SetSliceSize( bCol16Bit ? 8 : 6 );
118 for( const_iterator aIt = begin() + nBegin, aEnd = begin() + nEnd; aIt != aEnd; ++aIt )
119 aIt->Write( rStrm, bCol16Bit );
122 // ============================================================================
124 XclAddressConverterBase::XclAddressConverterBase( XclTracer& rTracer, const ScAddress& rMaxPos ) :
125 mrTracer( rTracer ),
126 maMaxPos( rMaxPos ),
127 mnMaxCol( static_cast< sal_uInt16 >( rMaxPos.Col() ) ),
128 mnMaxRow( static_cast< sal_uInt16 >( rMaxPos.Row() ) ),
129 mbColTrunc( false ),
130 mbRowTrunc( false ),
131 mbTabTrunc( false )
133 OSL_ENSURE( static_cast< size_t >( rMaxPos.Col() ) <= SAL_MAX_UINT16, "XclAddressConverterBase::XclAddressConverterBase - invalid max column" );
134 OSL_ENSURE( static_cast< size_t >( rMaxPos.Row() ) <= SAL_MAX_UINT32, "XclAddressConverterBase::XclAddressConverterBase - invalid max row" );
137 XclAddressConverterBase::~XclAddressConverterBase()
141 bool XclAddressConverterBase::CheckScTab( SCTAB nScTab, bool bWarn )
143 bool bValid = (0 <= nScTab) && (nScTab <= maMaxPos.Tab());
144 if( !bValid && bWarn )
146 mbTabTrunc |= (nScTab > maMaxPos.Tab()); // do not warn for deleted refs
147 mrTracer.TraceInvalidTab( nScTab, maMaxPos.Tab() );
149 return bValid;
152 // ============================================================================
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */