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 #ifndef INCLUDED_CANVAS_VERIFYINPUT_HXX
21 #define INCLUDED_CANVAS_VERIFYINPUT_HXX
23 #include <com/sun/star/uno/Reference.hxx>
24 #include <com/sun/star/lang/IllegalArgumentException.hpp>
26 #include <canvas/canvastoolsdllapi.h>
28 namespace com
{ namespace sun
{ namespace star
{ namespace geometry
32 struct RealBezierSegment2D
;
33 struct RealRectangle2D
;
34 struct AffineMatrix2D
;
36 struct IntegerPoint2D
;
38 struct IntegerRectangle2D
;
41 namespace com
{ namespace sun
{ namespace star
{ namespace rendering
44 struct StrokeAttributes
;
47 struct IntegerBitmapLayout
;
51 namespace com::sun::star::uno
{ template <class E
> class Sequence
; }
58 // Input checking facilities
61 // This header provides methods to check all common
62 // css::rendering::* method input parameters against
63 // compliance to the API specification.
65 /** Verify that the given transformation contains valid floating point
72 The interface that should be reported as the one
73 generating the exception.
76 Argument position on the call site (i.e. the position of
77 the argument, checked here, on the UNO interface
78 method. Counting starts at 0).
80 @throws an lang::IllegalArgumentException, if anything is wrong
82 CANVASTOOLS_DLLPUBLIC
void verifyInput( const css::geometry::AffineMatrix2D
& rMatrix
,
84 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
85 ::sal_Int16 nArgPos
);
87 /** Verify that the given transformation contains valid floating point
94 The interface that should be reported as the one
95 generating the exception.
98 Argument position on the call site (i.e. the position of
99 the argument, checked here, on the UNO interface
100 method. Counting starts at 0).
102 @throws an lang::IllegalArgumentException, if anything is wrong
104 CANVASTOOLS_DLLPUBLIC
void verifyInput( const css::geometry::Matrix2D
& rMatrix
,
106 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
107 ::sal_Int16 nArgPos
);
109 /** Verify that the given point contains valid floating point
116 The interface that should be reported as the one
117 generating the exception.
120 Argument position on the call site (i.e. the position of
121 the argument, checked here, on the UNO interface
122 method. Counting starts at 0).
124 @throws an lang::IllegalArgumentException, if anything is wrong
126 CANVASTOOLS_DLLPUBLIC
void verifyInput( const css::geometry::RealPoint2D
& rPoint
,
128 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
129 ::sal_Int16 nArgPos
);
131 /** Verify that the given bezier segment contains valid
132 floating point values.
138 The interface that should be reported as the one
139 generating the exception.
142 Argument position on the call site (i.e. the position of
143 the argument, checked here, on the UNO interface
144 method. Counting starts at 0).
146 @throws an lang::IllegalArgumentException, if anything is wrong
148 CANVASTOOLS_DLLPUBLIC
void verifyInput( const css::geometry::RealBezierSegment2D
& rSegment
,
150 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
151 ::sal_Int16 nArgPos
);
153 /** Verify that the given rectangle contains valid floating
160 The interface that should be reported as the one
161 generating the exception.
164 Argument position on the call site (i.e. the position of
165 the argument, checked here, on the UNO interface
166 method. Counting starts at 0).
168 @throws an lang::IllegalArgumentException, if anything is wrong
170 CANVASTOOLS_DLLPUBLIC
void verifyInput( const css::geometry::RealRectangle2D
& rRect
,
172 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
173 ::sal_Int16 nArgPos
);
175 /** Basic check for view state validity.
181 The interface that should be reported as the one
182 generating the exception.
185 Argument position on the call site (i.e. the position of
186 the argument, checked here, on the UNO interface
187 method. Counting starts at 0).
189 @throws an lang::IllegalArgumentException, if anything is wrong
191 CANVASTOOLS_DLLPUBLIC
void verifyInput( const css::rendering::ViewState
& viewState
,
193 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
194 ::sal_Int16 nArgPos
);
196 /** Basic check for render state validity.
202 The interface that should be reported as the one
203 generating the exception.
206 Argument position on the call site (i.e. the position of
207 the argument, checked here, on the UNO interface
208 method. Counting starts at 0).
210 @param nMinColorComponents
211 Minimal number of color components available in
212 RenderState::DeviceColor
214 @throws an lang::IllegalArgumentException, if anything is wrong
216 CANVASTOOLS_DLLPUBLIC
void verifyInput( const css::rendering::RenderState
& renderState
,
218 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
220 sal_Int32 nMinColorComponents
=0 );
222 /** Basic check for stroke attributes validity.
224 @param strokeAttributes
228 The interface that should be reported as the one
229 generating the exception.
232 Argument position on the call site (i.e. the position of
233 the argument, checked here, on the UNO interface
234 method. Counting starts at 0).
236 @throws an lang::IllegalArgumentException, if anything is wrong
238 CANVASTOOLS_DLLPUBLIC
void verifyInput( const css::rendering::StrokeAttributes
& strokeAttributes
,
240 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
241 ::sal_Int16 nArgPos
);
243 /** Basic check for texture validity.
249 The interface that should be reported as the one
250 generating the exception.
253 Argument position on the call site (i.e. the position of
254 the argument, checked here, on the UNO interface
255 method. Counting starts at 0).
257 @throws an lang::IllegalArgumentException, if anything is wrong
259 CANVASTOOLS_DLLPUBLIC
void verifyInput( const css::rendering::Texture
& texture
,
261 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
262 ::sal_Int16 nArgPos
);
264 /** Basic check for bitmap layout validity.
267 Bitmap layout to check
270 The interface that should be reported as the one
271 generating the exception.
274 Argument position on the call site (i.e. the position of
275 the argument, checked here, on the UNO interface
276 method. Counting starts at 0).
278 @throws an lang::IllegalArgumentException, if anything is wrong
280 CANVASTOOLS_DLLPUBLIC
void verifyInput( const css::rendering::IntegerBitmapLayout
& bitmapLayout
,
282 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
283 ::sal_Int16 nArgPos
);
285 /** Basic check for font request validity.
288 Font request to check
291 The interface that should be reported as the one
292 generating the exception.
295 Argument position on the call site (i.e. the position of
296 the argument, checked here, on the UNO interface
297 method. Counting starts at 0).
299 @throws an lang::IllegalArgumentException, if anything is wrong
301 CANVASTOOLS_DLLPUBLIC
void verifyInput( const css::rendering::FontRequest
& fontRequest
,
303 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
304 ::sal_Int16 nArgPos
);
306 /** Templatized check for uno::Reference validity.
309 Reference to check against non-NILness
312 The interface that should be reported as the one
313 generating the exception.
316 Argument position on the call site (i.e. the position of
317 the argument, checked here, on the UNO interface
318 method. Counting starts at 0).
320 @throws an lang::IllegalArgumentException, if anything is wrong
322 template< class Interface
> void verifyInput(
323 const css::uno::Reference
< Interface
>& rRef
,
325 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
326 ::sal_Int16 nArgPos
)
330 #if OSL_DEBUG_LEVEL > 0
331 throw css::lang::IllegalArgumentException(
332 OUString::createFromAscii(pStr
) + ": reference is NULL",
336 (void)pStr
; (void)xIf
; (void)nArgPos
;
337 throw css::lang::IllegalArgumentException();
342 /** Templatized check for content-of-sequence validity.
345 Sequence of things to check
348 The interface that should be reported as the one
349 generating the exception.
352 Argument position on the call site (i.e. the position of
353 the argument, checked here, on the UNO interface
354 method. Counting starts at 0).
356 @throws an lang::IllegalArgumentException, if anything is wrong
358 template< typename SequenceContent
> void verifyInput(
359 const css::uno::Sequence
< SequenceContent
>& rSequence
,
361 const css::uno::Reference
< css::uno::XInterface
>& xIf
,
362 ::sal_Int16 nArgPos
)
364 const SequenceContent
* pCurr
= rSequence
.getConstArray();
365 const SequenceContent
* pEnd
= pCurr
+ rSequence
.getLength();
366 while( pCurr
!= pEnd
)
367 verifyInput( *pCurr
++, pStr
, xIf
, nArgPos
);
370 /// Catch-all, to handle cases that DON'T need input checking (i.e. the Integer geometry ones)
371 template< typename T
> void verifyInput( const T
& /*rDummy*/,
372 const char* /*pStr*/,
373 const css::uno::Reference
< css::uno::XInterface
>& /*xIf*/,
374 ::sal_Int16
/*nArgPos*/ )
378 // TODO(Q2): Employ some template arglist magic here, to avoid
379 // this duplication of code...
381 template< typename Arg0
> void verifyArgs( const Arg0
& rArg0
,
383 const css::uno::Reference
< css::uno::XInterface
>& xIf
)
385 verifyInput( rArg0
, pStr
, xIf
, 0 );
388 template< typename Arg0
,
389 typename Arg1
> void verifyArgs( const Arg0
& rArg0
,
392 const css::uno::Reference
< css::uno::XInterface
>& xIf
)
394 verifyInput( rArg0
, pStr
, xIf
, 0 );
395 verifyInput( rArg1
, pStr
, xIf
, 1 );
398 template< typename Arg0
,
400 typename Arg2
> void verifyArgs( const Arg0
& rArg0
,
404 const css::uno::Reference
< css::uno::XInterface
>& xIf
)
406 verifyInput( rArg0
, pStr
, xIf
, 0 );
407 verifyInput( rArg1
, pStr
, xIf
, 1 );
408 verifyInput( rArg2
, pStr
, xIf
, 2 );
411 template< typename Arg0
,
414 typename Arg3
> void verifyArgs( const Arg0
& rArg0
,
419 const css::uno::Reference
< css::uno::XInterface
>& xIf
)
421 verifyInput( rArg0
, pStr
, xIf
, 0 );
422 verifyInput( rArg1
, pStr
, xIf
, 1 );
423 verifyInput( rArg2
, pStr
, xIf
, 2 );
424 verifyInput( rArg3
, pStr
, xIf
, 3 );
427 template< typename Arg0
,
431 typename Arg4
> void verifyArgs( const Arg0
& rArg0
,
437 const css::uno::Reference
< css::uno::XInterface
>& xIf
)
439 verifyInput( rArg0
, pStr
, xIf
, 0 );
440 verifyInput( rArg1
, pStr
, xIf
, 1 );
441 verifyInput( rArg2
, pStr
, xIf
, 2 );
442 verifyInput( rArg3
, pStr
, xIf
, 3 );
443 verifyInput( rArg4
, pStr
, xIf
, 4 );
446 template< typename Arg0
,
451 typename Arg5
> void verifyArgs( const Arg0
& rArg0
,
458 const css::uno::Reference
< css::uno::XInterface
>& xIf
)
460 verifyInput( rArg0
, pStr
, xIf
, 0 );
461 verifyInput( rArg1
, pStr
, xIf
, 1 );
462 verifyInput( rArg2
, pStr
, xIf
, 2 );
463 verifyInput( rArg3
, pStr
, xIf
, 3 );
464 verifyInput( rArg4
, pStr
, xIf
, 4 );
465 verifyInput( rArg5
, pStr
, xIf
, 5 );
468 template< typename Arg0
,
474 typename Arg6
> void verifyArgs( const Arg0
& rArg0
,
482 const css::uno::Reference
< css::uno::XInterface
>& xIf
)
484 verifyInput( rArg0
, pStr
, xIf
, 0 );
485 verifyInput( rArg1
, pStr
, xIf
, 1 );
486 verifyInput( rArg2
, pStr
, xIf
, 2 );
487 verifyInput( rArg3
, pStr
, xIf
, 3 );
488 verifyInput( rArg4
, pStr
, xIf
, 4 );
489 verifyInput( rArg5
, pStr
, xIf
, 5 );
490 verifyInput( rArg6
, pStr
, xIf
, 6 );
494 /** Range checker, which throws css::lang::IllegalArgument exception, when
497 template< typename NumType
> inline void verifyRange( NumType arg
, NumType lowerBound
, NumType upperBound
)
499 if( arg
< lowerBound
||
502 throw css::lang::IllegalArgumentException();
506 /** Range checker, which throws css::lang::IllegalArgument exception, when
509 The checked range is half open, i.e. only bound by the specified value.
515 Bound to check against
518 When true, given bound is the lower bound. When false,
519 given bound is the upper bound.
521 template< typename NumType
> inline void verifyRange( NumType arg
, NumType bound
, bool bLowerBound
=true )
523 if( (bLowerBound
&& arg
< bound
) ||
524 (!bLowerBound
&& arg
> bound
) )
526 throw css::lang::IllegalArgumentException();
530 /** Range checker, which throws css::lang::IndexOutOfBounds exception, when
531 index range is violated
537 Given rectangle must be within ((0,0), (size.Width, size.Height))
539 CANVASTOOLS_DLLPUBLIC
void verifyIndexRange( const css::geometry::IntegerRectangle2D
& rect
,
540 const css::geometry::IntegerSize2D
& size
);
542 /** Range checker, which throws css::lang::IndexOutOfBounds exception, when
543 index range is violated
549 Given position must be within ((0,0), (size.Width, size.Height))
551 CANVASTOOLS_DLLPUBLIC
void verifyIndexRange( const css::geometry::IntegerPoint2D
& pos
,
552 const css::geometry::IntegerSize2D
& size
);
554 /** Range checker, which throws css::lang::IndexOutOfBounds exception, when
555 the size is negative or null
560 CANVASTOOLS_DLLPUBLIC
void verifyBitmapSize( const css::geometry::IntegerSize2D
& size
,
562 const css::uno::Reference
< css::uno::XInterface
>& xIf
);
564 /** Range checker, which throws css::lang::IndexOutOfBounds exception, when
565 the size is negative or null
570 CANVASTOOLS_DLLPUBLIC
void verifySpriteSize( const css::geometry::RealSize2D
& size
,
572 const css::uno::Reference
< css::uno::XInterface
>& xIf
);
576 #endif /* INCLUDED_CANVAS_VERIFYINPUT_HXX */
578 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */