1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #include <osl/diagnose.h>
27 void XclAddress::Read( XclImpStream
& rStrm
, bool bCol16Bit
)
29 mnRow
= rStrm
.ReaduInt16();
31 mnCol
= rStrm
.ReaduInt16();
33 mnCol
= rStrm
.ReaduInt8();
36 void XclAddress::Write( XclExpStream
& rStrm
, bool bCol16Bit
) const
38 rStrm
<< static_cast<sal_uInt16
> (mnRow
);
42 rStrm
<< static_cast< sal_uInt8
>( mnCol
);
45 bool XclRange::Contains( const XclAddress
& rPos
) const
47 return (maFirst
.mnCol
<= rPos
.mnCol
) && (rPos
.mnCol
<= maLast
.mnCol
) &&
48 (maFirst
.mnRow
<= rPos
.mnRow
) && (rPos
.mnRow
<= maLast
.mnRow
);
51 void XclRange::Read( XclImpStream
& rStrm
, bool bCol16Bit
)
53 maFirst
.mnRow
= rStrm
.ReaduInt16();
54 maLast
.mnRow
= rStrm
.ReaduInt16();
58 maFirst
.mnCol
= rStrm
.ReaduInt16();
59 maLast
.mnCol
= rStrm
.ReaduInt16();
63 maFirst
.mnCol
= rStrm
.ReaduInt8();
64 maLast
.mnCol
= rStrm
.ReaduInt8();
68 void XclRange::Write( XclExpStream
& rStrm
, bool bCol16Bit
) const
70 rStrm
<< static_cast<sal_uInt16
>(maFirst
.mnRow
) << static_cast<sal_uInt16
>(maLast
.mnRow
);
72 rStrm
<< maFirst
.mnCol
<< maLast
.mnCol
;
74 rStrm
<< static_cast< sal_uInt8
>( maFirst
.mnCol
) << static_cast< sal_uInt8
>( maLast
.mnCol
);
77 XclRange
XclRangeList::GetEnclosingRange() const
80 if( !mRanges
.empty() )
82 XclRangeVector::const_iterator aIt
= mRanges
.begin(), aEnd
= mRanges
.end();
84 for( ++aIt
; aIt
!= aEnd
; ++aIt
)
86 aXclRange
.maFirst
.mnCol
= ::std::min( aXclRange
.maFirst
.mnCol
, aIt
->maFirst
.mnCol
);
87 aXclRange
.maFirst
.mnRow
= ::std::min( aXclRange
.maFirst
.mnRow
, aIt
->maFirst
.mnRow
);
88 aXclRange
.maLast
.mnCol
= ::std::max( aXclRange
.maLast
.mnCol
, aIt
->maLast
.mnCol
);
89 aXclRange
.maLast
.mnRow
= ::std::max( aXclRange
.maLast
.mnRow
, aIt
->maLast
.mnRow
);
95 void XclRangeList::Read( XclImpStream
& rStrm
, bool bCol16Bit
, sal_uInt16 nCountInStream
)
99 nCount
= nCountInStream
;
101 nCount
= rStrm
.ReaduInt16();
102 size_t nOldSize
= mRanges
.size();
103 mRanges
.resize( nOldSize
+ nCount
);
104 for( XclRangeVector::iterator aIt
= mRanges
.begin() + nOldSize
; rStrm
.IsValid() && (nCount
> 0); --nCount
, ++aIt
)
105 aIt
->Read( rStrm
, bCol16Bit
);
108 void XclRangeList::Write( XclExpStream
& rStrm
, bool bCol16Bit
, sal_uInt16 nCountInStream
) const
110 WriteSubList( rStrm
, 0, mRanges
.size(), bCol16Bit
, nCountInStream
);
113 void XclRangeList::WriteSubList( XclExpStream
& rStrm
, size_t nBegin
, size_t nCount
, bool bCol16Bit
,
114 sal_uInt16 nCountInStream
) const
116 OSL_ENSURE( nBegin
<= mRanges
.size(), "XclRangeList::WriteSubList - invalid start position" );
117 size_t nEnd
= ::std::min
< size_t >( nBegin
+ nCount
, mRanges
.size() );
120 sal_uInt16 nXclCount
= ulimit_cast
< sal_uInt16
>( nEnd
- nBegin
);
123 rStrm
.SetSliceSize( bCol16Bit
? 8 : 6 );
124 for( XclRangeVector::const_iterator aIt
= mRanges
.begin() + nBegin
, aEnd
= mRanges
.begin() + nEnd
; aIt
!= aEnd
; ++aIt
)
125 aIt
->Write( rStrm
, bCol16Bit
);
128 XclAddressConverterBase::XclAddressConverterBase( XclTracer
& rTracer
, const ScAddress
& rMaxPos
) :
131 mnMaxCol( static_cast< sal_uInt16
>( rMaxPos
.Col() ) ),
132 mnMaxRow( static_cast< sal_uInt16
>( rMaxPos
.Row() ) ),
137 OSL_ENSURE( static_cast< size_t >( rMaxPos
.Col() ) <= SAL_MAX_UINT16
, "XclAddressConverterBase::XclAddressConverterBase - invalid max column" );
138 OSL_ENSURE( static_cast< size_t >( rMaxPos
.Row() ) <= SAL_MAX_UINT32
, "XclAddressConverterBase::XclAddressConverterBase - invalid max row" );
141 XclAddressConverterBase::~XclAddressConverterBase()
145 bool XclAddressConverterBase::CheckScTab( SCTAB nScTab
, bool bWarn
)
147 bool bValid
= (0 <= nScTab
) && (nScTab
<= maMaxPos
.Tab());
148 if( !bValid
&& bWarn
)
150 mbTabTrunc
|= (nScTab
> maMaxPos
.Tab()); // do not warn for deleted refs
151 mrTracer
.TraceInvalidTab( nScTab
, maMaxPos
.Tab() );
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */