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 .
22 #include <com/sun/star/uno/Reference.hxx>
23 #include <com/sun/star/lang/IllegalArgumentException.hpp>
25 #include <canvas/canvastoolsdllapi.h>
27 namespace com::sun::star::geometry
31 struct RealBezierSegment2D
;
32 struct RealRectangle2D
;
33 struct AffineMatrix2D
;
35 struct IntegerPoint2D
;
37 struct IntegerRectangle2D
;
40 namespace com::sun::star::rendering
43 struct StrokeAttributes
;
46 struct IntegerBitmapLayout
;
50 namespace com::sun::star::uno
{ template <class E
> class Sequence
; }
57 // Input checking facilities
60 // This header provides methods to check all common
61 // css::rendering::* method input parameters against
62 // compliance to the API specification.
64 /** Verify that the given transformation contains valid floating point
71 The interface that should be reported as the one
72 generating the exception.
75 Argument position on the call site (i.e. the position of
76 the argument, checked here, on the UNO interface
77 method. Counting starts at 0).
79 @throws a lang::IllegalArgumentException, if anything is wrong
81 CANVASTOOLS_DLLPUBLIC
void verifyInput( const css::geometry::AffineMatrix2D
& rMatrix
,
83 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
84 ::sal_Int16 nArgPos
);
86 /** Verify that the given transformation contains valid floating point
93 The interface that should be reported as the one
94 generating the exception.
97 Argument position on the call site (i.e. the position of
98 the argument, checked here, on the UNO interface
99 method. Counting starts at 0).
101 @throws a lang::IllegalArgumentException, if anything is wrong
103 CANVASTOOLS_DLLPUBLIC
void verifyInput( const css::geometry::Matrix2D
& rMatrix
,
105 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
106 ::sal_Int16 nArgPos
);
108 /** Verify that the given point contains valid floating point
115 The interface that should be reported as the one
116 generating the exception.
119 Argument position on the call site (i.e. the position of
120 the argument, checked here, on the UNO interface
121 method. Counting starts at 0).
123 @throws a lang::IllegalArgumentException, if anything is wrong
125 CANVASTOOLS_DLLPUBLIC
void verifyInput( const css::geometry::RealPoint2D
& rPoint
,
127 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
128 ::sal_Int16 nArgPos
);
130 /** Verify that the given bezier segment contains valid
131 floating point values.
137 The interface that should be reported as the one
138 generating the exception.
141 Argument position on the call site (i.e. the position of
142 the argument, checked here, on the UNO interface
143 method. Counting starts at 0).
145 @throws a lang::IllegalArgumentException, if anything is wrong
147 CANVASTOOLS_DLLPUBLIC
void verifyInput( const css::geometry::RealBezierSegment2D
& rSegment
,
149 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
150 ::sal_Int16 nArgPos
);
152 /** Verify that the given rectangle contains valid floating
159 The interface that should be reported as the one
160 generating the exception.
163 Argument position on the call site (i.e. the position of
164 the argument, checked here, on the UNO interface
165 method. Counting starts at 0).
167 @throws a lang::IllegalArgumentException, if anything is wrong
169 CANVASTOOLS_DLLPUBLIC
void verifyInput( const css::geometry::RealRectangle2D
& rRect
,
171 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
172 ::sal_Int16 nArgPos
);
174 /** Basic check for view state validity.
180 The interface that should be reported as the one
181 generating the exception.
184 Argument position on the call site (i.e. the position of
185 the argument, checked here, on the UNO interface
186 method. Counting starts at 0).
188 @throws a lang::IllegalArgumentException, if anything is wrong
190 CANVASTOOLS_DLLPUBLIC
void verifyInput( const css::rendering::ViewState
& viewState
,
192 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
193 ::sal_Int16 nArgPos
);
195 /** Basic check for render state validity.
201 The interface that should be reported as the one
202 generating the exception.
205 Argument position on the call site (i.e. the position of
206 the argument, checked here, on the UNO interface
207 method. Counting starts at 0).
209 @param nMinColorComponents
210 Minimal number of color components available in
211 RenderState::DeviceColor
213 @throws a lang::IllegalArgumentException, if anything is wrong
215 CANVASTOOLS_DLLPUBLIC
void verifyInput( const css::rendering::RenderState
& renderState
,
217 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
219 sal_Int32 nMinColorComponents
=0 );
221 /** Basic check for stroke attributes validity.
223 @param strokeAttributes
227 The interface that should be reported as the one
228 generating the exception.
231 Argument position on the call site (i.e. the position of
232 the argument, checked here, on the UNO interface
233 method. Counting starts at 0).
235 @throws a lang::IllegalArgumentException, if anything is wrong
237 CANVASTOOLS_DLLPUBLIC
void verifyInput( const css::rendering::StrokeAttributes
& strokeAttributes
,
239 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
240 ::sal_Int16 nArgPos
);
242 /** Basic check for texture validity.
248 The interface that should be reported as the one
249 generating the exception.
252 Argument position on the call site (i.e. the position of
253 the argument, checked here, on the UNO interface
254 method. Counting starts at 0).
256 @throws a lang::IllegalArgumentException, if anything is wrong
258 CANVASTOOLS_DLLPUBLIC
void verifyInput( const css::rendering::Texture
& texture
,
260 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
261 ::sal_Int16 nArgPos
);
263 /** Basic check for bitmap layout validity.
266 Bitmap layout to check
269 The interface that should be reported as the one
270 generating the exception.
273 Argument position on the call site (i.e. the position of
274 the argument, checked here, on the UNO interface
275 method. Counting starts at 0).
277 @throws a lang::IllegalArgumentException, if anything is wrong
279 CANVASTOOLS_DLLPUBLIC
void verifyInput( const css::rendering::IntegerBitmapLayout
& bitmapLayout
,
281 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
282 ::sal_Int16 nArgPos
);
284 /** Basic check for font request validity.
287 Font request to check
290 The interface that should be reported as the one
291 generating the exception.
294 Argument position on the call site (i.e. the position of
295 the argument, checked here, on the UNO interface
296 method. Counting starts at 0).
298 @throws a lang::IllegalArgumentException, if anything is wrong
300 CANVASTOOLS_DLLPUBLIC
void verifyInput( const css::rendering::FontRequest
& fontRequest
,
302 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
303 ::sal_Int16 nArgPos
);
305 /** Templatized check for uno::Reference validity.
308 Reference to check against non-NILness
311 The interface that should be reported as the one
312 generating the exception.
315 Argument position on the call site (i.e. the position of
316 the argument, checked here, on the UNO interface
317 method. Counting starts at 0).
319 @throws a lang::IllegalArgumentException, if anything is wrong
321 template< class Interface
> void verifyInput(
322 const css::uno::Reference
< Interface
>& rRef
,
324 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
325 ::sal_Int16 nArgPos
)
329 #if OSL_DEBUG_LEVEL > 0
330 throw css::lang::IllegalArgumentException(
331 OUString::createFromAscii(pStr
) + ": reference is NULL",
335 (void)pStr
; (void)xIf
; (void)nArgPos
;
336 throw css::lang::IllegalArgumentException();
341 /** Templatized check for content-of-sequence validity.
344 Sequence of things to check
347 The interface that should be reported as the one
348 generating the exception.
351 Argument position on the call site (i.e. the position of
352 the argument, checked here, on the UNO interface
353 method. Counting starts at 0).
355 @throws a lang::IllegalArgumentException, if anything is wrong
357 template< typename SequenceContent
> void verifyInput(
358 const css::uno::Sequence
< SequenceContent
>& rSequence
,
360 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
361 ::sal_Int16 nArgPos
)
363 const SequenceContent
* pCurr
= rSequence
.getConstArray();
364 const SequenceContent
* pEnd
= pCurr
+ rSequence
.getLength();
365 while( pCurr
!= pEnd
)
366 verifyInput( *pCurr
++, pStr
, xIf
, nArgPos
);
369 /// Catch-all, to handle cases that DON'T need input checking (i.e. the Integer geometry ones)
370 template< typename T
> void verifyInput( const T
& /*rDummy*/,
371 const char* /*pStr*/,
372 const css::uno::Reference
< css::uno::XInterface
>& /*xIf*/,
373 ::sal_Int16
/*nArgPos*/ )
377 // TODO(Q2): Employ some template arglist magic here, to avoid
378 // this duplication of code...
380 template< typename Arg0
> void verifyArgs( const Arg0
& rArg0
,
382 const css::uno::Reference
< css::uno::XInterface
>& xIf
)
384 verifyInput( rArg0
, pStr
, xIf
, 0 );
387 template< typename Arg0
,
388 typename Arg1
> void verifyArgs( const Arg0
& rArg0
,
391 const css::uno::Reference
< css::uno::XInterface
>& xIf
)
393 verifyInput( rArg0
, pStr
, xIf
, 0 );
394 verifyInput( rArg1
, pStr
, xIf
, 1 );
397 template< typename Arg0
,
399 typename Arg2
> void verifyArgs( const Arg0
& rArg0
,
403 const css::uno::Reference
< css::uno::XInterface
>& xIf
)
405 verifyInput( rArg0
, pStr
, xIf
, 0 );
406 verifyInput( rArg1
, pStr
, xIf
, 1 );
407 verifyInput( rArg2
, pStr
, xIf
, 2 );
410 template< typename Arg0
,
413 typename Arg3
> void verifyArgs( const Arg0
& rArg0
,
418 const css::uno::Reference
< css::uno::XInterface
>& xIf
)
420 verifyInput( rArg0
, pStr
, xIf
, 0 );
421 verifyInput( rArg1
, pStr
, xIf
, 1 );
422 verifyInput( rArg2
, pStr
, xIf
, 2 );
423 verifyInput( rArg3
, pStr
, xIf
, 3 );
426 template< typename Arg0
,
430 typename Arg4
> void verifyArgs( const Arg0
& rArg0
,
436 const css::uno::Reference
< css::uno::XInterface
>& xIf
)
438 verifyInput( rArg0
, pStr
, xIf
, 0 );
439 verifyInput( rArg1
, pStr
, xIf
, 1 );
440 verifyInput( rArg2
, pStr
, xIf
, 2 );
441 verifyInput( rArg3
, pStr
, xIf
, 3 );
442 verifyInput( rArg4
, pStr
, xIf
, 4 );
445 template< typename Arg0
,
450 typename Arg5
> void verifyArgs( const Arg0
& rArg0
,
457 const css::uno::Reference
< css::uno::XInterface
>& xIf
)
459 verifyInput( rArg0
, pStr
, xIf
, 0 );
460 verifyInput( rArg1
, pStr
, xIf
, 1 );
461 verifyInput( rArg2
, pStr
, xIf
, 2 );
462 verifyInput( rArg3
, pStr
, xIf
, 3 );
463 verifyInput( rArg4
, pStr
, xIf
, 4 );
464 verifyInput( rArg5
, pStr
, xIf
, 5 );
467 template< typename Arg0
,
473 typename Arg6
> void verifyArgs( const Arg0
& rArg0
,
481 const css::uno::Reference
< css::uno::XInterface
>& xIf
)
483 verifyInput( rArg0
, pStr
, xIf
, 0 );
484 verifyInput( rArg1
, pStr
, xIf
, 1 );
485 verifyInput( rArg2
, pStr
, xIf
, 2 );
486 verifyInput( rArg3
, pStr
, xIf
, 3 );
487 verifyInput( rArg4
, pStr
, xIf
, 4 );
488 verifyInput( rArg5
, pStr
, xIf
, 5 );
489 verifyInput( rArg6
, pStr
, xIf
, 6 );
493 /** Range checker, which throws css::lang::IllegalArgument exception, when
496 template< typename NumType
> inline void verifyRange( NumType arg
, NumType lowerBound
, NumType upperBound
)
498 if( arg
< lowerBound
||
501 throw css::lang::IllegalArgumentException();
505 /** Range checker, which throws css::lang::IllegalArgument exception, when
508 The checked range is half open, i.e. only bound by the specified value.
514 Bound to check against
517 When true, given bound is the lower bound. When false,
518 given bound is the upper bound.
520 template< typename NumType
> inline void verifyRange( NumType arg
, NumType bound
, bool bLowerBound
=true )
522 if( (bLowerBound
&& arg
< bound
) ||
523 (!bLowerBound
&& arg
> bound
) )
525 throw css::lang::IllegalArgumentException();
529 /** Range checker, which throws css::lang::IndexOutOfBounds exception, when
530 index range is violated
536 Given rectangle must be within ((0,0), (size.Width, size.Height))
538 CANVASTOOLS_DLLPUBLIC
void verifyIndexRange( const css::geometry::IntegerRectangle2D
& rect
,
539 const css::geometry::IntegerSize2D
& size
);
541 /** Range checker, which throws css::lang::IndexOutOfBounds exception, when
542 index range is violated
548 Given position must be within ((0,0), (size.Width, size.Height))
550 CANVASTOOLS_DLLPUBLIC
void verifyIndexRange( const css::geometry::IntegerPoint2D
& pos
,
551 const css::geometry::IntegerSize2D
& size
);
553 /** Range checker, which throws css::lang::IndexOutOfBounds exception, when
554 the size is negative or null
559 CANVASTOOLS_DLLPUBLIC
void verifyBitmapSize( const css::geometry::IntegerSize2D
& size
,
561 const css::uno::Reference
< css::uno::XInterface
>& xIf
);
563 /** Range checker, which throws css::lang::IndexOutOfBounds exception, when
564 the size is negative or null
569 CANVASTOOLS_DLLPUBLIC
void verifySpriteSize( const css::geometry::RealSize2D
& size
,
571 const css::uno::Reference
< css::uno::XInterface
>& xIf
);
575 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */