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 for (auto& element
: rSequence
)
364 verifyInput(element
, pStr
, xIf
, nArgPos
);
367 /// Catch-all, to handle cases that DON'T need input checking (i.e. the Integer geometry ones)
368 template< typename T
> void verifyInput( const T
& /*rDummy*/,
369 const char* /*pStr*/,
370 const css::uno::Reference
< css::uno::XInterface
>& /*xIf*/,
371 ::sal_Int16
/*nArgPos*/ )
375 // TODO(Q2): Employ some template arglist magic here, to avoid
376 // this duplication of code...
378 template< typename Arg0
> void verifyArgs( const Arg0
& rArg0
,
380 const css::uno::Reference
< css::uno::XInterface
>& xIf
)
382 verifyInput( rArg0
, pStr
, xIf
, 0 );
385 template< typename Arg0
,
386 typename Arg1
> void verifyArgs( const Arg0
& rArg0
,
389 const css::uno::Reference
< css::uno::XInterface
>& xIf
)
391 verifyInput( rArg0
, pStr
, xIf
, 0 );
392 verifyInput( rArg1
, pStr
, xIf
, 1 );
395 template< typename Arg0
,
397 typename Arg2
> void verifyArgs( const Arg0
& rArg0
,
401 const css::uno::Reference
< css::uno::XInterface
>& xIf
)
403 verifyInput( rArg0
, pStr
, xIf
, 0 );
404 verifyInput( rArg1
, pStr
, xIf
, 1 );
405 verifyInput( rArg2
, pStr
, xIf
, 2 );
408 template< typename Arg0
,
411 typename Arg3
> void verifyArgs( const Arg0
& rArg0
,
416 const css::uno::Reference
< css::uno::XInterface
>& xIf
)
418 verifyInput( rArg0
, pStr
, xIf
, 0 );
419 verifyInput( rArg1
, pStr
, xIf
, 1 );
420 verifyInput( rArg2
, pStr
, xIf
, 2 );
421 verifyInput( rArg3
, pStr
, xIf
, 3 );
424 template< typename Arg0
,
428 typename Arg4
> void verifyArgs( const Arg0
& rArg0
,
434 const css::uno::Reference
< css::uno::XInterface
>& xIf
)
436 verifyInput( rArg0
, pStr
, xIf
, 0 );
437 verifyInput( rArg1
, pStr
, xIf
, 1 );
438 verifyInput( rArg2
, pStr
, xIf
, 2 );
439 verifyInput( rArg3
, pStr
, xIf
, 3 );
440 verifyInput( rArg4
, pStr
, xIf
, 4 );
443 template< typename Arg0
,
448 typename Arg5
> void verifyArgs( const Arg0
& rArg0
,
455 const css::uno::Reference
< css::uno::XInterface
>& xIf
)
457 verifyInput( rArg0
, pStr
, xIf
, 0 );
458 verifyInput( rArg1
, pStr
, xIf
, 1 );
459 verifyInput( rArg2
, pStr
, xIf
, 2 );
460 verifyInput( rArg3
, pStr
, xIf
, 3 );
461 verifyInput( rArg4
, pStr
, xIf
, 4 );
462 verifyInput( rArg5
, pStr
, xIf
, 5 );
465 template< typename Arg0
,
471 typename Arg6
> void verifyArgs( const Arg0
& rArg0
,
479 const css::uno::Reference
< css::uno::XInterface
>& xIf
)
481 verifyInput( rArg0
, pStr
, xIf
, 0 );
482 verifyInput( rArg1
, pStr
, xIf
, 1 );
483 verifyInput( rArg2
, pStr
, xIf
, 2 );
484 verifyInput( rArg3
, pStr
, xIf
, 3 );
485 verifyInput( rArg4
, pStr
, xIf
, 4 );
486 verifyInput( rArg5
, pStr
, xIf
, 5 );
487 verifyInput( rArg6
, pStr
, xIf
, 6 );
491 /** Range checker, which throws css::lang::IllegalArgument exception, when
494 template< typename NumType
> inline void verifyRange( NumType arg
, NumType lowerBound
, NumType upperBound
)
496 if( arg
< lowerBound
||
499 throw css::lang::IllegalArgumentException();
503 /** Range checker, which throws css::lang::IllegalArgument exception, when
506 The checked range is half open, i.e. only bound by the specified value.
512 Bound to check against
515 When true, given bound is the lower bound. When false,
516 given bound is the upper bound.
518 template< typename NumType
> inline void verifyRange( NumType arg
, NumType bound
, bool bLowerBound
=true )
520 if( (bLowerBound
&& arg
< bound
) ||
521 (!bLowerBound
&& arg
> bound
) )
523 throw css::lang::IllegalArgumentException();
527 /** Range checker, which throws css::lang::IndexOutOfBounds exception, when
528 index range is violated
534 Given rectangle must be within ((0,0), (size.Width, size.Height))
536 CANVASTOOLS_DLLPUBLIC
void verifyIndexRange( const css::geometry::IntegerRectangle2D
& rect
,
537 const css::geometry::IntegerSize2D
& size
);
539 /** Range checker, which throws css::lang::IndexOutOfBounds exception, when
540 index range is violated
546 Given position must be within ((0,0), (size.Width, size.Height))
548 CANVASTOOLS_DLLPUBLIC
void verifyIndexRange( const css::geometry::IntegerPoint2D
& pos
,
549 const css::geometry::IntegerSize2D
& size
);
551 /** Range checker, which throws css::lang::IndexOutOfBounds exception, when
552 the size is negative or null
557 CANVASTOOLS_DLLPUBLIC
void verifyBitmapSize( const css::geometry::IntegerSize2D
& size
,
559 const css::uno::Reference
< css::uno::XInterface
>& xIf
);
561 /** Range checker, which throws css::lang::IndexOutOfBounds exception, when
562 the size is negative or null
567 CANVASTOOLS_DLLPUBLIC
void verifySpriteSize( const css::geometry::RealSize2D
& size
,
569 const css::uno::Reference
< css::uno::XInterface
>& xIf
);
573 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */