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
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 rectangle contains valid floating
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::RealRectangle2D
& rRect
,
184 const ::com::sun::star::uno::Reference
<
185 ::com::sun::star::uno::XInterface
>& xIf
,
186 ::sal_Int16 nArgPos
);
188 /** Basic check for view state validity.
194 The interface that should be reported as the one
195 generating the exception.
198 Argument position on the call site (i.e. the position of
199 the argument, checked here, on the UNO interface
200 method. Counting starts at 0).
202 @throws an lang::IllegalArgumentException, if anything is wrong
204 CANVASTOOLS_DLLPUBLIC
void verifyInput( const ::com::sun::star::rendering::ViewState
& viewState
,
206 const ::com::sun::star::uno::Reference
<
207 ::com::sun::star::uno::XInterface
>& xIf
,
208 ::sal_Int16 nArgPos
);
210 /** Basic check for render state validity.
216 The interface that should be reported as the one
217 generating the exception.
220 Argument position on the call site (i.e. the position of
221 the argument, checked here, on the UNO interface
222 method. Counting starts at 0).
224 @param nMinColorComponents
225 Minimal number of color components available in
226 RenderState::DeviceColor
228 @throws an lang::IllegalArgumentException, if anything is wrong
230 CANVASTOOLS_DLLPUBLIC
void verifyInput( const ::com::sun::star::rendering::RenderState
& renderState
,
232 const ::com::sun::star::uno::Reference
<
233 ::com::sun::star::uno::XInterface
>& xIf
,
235 sal_Int32 nMinColorComponents
=0 );
237 /** Basic check for stroke attributes validity.
239 @param strokeAttributes
243 The interface that should be reported as the one
244 generating the exception.
247 Argument position on the call site (i.e. the position of
248 the argument, checked here, on the UNO interface
249 method. Counting starts at 0).
251 @throws an lang::IllegalArgumentException, if anything is wrong
253 CANVASTOOLS_DLLPUBLIC
void verifyInput( const ::com::sun::star::rendering::StrokeAttributes
& strokeAttributes
,
255 const ::com::sun::star::uno::Reference
<
256 ::com::sun::star::uno::XInterface
>& xIf
,
257 ::sal_Int16 nArgPos
);
259 /** Basic check for texture validity.
265 The interface that should be reported as the one
266 generating the exception.
269 Argument position on the call site (i.e. the position of
270 the argument, checked here, on the UNO interface
271 method. Counting starts at 0).
273 @throws an lang::IllegalArgumentException, if anything is wrong
275 CANVASTOOLS_DLLPUBLIC
void verifyInput( const ::com::sun::star::rendering::Texture
& texture
,
277 const ::com::sun::star::uno::Reference
<
278 ::com::sun::star::uno::XInterface
>& xIf
,
279 ::sal_Int16 nArgPos
);
281 /** Basic check for bitmap layout validity.
284 Bitmap layout to check
287 The interface that should be reported as the one
288 generating the exception.
291 Argument position on the call site (i.e. the position of
292 the argument, checked here, on the UNO interface
293 method. Counting starts at 0).
295 @throws an lang::IllegalArgumentException, if anything is wrong
297 CANVASTOOLS_DLLPUBLIC
void verifyInput( const ::com::sun::star::rendering::IntegerBitmapLayout
& bitmapLayout
,
299 const ::com::sun::star::uno::Reference
<
300 ::com::sun::star::uno::XInterface
>& xIf
,
301 ::sal_Int16 nArgPos
);
303 /** Basic check for font info validity.
309 The interface that should be reported as the one
310 generating the exception.
313 Argument position on the call site (i.e. the position of
314 the argument, checked here, on the UNO interface
315 method. Counting starts at 0).
317 @throws an lang::IllegalArgumentException, if anything is wrong
319 CANVASTOOLS_DLLPUBLIC
void verifyInput( const ::com::sun::star::rendering::FontInfo
& fontInfo
,
321 const ::com::sun::star::uno::Reference
<
322 ::com::sun::star::uno::XInterface
>& xIf
,
323 ::sal_Int16 nArgPos
);
325 /** Basic check for font request validity.
328 Font request to check
331 The interface that should be reported as the one
332 generating the exception.
335 Argument position on the call site (i.e. the position of
336 the argument, checked here, on the UNO interface
337 method. Counting starts at 0).
339 @throws an lang::IllegalArgumentException, if anything is wrong
341 CANVASTOOLS_DLLPUBLIC
void verifyInput( const ::com::sun::star::rendering::FontRequest
& fontRequest
,
343 const ::com::sun::star::uno::Reference
<
344 ::com::sun::star::uno::XInterface
>& xIf
,
345 ::sal_Int16 nArgPos
);
347 /** Templatized check for uno::Reference validity.
350 Reference to check against non-NILness
353 The interface that should be reported as the one
354 generating the exception.
357 Argument position on the call site (i.e. the position of
358 the argument, checked here, on the UNO interface
359 method. Counting starts at 0).
361 @throws an lang::IllegalArgumentException, if anything is wrong
363 template< class Interface
> void verifyInput(
364 const ::com::sun::star::uno::Reference
< Interface
>& rRef
,
366 const ::com::sun::star::uno::Reference
<
367 ::com::sun::star::uno::XInterface
>& xIf
,
368 ::sal_Int16 nArgPos
)
370 (void)pStr
; (void)xIf
; (void)nArgPos
;
374 #if OSL_DEBUG_LEVEL > 0
375 throw ::com::sun::star::lang::IllegalArgumentException(
376 OUString::createFromAscii(pStr
) + ": reference is NULL",
380 throw ::com::sun::star::lang::IllegalArgumentException();
385 /** Templatized check for content-of-sequence validity.
388 Sequence of things to check
391 The interface that should be reported as the one
392 generating the exception.
395 Argument position on the call site (i.e. the position of
396 the argument, checked here, on the UNO interface
397 method. Counting starts at 0).
399 @throws an lang::IllegalArgumentException, if anything is wrong
401 template< typename SequenceContent
> void verifyInput(
402 const ::com::sun::star::uno::Sequence
< SequenceContent
>& rSequence
,
404 const ::com::sun::star::uno::Reference
<
405 ::com::sun::star::uno::XInterface
>& xIf
,
406 ::sal_Int16 nArgPos
)
408 const SequenceContent
* pCurr
= rSequence
.getConstArray();
409 const SequenceContent
* pEnd
= pCurr
+ rSequence
.getLength();
410 while( pCurr
!= pEnd
)
411 verifyInput( *pCurr
++, pStr
, xIf
, nArgPos
);
414 /// Catch-all, to handle cases that DON'T need input checking (i.e. the Integer geometry ones)
415 template< typename T
> void verifyInput( const T
& /*rDummy*/,
416 const char* /*pStr*/,
417 const ::com::sun::star::uno::Reference
<
418 ::com::sun::star::uno::XInterface
>& /*xIf*/,
419 ::sal_Int16
/*nArgPos*/ )
423 // TODO(Q2): Employ some template arglist magic here, to avoid
424 // this duplication of code...
426 template< typename Arg0
> void verifyArgs( const Arg0
& rArg0
,
428 const ::com::sun::star::uno::Reference
<
429 ::com::sun::star::uno::XInterface
>& xIf
)
431 verifyInput( rArg0
, pStr
, xIf
, 0 );
434 template< typename Arg0
,
435 typename Arg1
> void verifyArgs( const Arg0
& rArg0
,
438 const ::com::sun::star::uno::Reference
<
439 ::com::sun::star::uno::XInterface
>& xIf
)
441 verifyInput( rArg0
, pStr
, xIf
, 0 );
442 verifyInput( rArg1
, pStr
, xIf
, 1 );
445 template< typename Arg0
,
447 typename Arg2
> 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 );
455 verifyInput( rArg1
, pStr
, xIf
, 1 );
456 verifyInput( rArg2
, pStr
, xIf
, 2 );
459 template< typename Arg0
,
462 typename Arg3
> void verifyArgs( const Arg0
& rArg0
,
467 const ::com::sun::star::uno::Reference
<
468 ::com::sun::star::uno::XInterface
>& xIf
)
470 verifyInput( rArg0
, pStr
, xIf
, 0 );
471 verifyInput( rArg1
, pStr
, xIf
, 1 );
472 verifyInput( rArg2
, pStr
, xIf
, 2 );
473 verifyInput( rArg3
, pStr
, xIf
, 3 );
476 template< typename Arg0
,
480 typename Arg4
> void verifyArgs( const Arg0
& rArg0
,
486 const ::com::sun::star::uno::Reference
<
487 ::com::sun::star::uno::XInterface
>& xIf
)
489 verifyInput( rArg0
, pStr
, xIf
, 0 );
490 verifyInput( rArg1
, pStr
, xIf
, 1 );
491 verifyInput( rArg2
, pStr
, xIf
, 2 );
492 verifyInput( rArg3
, pStr
, xIf
, 3 );
493 verifyInput( rArg4
, pStr
, xIf
, 4 );
496 template< typename Arg0
,
501 typename Arg5
> void verifyArgs( const Arg0
& rArg0
,
508 const ::com::sun::star::uno::Reference
<
509 ::com::sun::star::uno::XInterface
>& xIf
)
511 verifyInput( rArg0
, pStr
, xIf
, 0 );
512 verifyInput( rArg1
, pStr
, xIf
, 1 );
513 verifyInput( rArg2
, pStr
, xIf
, 2 );
514 verifyInput( rArg3
, pStr
, xIf
, 3 );
515 verifyInput( rArg4
, pStr
, xIf
, 4 );
516 verifyInput( rArg5
, pStr
, xIf
, 5 );
519 template< typename Arg0
,
525 typename Arg6
> void verifyArgs( const Arg0
& rArg0
,
533 const ::com::sun::star::uno::Reference
<
534 ::com::sun::star::uno::XInterface
>& xIf
)
536 verifyInput( rArg0
, pStr
, xIf
, 0 );
537 verifyInput( rArg1
, pStr
, xIf
, 1 );
538 verifyInput( rArg2
, pStr
, xIf
, 2 );
539 verifyInput( rArg3
, pStr
, xIf
, 3 );
540 verifyInput( rArg4
, pStr
, xIf
, 4 );
541 verifyInput( rArg5
, pStr
, xIf
, 5 );
542 verifyInput( rArg6
, pStr
, xIf
, 6 );
546 /** Range checker, which throws ::com::sun::star::lang::IllegalArgument exception, when
549 template< typename NumType
> inline void verifyRange( NumType arg
, NumType lowerBound
, NumType upperBound
)
551 if( arg
< lowerBound
||
554 throw ::com::sun::star::lang::IllegalArgumentException();
558 /** Range checker, which throws ::com::sun::star::lang::IllegalArgument exception, when
561 The checked range is half open, i.e. only bound by the specified value.
567 Bound to check against
570 When true, given bound is the lower bound. When false,
571 given bound is the upper bound.
573 template< typename NumType
> inline void verifyRange( NumType arg
, NumType bound
, bool bLowerBound
=true )
575 if( (bLowerBound
&& arg
< bound
) ||
576 (!bLowerBound
&& arg
> bound
) )
578 throw ::com::sun::star::lang::IllegalArgumentException();
582 /** Range checker, which throws ::com::sun::star::lang::IndexOutOfBounds exception, when
583 index range is violated
585 template< typename NumType
> inline void verifyIndexRange( NumType arg
, NumType lowerBound
, NumType upperBound
)
587 if( arg
< lowerBound
||
590 throw ::com::sun::star::lang::IndexOutOfBoundsException();
594 /** Range checker, which throws ::com::sun::star::lang::IndexOutOfBounds exception, when
595 index range is violated
601 Given rectangle must be within ((0,0), (size.Width, size.Height))
603 CANVASTOOLS_DLLPUBLIC
void verifyIndexRange( const ::com::sun::star::geometry::IntegerRectangle2D
& rect
,
604 const ::com::sun::star::geometry::IntegerSize2D
& size
);
606 /** Range checker, which throws ::com::sun::star::lang::IndexOutOfBounds exception, when
607 index range is violated
613 Given position must be within ((0,0), (size.Width, size.Height))
615 CANVASTOOLS_DLLPUBLIC
void verifyIndexRange( const ::com::sun::star::geometry::IntegerPoint2D
& pos
,
616 const ::com::sun::star::geometry::IntegerSize2D
& size
);
618 /** Range checker, which throws ::com::sun::star::lang::IndexOutOfBounds exception, when
619 the size is negative or null
624 CANVASTOOLS_DLLPUBLIC
void verifyBitmapSize( const ::com::sun::star::geometry::IntegerSize2D
& size
,
626 const ::com::sun::star::uno::Reference
<
627 ::com::sun::star::uno::XInterface
>& xIf
);
629 /** Range checker, which throws ::com::sun::star::lang::IndexOutOfBounds exception, when
630 the size is negative or null
635 CANVASTOOLS_DLLPUBLIC
void verifySpriteSize( const ::com::sun::star::geometry::RealSize2D
& size
,
637 const ::com::sun::star::uno::Reference
<
638 ::com::sun::star::uno::XInterface
>& xIf
);
642 #endif /* INCLUDED_CANVAS_VERIFYINPUT_HXX */
644 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */