bump product version to 5.0.4.1
[LibreOffice.git] / include / canvas / verifyinput.hxx
blob14f86769b299e09cb1cec6c7cc14592d4e04ed34
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
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 rectangle contains valid floating
166 point values.
168 @param rRect
169 Rect 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::RealRectangle2D& rRect,
183 const char* pStr,
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.
190 @param viewState
191 Viewstate to check
193 @param xIf
194 The interface that should be reported as the one
195 generating the exception.
197 @param nArgPos
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,
205 const char* pStr,
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.
212 @param renderState
213 Renderstate to check
215 @param xIf
216 The interface that should be reported as the one
217 generating the exception.
219 @param nArgPos
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,
231 const char* pStr,
232 const ::com::sun::star::uno::Reference<
233 ::com::sun::star::uno::XInterface >& xIf,
234 ::sal_Int16 nArgPos,
235 sal_Int32 nMinColorComponents=0 );
237 /** Basic check for stroke attributes validity.
239 @param strokeAttributes
240 Attributes to check
242 @param xIf
243 The interface that should be reported as the one
244 generating the exception.
246 @param nArgPos
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,
254 const char* pStr,
255 const ::com::sun::star::uno::Reference<
256 ::com::sun::star::uno::XInterface >& xIf,
257 ::sal_Int16 nArgPos );
259 /** Basic check for texture validity.
261 @param texture
262 Texture to check
264 @param xIf
265 The interface that should be reported as the one
266 generating the exception.
268 @param nArgPos
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,
276 const char* pStr,
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.
283 @param bitmapLayout
284 Bitmap layout to check
286 @param xIf
287 The interface that should be reported as the one
288 generating the exception.
290 @param nArgPos
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,
298 const char* pStr,
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.
305 @param fontInfo
306 Font info to check
308 @param xIf
309 The interface that should be reported as the one
310 generating the exception.
312 @param nArgPos
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,
320 const char* pStr,
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.
327 @param fontRequest
328 Font request to check
330 @param xIf
331 The interface that should be reported as the one
332 generating the exception.
334 @param nArgPos
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,
342 const char* pStr,
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.
349 @param rRef
350 Reference to check against non-NILness
352 @param xIf
353 The interface that should be reported as the one
354 generating the exception.
356 @param nArgPos
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,
365 const char* pStr,
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;
372 if( !rRef.is() )
374 #if OSL_DEBUG_LEVEL > 0
375 throw ::com::sun::star::lang::IllegalArgumentException(
376 OUString::createFromAscii(pStr) + ": reference is NULL",
377 xIf,
378 nArgPos );
379 #else
380 throw ::com::sun::star::lang::IllegalArgumentException();
381 #endif
385 /** Templatized check for content-of-sequence validity.
387 @param rSequence
388 Sequence of things to check
390 @param xIf
391 The interface that should be reported as the one
392 generating the exception.
394 @param nArgPos
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,
403 const char* pStr,
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,
427 const char* pStr,
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,
436 const Arg1& rArg1,
437 const char* pStr,
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,
446 typename Arg1,
447 typename Arg2 > void verifyArgs( const Arg0& rArg0,
448 const Arg1& rArg1,
449 const Arg2& rArg2,
450 const char* pStr,
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,
460 typename Arg1,
461 typename Arg2,
462 typename Arg3 > void verifyArgs( const Arg0& rArg0,
463 const Arg1& rArg1,
464 const Arg2& rArg2,
465 const Arg3& rArg3,
466 const char* pStr,
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,
477 typename Arg1,
478 typename Arg2,
479 typename Arg3,
480 typename Arg4 > void verifyArgs( const Arg0& rArg0,
481 const Arg1& rArg1,
482 const Arg2& rArg2,
483 const Arg3& rArg3,
484 const Arg4& rArg4,
485 const char* pStr,
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,
497 typename Arg1,
498 typename Arg2,
499 typename Arg3,
500 typename Arg4,
501 typename Arg5 > void verifyArgs( const Arg0& rArg0,
502 const Arg1& rArg1,
503 const Arg2& rArg2,
504 const Arg3& rArg3,
505 const Arg4& rArg4,
506 const Arg5& rArg5,
507 const char* pStr,
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,
520 typename Arg1,
521 typename Arg2,
522 typename Arg3,
523 typename Arg4,
524 typename Arg5,
525 typename Arg6 > void verifyArgs( const Arg0& rArg0,
526 const Arg1& rArg1,
527 const Arg2& rArg2,
528 const Arg3& rArg3,
529 const Arg4& rArg4,
530 const Arg5& rArg5,
531 const Arg6& rArg6,
532 const char* pStr,
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
547 range is violated
549 template< typename NumType > inline void verifyRange( NumType arg, NumType lowerBound, NumType upperBound )
551 if( arg < lowerBound ||
552 arg > upperBound )
554 throw ::com::sun::star::lang::IllegalArgumentException();
558 /** Range checker, which throws ::com::sun::star::lang::IllegalArgument exception, when
559 range is violated
561 The checked range is half open, i.e. only bound by the specified value.
563 @param arg
564 Arg to check
566 @param bound
567 Bound to check against
569 @param bLowerBound
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 ||
588 arg > upperBound )
590 throw ::com::sun::star::lang::IndexOutOfBoundsException();
594 /** Range checker, which throws ::com::sun::star::lang::IndexOutOfBounds exception, when
595 index range is violated
597 @param rect
598 Rect to verify
600 @param size
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
609 @param pos
610 Position to verify
612 @param size
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
621 @param size
622 Size to verify
624 CANVASTOOLS_DLLPUBLIC void verifyBitmapSize( const ::com::sun::star::geometry::IntegerSize2D& size,
625 const char* pStr,
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
632 @param size
633 Size to verify
635 CANVASTOOLS_DLLPUBLIC void verifySpriteSize( const ::com::sun::star::geometry::RealSize2D& size,
636 const char* pStr,
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: */