bump product version to 4.1.6.2
[LibreOffice.git] / include / canvas / verifyinput.hxx
blob07d72b32ff6cbd9d273b372da5209aa34cf9b938
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/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>
29 #include <algorithm>
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
37 struct RealPoint2D;
38 struct RealSize2D;
39 struct RealBezierSegment2D;
40 struct RealRectangle2D;
41 struct AffineMatrix2D;
42 struct Matrix2D;
43 struct IntegerPoint2D;
44 struct IntegerSize2D;
45 struct IntegerRectangle2D;
46 } } } }
48 namespace com { namespace sun { namespace star { namespace rendering
50 struct RenderState;
51 struct StrokeAttributes;
52 struct Texture;
53 struct ViewState;
54 struct IntegerBitmapLayout;
55 struct FontRequest;
56 struct FontInfo;
57 class XCanvas;
58 } } } }
61 namespace canvas
63 namespace tools
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
74 values.
76 @param rMatrix
77 Matrix to check
79 @param xIf
80 The interface that should be reported as the one
81 generating the exception.
83 @param nArgPos
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,
91 const char* pStr,
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
97 values.
99 @param rMatrix
100 Matrix to check
102 @param xIf
103 The interface that should be reported as the one
104 generating the exception.
106 @param nArgPos
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,
114 const char* pStr,
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
120 values.
122 @param rPoint
123 Point to check
125 @param xIf
126 The interface that should be reported as the one
127 generating the exception.
129 @param nArgPos
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,
137 const char* pStr,
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.
145 @param rSegment
146 Segment to check
148 @param xIf
149 The interface that should be reported as the one
150 generating the exception.
152 @param nArgPos
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,
160 const char* pStr,
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
166 values.
168 @param rPoint
169 Point to check
171 @param xIf
172 The interface that should be reported as the one
173 generating the exception.
175 @param nArgPos
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,
183 const char* pStr,
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
189 point values.
191 @param rRect
192 Rect to check
194 @param xIf
195 The interface that should be reported as the one
196 generating the exception.
198 @param nArgPos
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,
206 const char* pStr,
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.
213 @param viewState
214 Viewstate to check
216 @param xIf
217 The interface that should be reported as the one
218 generating the exception.
220 @param nArgPos
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,
228 const char* pStr,
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.
235 @param renderState
236 Renderstate to check
238 @param xIf
239 The interface that should be reported as the one
240 generating the exception.
242 @param nArgPos
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,
254 const char* pStr,
255 const ::com::sun::star::uno::Reference<
256 ::com::sun::star::uno::XInterface >& xIf,
257 ::sal_Int16 nArgPos,
258 sal_Int32 nMinColorComponents=0 );
260 /** Basic check for stroke attributes validity.
262 @param strokeAttributes
263 Attributes to check
265 @param xIf
266 The interface that should be reported as the one
267 generating the exception.
269 @param nArgPos
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,
277 const char* pStr,
278 const ::com::sun::star::uno::Reference<
279 ::com::sun::star::uno::XInterface >& xIf,
280 ::sal_Int16 nArgPos );
282 /** Basic check for texture validity.
284 @param texture
285 Texture to check
287 @param xIf
288 The interface that should be reported as the one
289 generating the exception.
291 @param nArgPos
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,
299 const char* pStr,
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.
306 @param bitmapLayout
307 Bitmap layout to check
309 @param xIf
310 The interface that should be reported as the one
311 generating the exception.
313 @param nArgPos
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,
321 const char* pStr,
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.
328 @param fontInfo
329 Font info to check
331 @param xIf
332 The interface that should be reported as the one
333 generating the exception.
335 @param nArgPos
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,
343 const char* pStr,
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.
350 @param fontRequest
351 Font request to check
353 @param xIf
354 The interface that should be reported as the one
355 generating the exception.
357 @param nArgPos
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,
365 const char* pStr,
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.
372 @param rRef
373 Reference to check against non-NILness
375 @param xIf
376 The interface that should be reported as the one
377 generating the exception.
379 @param nArgPos
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,
388 const char* pStr,
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;
395 if( !rRef.is() )
397 #if OSL_DEBUG_LEVEL > 0
398 throw ::com::sun::star::lang::IllegalArgumentException(
399 OUString::createFromAscii(pStr) + ": reference is NULL",
400 xIf,
401 nArgPos );
402 #else
403 throw ::com::sun::star::lang::IllegalArgumentException();
404 #endif
408 /** Templatized check for content-of-sequence validity.
410 @param rSequence
411 Sequence of things to check
413 @param xIf
414 The interface that should be reported as the one
415 generating the exception.
417 @param nArgPos
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,
426 const char* pStr,
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,
450 const char* pStr,
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,
459 const Arg1& rArg1,
460 const char* pStr,
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,
469 typename Arg1,
470 typename Arg2 > void verifyArgs( const Arg0& rArg0,
471 const Arg1& rArg1,
472 const Arg2& rArg2,
473 const char* pStr,
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,
483 typename Arg1,
484 typename Arg2,
485 typename Arg3 > void verifyArgs( const Arg0& rArg0,
486 const Arg1& rArg1,
487 const Arg2& rArg2,
488 const Arg3& rArg3,
489 const char* pStr,
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,
500 typename Arg1,
501 typename Arg2,
502 typename Arg3,
503 typename Arg4 > void verifyArgs( const Arg0& rArg0,
504 const Arg1& rArg1,
505 const Arg2& rArg2,
506 const Arg3& rArg3,
507 const Arg4& rArg4,
508 const char* pStr,
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,
520 typename Arg1,
521 typename Arg2,
522 typename Arg3,
523 typename Arg4,
524 typename Arg5 > void verifyArgs( const Arg0& rArg0,
525 const Arg1& rArg1,
526 const Arg2& rArg2,
527 const Arg3& rArg3,
528 const Arg4& rArg4,
529 const Arg5& rArg5,
530 const char* pStr,
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,
543 typename Arg1,
544 typename Arg2,
545 typename Arg3,
546 typename Arg4,
547 typename Arg5,
548 typename Arg6 > void verifyArgs( const Arg0& rArg0,
549 const Arg1& rArg1,
550 const Arg2& rArg2,
551 const Arg3& rArg3,
552 const Arg4& rArg4,
553 const Arg5& rArg5,
554 const Arg6& rArg6,
555 const char* pStr,
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
570 range is violated
572 template< typename NumType > inline void verifyRange( NumType arg, NumType lowerBound, NumType upperBound )
574 if( arg < lowerBound ||
575 arg > upperBound )
577 throw ::com::sun::star::lang::IllegalArgumentException();
581 /** Range checker, which throws ::com::sun::star::lang::IllegalArgument exception, when
582 range is violated
584 The checked range is half open, i.e. only bound by the specified value.
586 @param arg
587 Arg to check
589 @param bound
590 Bound to check against
592 @param bLowerBound
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 ||
611 arg > upperBound )
613 throw ::com::sun::star::lang::IndexOutOfBoundsException();
617 /** Range checker, which throws ::com::sun::star::lang::IndexOutOfBounds exception, when
618 index range is violated
620 @param rect
621 Rect to verify
623 @param size
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
632 @param pos
633 Position to verify
635 @param size
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
644 @param size
645 Size to verify
647 CANVASTOOLS_DLLPUBLIC void verifyBitmapSize( const ::com::sun::star::geometry::IntegerSize2D& size,
648 const char* pStr,
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
655 @param size
656 Size to verify
658 CANVASTOOLS_DLLPUBLIC void verifySpriteSize( const ::com::sun::star::geometry::RealSize2D& size,
659 const char* pStr,
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: */