Bump version to 21.06.18.1
[LibreOffice.git] / canvas / inc / verifyinput.hxx
blobb37468ebbe24642591b9abe2d4b52871b7dcacd0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
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
29 struct RealPoint2D;
30 struct RealSize2D;
31 struct RealBezierSegment2D;
32 struct RealRectangle2D;
33 struct AffineMatrix2D;
34 struct Matrix2D;
35 struct IntegerPoint2D;
36 struct IntegerSize2D;
37 struct IntegerRectangle2D;
40 namespace com::sun::star::rendering
42 struct RenderState;
43 struct StrokeAttributes;
44 struct Texture;
45 struct ViewState;
46 struct IntegerBitmapLayout;
47 struct FontRequest;
50 namespace com::sun::star::uno { template <class E> class Sequence; }
52 namespace canvas
54 namespace tools
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
65 values.
67 @param rMatrix
68 Matrix to check
70 @param xIf
71 The interface that should be reported as the one
72 generating the exception.
74 @param nArgPos
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,
82 const char* pStr,
83 const css::uno::Reference< css::uno::XInterface >& xIf,
84 ::sal_Int16 nArgPos );
86 /** Verify that the given transformation contains valid floating point
87 values.
89 @param rMatrix
90 Matrix to check
92 @param xIf
93 The interface that should be reported as the one
94 generating the exception.
96 @param nArgPos
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,
104 const char* pStr,
105 const css::uno::Reference< css::uno::XInterface >& xIf,
106 ::sal_Int16 nArgPos );
108 /** Verify that the given point contains valid floating point
109 values.
111 @param rPoint
112 Point to check
114 @param xIf
115 The interface that should be reported as the one
116 generating the exception.
118 @param nArgPos
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,
126 const char* pStr,
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.
133 @param rSegment
134 Segment to check
136 @param xIf
137 The interface that should be reported as the one
138 generating the exception.
140 @param nArgPos
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,
148 const char* pStr,
149 const css::uno::Reference< css::uno::XInterface >& xIf,
150 ::sal_Int16 nArgPos );
152 /** Verify that the given rectangle contains valid floating
153 point values.
155 @param rRect
156 Rect to check
158 @param xIf
159 The interface that should be reported as the one
160 generating the exception.
162 @param nArgPos
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,
170 const char* pStr,
171 const css::uno::Reference< css::uno::XInterface >& xIf,
172 ::sal_Int16 nArgPos );
174 /** Basic check for view state validity.
176 @param viewState
177 Viewstate to check
179 @param xIf
180 The interface that should be reported as the one
181 generating the exception.
183 @param nArgPos
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,
191 const char* pStr,
192 const css::uno::Reference< css::uno::XInterface >& xIf,
193 ::sal_Int16 nArgPos );
195 /** Basic check for render state validity.
197 @param renderState
198 Renderstate to check
200 @param xIf
201 The interface that should be reported as the one
202 generating the exception.
204 @param nArgPos
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,
216 const char* pStr,
217 const css::uno::Reference< css::uno::XInterface >& xIf,
218 ::sal_Int16 nArgPos,
219 sal_Int32 nMinColorComponents=0 );
221 /** Basic check for stroke attributes validity.
223 @param strokeAttributes
224 Attributes to check
226 @param xIf
227 The interface that should be reported as the one
228 generating the exception.
230 @param nArgPos
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,
238 const char* pStr,
239 const css::uno::Reference< css::uno::XInterface >& xIf,
240 ::sal_Int16 nArgPos );
242 /** Basic check for texture validity.
244 @param texture
245 Texture to check
247 @param xIf
248 The interface that should be reported as the one
249 generating the exception.
251 @param nArgPos
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,
259 const char* pStr,
260 const css::uno::Reference< css::uno::XInterface >& xIf,
261 ::sal_Int16 nArgPos );
263 /** Basic check for bitmap layout validity.
265 @param bitmapLayout
266 Bitmap layout to check
268 @param xIf
269 The interface that should be reported as the one
270 generating the exception.
272 @param nArgPos
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,
280 const char* pStr,
281 const css::uno::Reference< css::uno::XInterface >& xIf,
282 ::sal_Int16 nArgPos );
284 /** Basic check for font request validity.
286 @param fontRequest
287 Font request to check
289 @param xIf
290 The interface that should be reported as the one
291 generating the exception.
293 @param nArgPos
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,
301 const char* pStr,
302 const css::uno::Reference< css::uno::XInterface >& xIf,
303 ::sal_Int16 nArgPos );
305 /** Templatized check for uno::Reference validity.
307 @param rRef
308 Reference to check against non-NILness
310 @param xIf
311 The interface that should be reported as the one
312 generating the exception.
314 @param nArgPos
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,
323 const char* pStr,
324 const css::uno::Reference< css::uno::XInterface >& xIf,
325 ::sal_Int16 nArgPos )
327 if( !rRef.is() )
329 #if OSL_DEBUG_LEVEL > 0
330 throw css::lang::IllegalArgumentException(
331 OUString::createFromAscii(pStr) + ": reference is NULL",
332 xIf,
333 nArgPos );
334 #else
335 (void)pStr; (void)xIf; (void)nArgPos;
336 throw css::lang::IllegalArgumentException();
337 #endif
341 /** Templatized check for content-of-sequence validity.
343 @param rSequence
344 Sequence of things to check
346 @param xIf
347 The interface that should be reported as the one
348 generating the exception.
350 @param nArgPos
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,
359 const char* pStr,
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,
381 const char* pStr,
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,
389 const Arg1& rArg1,
390 const char* pStr,
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,
398 typename Arg1,
399 typename Arg2 > void verifyArgs( const Arg0& rArg0,
400 const Arg1& rArg1,
401 const Arg2& rArg2,
402 const char* pStr,
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,
411 typename Arg1,
412 typename Arg2,
413 typename Arg3 > void verifyArgs( const Arg0& rArg0,
414 const Arg1& rArg1,
415 const Arg2& rArg2,
416 const Arg3& rArg3,
417 const char* pStr,
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,
427 typename Arg1,
428 typename Arg2,
429 typename Arg3,
430 typename Arg4 > void verifyArgs( const Arg0& rArg0,
431 const Arg1& rArg1,
432 const Arg2& rArg2,
433 const Arg3& rArg3,
434 const Arg4& rArg4,
435 const char* pStr,
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,
446 typename Arg1,
447 typename Arg2,
448 typename Arg3,
449 typename Arg4,
450 typename Arg5 > void verifyArgs( const Arg0& rArg0,
451 const Arg1& rArg1,
452 const Arg2& rArg2,
453 const Arg3& rArg3,
454 const Arg4& rArg4,
455 const Arg5& rArg5,
456 const char* pStr,
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,
468 typename Arg1,
469 typename Arg2,
470 typename Arg3,
471 typename Arg4,
472 typename Arg5,
473 typename Arg6 > void verifyArgs( const Arg0& rArg0,
474 const Arg1& rArg1,
475 const Arg2& rArg2,
476 const Arg3& rArg3,
477 const Arg4& rArg4,
478 const Arg5& rArg5,
479 const Arg6& rArg6,
480 const char* pStr,
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
494 range is violated
496 template< typename NumType > inline void verifyRange( NumType arg, NumType lowerBound, NumType upperBound )
498 if( arg < lowerBound ||
499 arg > upperBound )
501 throw css::lang::IllegalArgumentException();
505 /** Range checker, which throws css::lang::IllegalArgument exception, when
506 range is violated
508 The checked range is half open, i.e. only bound by the specified value.
510 @param arg
511 Arg to check
513 @param bound
514 Bound to check against
516 @param bLowerBound
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
532 @param rect
533 Rect to verify
535 @param size
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
544 @param pos
545 Position to verify
547 @param size
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
556 @param size
557 Size to verify
559 CANVASTOOLS_DLLPUBLIC void verifyBitmapSize( const css::geometry::IntegerSize2D& size,
560 const char* pStr,
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
566 @param size
567 Size to verify
569 CANVASTOOLS_DLLPUBLIC void verifySpriteSize( const css::geometry::RealSize2D& size,
570 const char* pStr,
571 const css::uno::Reference< css::uno::XInterface >& xIf );
575 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */