bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / canvas / verifyinput.hxx
blobedc7dc3c2c55782f1cf1fcd39de55f2d80414fe0
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 #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
30 struct RealPoint2D;
31 struct RealSize2D;
32 struct RealBezierSegment2D;
33 struct RealRectangle2D;
34 struct AffineMatrix2D;
35 struct Matrix2D;
36 struct IntegerPoint2D;
37 struct IntegerSize2D;
38 struct IntegerRectangle2D;
39 } } } }
41 namespace com { namespace sun { namespace star { namespace rendering
43 struct RenderState;
44 struct StrokeAttributes;
45 struct Texture;
46 struct ViewState;
47 struct IntegerBitmapLayout;
48 struct FontRequest;
49 } } } }
51 namespace com::sun::star::uno { template <class E> class Sequence; }
53 namespace canvas
55 namespace tools
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
66 values.
68 @param rMatrix
69 Matrix to check
71 @param xIf
72 The interface that should be reported as the one
73 generating the exception.
75 @param nArgPos
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,
83 const char* pStr,
84 const css::uno::Reference< css::uno::XInterface >& xIf,
85 ::sal_Int16 nArgPos );
87 /** Verify that the given transformation contains valid floating point
88 values.
90 @param rMatrix
91 Matrix to check
93 @param xIf
94 The interface that should be reported as the one
95 generating the exception.
97 @param nArgPos
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,
105 const char* pStr,
106 const css::uno::Reference< css::uno::XInterface >& xIf,
107 ::sal_Int16 nArgPos );
109 /** Verify that the given point contains valid floating point
110 values.
112 @param rPoint
113 Point to check
115 @param xIf
116 The interface that should be reported as the one
117 generating the exception.
119 @param nArgPos
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,
127 const char* pStr,
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.
134 @param rSegment
135 Segment to check
137 @param xIf
138 The interface that should be reported as the one
139 generating the exception.
141 @param nArgPos
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,
149 const char* pStr,
150 const css::uno::Reference< css::uno::XInterface >& xIf,
151 ::sal_Int16 nArgPos );
153 /** Verify that the given rectangle contains valid floating
154 point values.
156 @param rRect
157 Rect to check
159 @param xIf
160 The interface that should be reported as the one
161 generating the exception.
163 @param nArgPos
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,
171 const char* pStr,
172 const css::uno::Reference< css::uno::XInterface >& xIf,
173 ::sal_Int16 nArgPos );
175 /** Basic check for view state validity.
177 @param viewState
178 Viewstate to check
180 @param xIf
181 The interface that should be reported as the one
182 generating the exception.
184 @param nArgPos
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,
192 const char* pStr,
193 const css::uno::Reference< css::uno::XInterface >& xIf,
194 ::sal_Int16 nArgPos );
196 /** Basic check for render state validity.
198 @param renderState
199 Renderstate to check
201 @param xIf
202 The interface that should be reported as the one
203 generating the exception.
205 @param nArgPos
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,
217 const char* pStr,
218 const css::uno::Reference< css::uno::XInterface >& xIf,
219 ::sal_Int16 nArgPos,
220 sal_Int32 nMinColorComponents=0 );
222 /** Basic check for stroke attributes validity.
224 @param strokeAttributes
225 Attributes to check
227 @param xIf
228 The interface that should be reported as the one
229 generating the exception.
231 @param nArgPos
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,
239 const char* pStr,
240 const css::uno::Reference< css::uno::XInterface >& xIf,
241 ::sal_Int16 nArgPos );
243 /** Basic check for texture validity.
245 @param texture
246 Texture to check
248 @param xIf
249 The interface that should be reported as the one
250 generating the exception.
252 @param nArgPos
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,
260 const char* pStr,
261 const css::uno::Reference< css::uno::XInterface >& xIf,
262 ::sal_Int16 nArgPos );
264 /** Basic check for bitmap layout validity.
266 @param bitmapLayout
267 Bitmap layout to check
269 @param xIf
270 The interface that should be reported as the one
271 generating the exception.
273 @param nArgPos
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,
281 const char* pStr,
282 const css::uno::Reference< css::uno::XInterface >& xIf,
283 ::sal_Int16 nArgPos );
285 /** Basic check for font request validity.
287 @param fontRequest
288 Font request to check
290 @param xIf
291 The interface that should be reported as the one
292 generating the exception.
294 @param nArgPos
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,
302 const char* pStr,
303 const css::uno::Reference< css::uno::XInterface >& xIf,
304 ::sal_Int16 nArgPos );
306 /** Templatized check for uno::Reference validity.
308 @param rRef
309 Reference to check against non-NILness
311 @param xIf
312 The interface that should be reported as the one
313 generating the exception.
315 @param nArgPos
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,
324 const char* pStr,
325 const css::uno::Reference< css::uno::XInterface >& xIf,
326 ::sal_Int16 nArgPos )
328 if( !rRef.is() )
330 #if OSL_DEBUG_LEVEL > 0
331 throw css::lang::IllegalArgumentException(
332 OUString::createFromAscii(pStr) + ": reference is NULL",
333 xIf,
334 nArgPos );
335 #else
336 (void)pStr; (void)xIf; (void)nArgPos;
337 throw css::lang::IllegalArgumentException();
338 #endif
342 /** Templatized check for content-of-sequence validity.
344 @param rSequence
345 Sequence of things to check
347 @param xIf
348 The interface that should be reported as the one
349 generating the exception.
351 @param nArgPos
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,
360 const char* pStr,
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,
382 const char* pStr,
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,
390 const Arg1& rArg1,
391 const char* pStr,
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,
399 typename Arg1,
400 typename Arg2 > void verifyArgs( const Arg0& rArg0,
401 const Arg1& rArg1,
402 const Arg2& rArg2,
403 const char* pStr,
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,
412 typename Arg1,
413 typename Arg2,
414 typename Arg3 > void verifyArgs( const Arg0& rArg0,
415 const Arg1& rArg1,
416 const Arg2& rArg2,
417 const Arg3& rArg3,
418 const char* pStr,
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,
428 typename Arg1,
429 typename Arg2,
430 typename Arg3,
431 typename Arg4 > void verifyArgs( const Arg0& rArg0,
432 const Arg1& rArg1,
433 const Arg2& rArg2,
434 const Arg3& rArg3,
435 const Arg4& rArg4,
436 const char* pStr,
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,
447 typename Arg1,
448 typename Arg2,
449 typename Arg3,
450 typename Arg4,
451 typename Arg5 > void verifyArgs( const Arg0& rArg0,
452 const Arg1& rArg1,
453 const Arg2& rArg2,
454 const Arg3& rArg3,
455 const Arg4& rArg4,
456 const Arg5& rArg5,
457 const char* pStr,
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,
469 typename Arg1,
470 typename Arg2,
471 typename Arg3,
472 typename Arg4,
473 typename Arg5,
474 typename Arg6 > void verifyArgs( const Arg0& rArg0,
475 const Arg1& rArg1,
476 const Arg2& rArg2,
477 const Arg3& rArg3,
478 const Arg4& rArg4,
479 const Arg5& rArg5,
480 const Arg6& rArg6,
481 const char* pStr,
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
495 range is violated
497 template< typename NumType > inline void verifyRange( NumType arg, NumType lowerBound, NumType upperBound )
499 if( arg < lowerBound ||
500 arg > upperBound )
502 throw css::lang::IllegalArgumentException();
506 /** Range checker, which throws css::lang::IllegalArgument exception, when
507 range is violated
509 The checked range is half open, i.e. only bound by the specified value.
511 @param arg
512 Arg to check
514 @param bound
515 Bound to check against
517 @param bLowerBound
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
533 @param rect
534 Rect to verify
536 @param size
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
545 @param pos
546 Position to verify
548 @param size
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
557 @param size
558 Size to verify
560 CANVASTOOLS_DLLPUBLIC void verifyBitmapSize( const css::geometry::IntegerSize2D& size,
561 const char* pStr,
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
567 @param size
568 Size to verify
570 CANVASTOOLS_DLLPUBLIC void verifySpriteSize( const css::geometry::RealSize2D& size,
571 const char* pStr,
572 const css::uno::Reference< css::uno::XInterface >& xIf );
576 #endif /* INCLUDED_CANVAS_VERIFYINPUT_HXX */
578 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */