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/uno/Sequence.hxx>
25 #include <com/sun/star/uno/RuntimeException.hpp>
26 #include <com/sun/star/lang/IllegalArgumentException.hpp>
27 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
30 #include <boost/bind.hpp>
31 #include <boost/current_function.hpp>
33 #include <canvas/canvastoolsdllapi.h>
35 namespace com
{ namespace sun
{ namespace star
{ namespace geometry
39 struct RealBezierSegment2D
;
40 struct RealRectangle2D
;
41 struct AffineMatrix2D
;
43 struct IntegerPoint2D
;
45 struct IntegerRectangle2D
;
48 namespace com
{ namespace sun
{ namespace star
{ namespace rendering
51 struct StrokeAttributes
;
54 struct IntegerBitmapLayout
;
66 // Input checking facilities
67 // ===================================================================
69 // This header provides methods to check all common
70 // css::rendering::* method input parameters against
71 // compliance to the API specification.
73 /** Verify that the given transformation contains valid floating point
80 The interface that should be reported as the one
81 generating the exception.
84 Argument position on the call site (i.e. the position of
85 the argument, checked here, on the UNO interface
86 method. Counting starts at 0).
88 @throws an lang::IllegalArgumentException, if anything is wrong
90 CANVASTOOLS_DLLPUBLIC
void verifyInput( const ::com::sun::star::geometry::AffineMatrix2D
& rMatrix
,
92 const ::com::sun::star::uno::Reference
<
93 ::com::sun::star::uno::XInterface
>& xIf
,
94 ::sal_Int16 nArgPos
);
96 /** Verify that the given transformation contains valid floating point
103 The interface that should be reported as the one
104 generating the exception.
107 Argument position on the call site (i.e. the position of
108 the argument, checked here, on the UNO interface
109 method. Counting starts at 0).
111 @throws an lang::IllegalArgumentException, if anything is wrong
113 CANVASTOOLS_DLLPUBLIC
void verifyInput( const ::com::sun::star::geometry::Matrix2D
& rMatrix
,
115 const ::com::sun::star::uno::Reference
<
116 ::com::sun::star::uno::XInterface
>& xIf
,
117 ::sal_Int16 nArgPos
);
119 /** Verify that the given point contains valid floating point
126 The interface that should be reported as the one
127 generating the exception.
130 Argument position on the call site (i.e. the position of
131 the argument, checked here, on the UNO interface
132 method. Counting starts at 0).
134 @throws an lang::IllegalArgumentException, if anything is wrong
136 CANVASTOOLS_DLLPUBLIC
void verifyInput( const ::com::sun::star::geometry::RealPoint2D
& rPoint
,
138 const ::com::sun::star::uno::Reference
<
139 ::com::sun::star::uno::XInterface
>& xIf
,
140 ::sal_Int16 nArgPos
);
142 /** Verify that the given bezier segment contains valid
143 floating point values.
149 The interface that should be reported as the one
150 generating the exception.
153 Argument position on the call site (i.e. the position of
154 the argument, checked here, on the UNO interface
155 method. Counting starts at 0).
157 @throws an lang::IllegalArgumentException, if anything is wrong
159 CANVASTOOLS_DLLPUBLIC
void verifyInput( const ::com::sun::star::geometry::RealBezierSegment2D
& rSegment
,
161 const ::com::sun::star::uno::Reference
<
162 ::com::sun::star::uno::XInterface
>& xIf
,
163 ::sal_Int16 nArgPos
);
165 /** Verify that the given point contains valid floating point
172 The interface that should be reported as the one
173 generating the exception.
176 Argument position on the call site (i.e. the position of
177 the argument, checked here, on the UNO interface
178 method. Counting starts at 0).
180 @throws an lang::IllegalArgumentException, if anything is wrong
182 CANVASTOOLS_DLLPUBLIC
void verifyInput( const ::com::sun::star::geometry::RealPoint2D
& rPoint
,
184 const ::com::sun::star::uno::Reference
<
185 ::com::sun::star::uno::XInterface
>& xIf
,
186 ::sal_Int16 nArgPos
);
188 /** Verify that the given rectangle contains valid floating
195 The interface that should be reported as the one
196 generating the exception.
199 Argument position on the call site (i.e. the position of
200 the argument, checked here, on the UNO interface
201 method. Counting starts at 0).
203 @throws an lang::IllegalArgumentException, if anything is wrong
205 CANVASTOOLS_DLLPUBLIC
void verifyInput( const ::com::sun::star::geometry::RealRectangle2D
& rRect
,
207 const ::com::sun::star::uno::Reference
<
208 ::com::sun::star::uno::XInterface
>& xIf
,
209 ::sal_Int16 nArgPos
);
211 /** Basic check for view state validity.
217 The interface that should be reported as the one
218 generating the exception.
221 Argument position on the call site (i.e. the position of
222 the argument, checked here, on the UNO interface
223 method. Counting starts at 0).
225 @throws an lang::IllegalArgumentException, if anything is wrong
227 CANVASTOOLS_DLLPUBLIC
void verifyInput( const ::com::sun::star::rendering::ViewState
& viewState
,
229 const ::com::sun::star::uno::Reference
<
230 ::com::sun::star::uno::XInterface
>& xIf
,
231 ::sal_Int16 nArgPos
);
233 /** Basic check for render state validity.
239 The interface that should be reported as the one
240 generating the exception.
243 Argument position on the call site (i.e. the position of
244 the argument, checked here, on the UNO interface
245 method. Counting starts at 0).
247 @param nMinColorComponents
248 Minimal number of color components available in
249 RenderState::DeviceColor
251 @throws an lang::IllegalArgumentException, if anything is wrong
253 CANVASTOOLS_DLLPUBLIC
void verifyInput( const ::com::sun::star::rendering::RenderState
& renderState
,
255 const ::com::sun::star::uno::Reference
<
256 ::com::sun::star::uno::XInterface
>& xIf
,
258 sal_Int32 nMinColorComponents
=0 );
260 /** Basic check for stroke attributes validity.
262 @param strokeAttributes
266 The interface that should be reported as the one
267 generating the exception.
270 Argument position on the call site (i.e. the position of
271 the argument, checked here, on the UNO interface
272 method. Counting starts at 0).
274 @throws an lang::IllegalArgumentException, if anything is wrong
276 CANVASTOOLS_DLLPUBLIC
void verifyInput( const ::com::sun::star::rendering::StrokeAttributes
& strokeAttributes
,
278 const ::com::sun::star::uno::Reference
<
279 ::com::sun::star::uno::XInterface
>& xIf
,
280 ::sal_Int16 nArgPos
);
282 /** Basic check for texture validity.
288 The interface that should be reported as the one
289 generating the exception.
292 Argument position on the call site (i.e. the position of
293 the argument, checked here, on the UNO interface
294 method. Counting starts at 0).
296 @throws an lang::IllegalArgumentException, if anything is wrong
298 CANVASTOOLS_DLLPUBLIC
void verifyInput( const ::com::sun::star::rendering::Texture
& texture
,
300 const ::com::sun::star::uno::Reference
<
301 ::com::sun::star::uno::XInterface
>& xIf
,
302 ::sal_Int16 nArgPos
);
304 /** Basic check for bitmap layout validity.
307 Bitmap layout to check
310 The interface that should be reported as the one
311 generating the exception.
314 Argument position on the call site (i.e. the position of
315 the argument, checked here, on the UNO interface
316 method. Counting starts at 0).
318 @throws an lang::IllegalArgumentException, if anything is wrong
320 CANVASTOOLS_DLLPUBLIC
void verifyInput( const ::com::sun::star::rendering::IntegerBitmapLayout
& bitmapLayout
,
322 const ::com::sun::star::uno::Reference
<
323 ::com::sun::star::uno::XInterface
>& xIf
,
324 ::sal_Int16 nArgPos
);
326 /** Basic check for font info validity.
332 The interface that should be reported as the one
333 generating the exception.
336 Argument position on the call site (i.e. the position of
337 the argument, checked here, on the UNO interface
338 method. Counting starts at 0).
340 @throws an lang::IllegalArgumentException, if anything is wrong
342 CANVASTOOLS_DLLPUBLIC
void verifyInput( const ::com::sun::star::rendering::FontInfo
& fontInfo
,
344 const ::com::sun::star::uno::Reference
<
345 ::com::sun::star::uno::XInterface
>& xIf
,
346 ::sal_Int16 nArgPos
);
348 /** Basic check for font request validity.
351 Font request to check
354 The interface that should be reported as the one
355 generating the exception.
358 Argument position on the call site (i.e. the position of
359 the argument, checked here, on the UNO interface
360 method. Counting starts at 0).
362 @throws an lang::IllegalArgumentException, if anything is wrong
364 CANVASTOOLS_DLLPUBLIC
void verifyInput( const ::com::sun::star::rendering::FontRequest
& fontRequest
,
366 const ::com::sun::star::uno::Reference
<
367 ::com::sun::star::uno::XInterface
>& xIf
,
368 ::sal_Int16 nArgPos
);
370 /** Templatized check for uno::Reference validity.
373 Reference to check against non-NILness
376 The interface that should be reported as the one
377 generating the exception.
380 Argument position on the call site (i.e. the position of
381 the argument, checked here, on the UNO interface
382 method. Counting starts at 0).
384 @throws an lang::IllegalArgumentException, if anything is wrong
386 template< class Interface
> void verifyInput(
387 const ::com::sun::star::uno::Reference
< Interface
>& rRef
,
389 const ::com::sun::star::uno::Reference
<
390 ::com::sun::star::uno::XInterface
>& xIf
,
391 ::sal_Int16 nArgPos
)
393 (void)pStr
; (void)xIf
; (void)nArgPos
;
397 #if OSL_DEBUG_LEVEL > 0
398 throw ::com::sun::star::lang::IllegalArgumentException(
399 OUString::createFromAscii(pStr
) + ": reference is NULL",
403 throw ::com::sun::star::lang::IllegalArgumentException();
408 /** Templatized check for content-of-sequence validity.
411 Sequence of things to check
414 The interface that should be reported as the one
415 generating the exception.
418 Argument position on the call site (i.e. the position of
419 the argument, checked here, on the UNO interface
420 method. Counting starts at 0).
422 @throws an lang::IllegalArgumentException, if anything is wrong
424 template< typename SequenceContent
> void verifyInput(
425 const ::com::sun::star::uno::Sequence
< SequenceContent
>& rSequence
,
427 const ::com::sun::star::uno::Reference
<
428 ::com::sun::star::uno::XInterface
>& xIf
,
429 ::sal_Int16 nArgPos
)
431 const SequenceContent
* pCurr
= rSequence
.getConstArray();
432 const SequenceContent
* pEnd
= pCurr
+ rSequence
.getLength();
433 while( pCurr
!= pEnd
)
434 verifyInput( *pCurr
++, pStr
, xIf
, nArgPos
);
437 /// Catch-all, to handle cases that DON'T need input checking (i.e. the Integer geometry ones)
438 template< typename T
> void verifyInput( const T
& /*rDummy*/,
439 const char* /*pStr*/,
440 const ::com::sun::star::uno::Reference
<
441 ::com::sun::star::uno::XInterface
>& /*xIf*/,
442 ::sal_Int16
/*nArgPos*/ )
446 // TODO(Q2): Employ some template arglist magic here, to avoid
447 // this duplication of code...
449 template< typename Arg0
> void verifyArgs( const Arg0
& rArg0
,
451 const ::com::sun::star::uno::Reference
<
452 ::com::sun::star::uno::XInterface
>& xIf
)
454 verifyInput( rArg0
, pStr
, xIf
, 0 );
457 template< typename Arg0
,
458 typename Arg1
> void verifyArgs( const Arg0
& rArg0
,
461 const ::com::sun::star::uno::Reference
<
462 ::com::sun::star::uno::XInterface
>& xIf
)
464 verifyInput( rArg0
, pStr
, xIf
, 0 );
465 verifyInput( rArg1
, pStr
, xIf
, 1 );
468 template< typename Arg0
,
470 typename Arg2
> void verifyArgs( const Arg0
& rArg0
,
474 const ::com::sun::star::uno::Reference
<
475 ::com::sun::star::uno::XInterface
>& xIf
)
477 verifyInput( rArg0
, pStr
, xIf
, 0 );
478 verifyInput( rArg1
, pStr
, xIf
, 1 );
479 verifyInput( rArg2
, pStr
, xIf
, 2 );
482 template< typename Arg0
,
485 typename Arg3
> void verifyArgs( const Arg0
& rArg0
,
490 const ::com::sun::star::uno::Reference
<
491 ::com::sun::star::uno::XInterface
>& xIf
)
493 verifyInput( rArg0
, pStr
, xIf
, 0 );
494 verifyInput( rArg1
, pStr
, xIf
, 1 );
495 verifyInput( rArg2
, pStr
, xIf
, 2 );
496 verifyInput( rArg3
, pStr
, xIf
, 3 );
499 template< typename Arg0
,
503 typename Arg4
> void verifyArgs( const Arg0
& rArg0
,
509 const ::com::sun::star::uno::Reference
<
510 ::com::sun::star::uno::XInterface
>& xIf
)
512 verifyInput( rArg0
, pStr
, xIf
, 0 );
513 verifyInput( rArg1
, pStr
, xIf
, 1 );
514 verifyInput( rArg2
, pStr
, xIf
, 2 );
515 verifyInput( rArg3
, pStr
, xIf
, 3 );
516 verifyInput( rArg4
, pStr
, xIf
, 4 );
519 template< typename Arg0
,
524 typename Arg5
> void verifyArgs( const Arg0
& rArg0
,
531 const ::com::sun::star::uno::Reference
<
532 ::com::sun::star::uno::XInterface
>& xIf
)
534 verifyInput( rArg0
, pStr
, xIf
, 0 );
535 verifyInput( rArg1
, pStr
, xIf
, 1 );
536 verifyInput( rArg2
, pStr
, xIf
, 2 );
537 verifyInput( rArg3
, pStr
, xIf
, 3 );
538 verifyInput( rArg4
, pStr
, xIf
, 4 );
539 verifyInput( rArg5
, pStr
, xIf
, 5 );
542 template< typename Arg0
,
548 typename Arg6
> void verifyArgs( const Arg0
& rArg0
,
556 const ::com::sun::star::uno::Reference
<
557 ::com::sun::star::uno::XInterface
>& xIf
)
559 verifyInput( rArg0
, pStr
, xIf
, 0 );
560 verifyInput( rArg1
, pStr
, xIf
, 1 );
561 verifyInput( rArg2
, pStr
, xIf
, 2 );
562 verifyInput( rArg3
, pStr
, xIf
, 3 );
563 verifyInput( rArg4
, pStr
, xIf
, 4 );
564 verifyInput( rArg5
, pStr
, xIf
, 5 );
565 verifyInput( rArg6
, pStr
, xIf
, 6 );
569 /** Range checker, which throws ::com::sun::star::lang::IllegalArgument exception, when
572 template< typename NumType
> inline void verifyRange( NumType arg
, NumType lowerBound
, NumType upperBound
)
574 if( arg
< lowerBound
||
577 throw ::com::sun::star::lang::IllegalArgumentException();
581 /** Range checker, which throws ::com::sun::star::lang::IllegalArgument exception, when
584 The checked range is half open, i.e. only bound by the specified value.
590 Bound to check against
593 When true, given bound is the lower bound. When false,
594 given bound is the upper bound.
596 template< typename NumType
> inline void verifyRange( NumType arg
, NumType bound
, bool bLowerBound
=true )
598 if( (bLowerBound
&& arg
< bound
) ||
599 (!bLowerBound
&& arg
> bound
) )
601 throw ::com::sun::star::lang::IllegalArgumentException();
605 /** Range checker, which throws ::com::sun::star::lang::IndexOutOfBounds exception, when
606 index range is violated
608 template< typename NumType
> inline void verifyIndexRange( NumType arg
, NumType lowerBound
, NumType upperBound
)
610 if( arg
< lowerBound
||
613 throw ::com::sun::star::lang::IndexOutOfBoundsException();
617 /** Range checker, which throws ::com::sun::star::lang::IndexOutOfBounds exception, when
618 index range is violated
624 Given rectangle must be within ((0,0), (size.Width, size.Height))
626 CANVASTOOLS_DLLPUBLIC
void verifyIndexRange( const ::com::sun::star::geometry::IntegerRectangle2D
& rect
,
627 const ::com::sun::star::geometry::IntegerSize2D
& size
);
629 /** Range checker, which throws ::com::sun::star::lang::IndexOutOfBounds exception, when
630 index range is violated
636 Given position must be within ((0,0), (size.Width, size.Height))
638 CANVASTOOLS_DLLPUBLIC
void verifyIndexRange( const ::com::sun::star::geometry::IntegerPoint2D
& pos
,
639 const ::com::sun::star::geometry::IntegerSize2D
& size
);
641 /** Range checker, which throws ::com::sun::star::lang::IndexOutOfBounds exception, when
642 the size is negative or null
647 CANVASTOOLS_DLLPUBLIC
void verifyBitmapSize( const ::com::sun::star::geometry::IntegerSize2D
& size
,
649 const ::com::sun::star::uno::Reference
<
650 ::com::sun::star::uno::XInterface
>& xIf
);
652 /** Range checker, which throws ::com::sun::star::lang::IndexOutOfBounds exception, when
653 the size is negative or null
658 CANVASTOOLS_DLLPUBLIC
void verifySpriteSize( const ::com::sun::star::geometry::RealSize2D
& size
,
660 const ::com::sun::star::uno::Reference
<
661 ::com::sun::star::uno::XInterface
>& xIf
);
665 #endif /* INCLUDED_CANVAS_VERIFYINPUT_HXX */
667 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */