mar: allow parallel creation of diff packages
[LibreOffice.git] / canvas / inc / verifyinput.hxx
blob7dd956c92882eabeef727ce8a187f86b049a9b24
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 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,
379 const char* pStr,
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,
387 const Arg1& rArg1,
388 const char* pStr,
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,
396 typename Arg1,
397 typename Arg2 > void verifyArgs( const Arg0& rArg0,
398 const Arg1& rArg1,
399 const Arg2& rArg2,
400 const char* pStr,
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,
409 typename Arg1,
410 typename Arg2,
411 typename Arg3 > void verifyArgs( const Arg0& rArg0,
412 const Arg1& rArg1,
413 const Arg2& rArg2,
414 const Arg3& rArg3,
415 const char* pStr,
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,
425 typename Arg1,
426 typename Arg2,
427 typename Arg3,
428 typename Arg4 > void verifyArgs( const Arg0& rArg0,
429 const Arg1& rArg1,
430 const Arg2& rArg2,
431 const Arg3& rArg3,
432 const Arg4& rArg4,
433 const char* pStr,
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,
444 typename Arg1,
445 typename Arg2,
446 typename Arg3,
447 typename Arg4,
448 typename Arg5 > void verifyArgs( const Arg0& rArg0,
449 const Arg1& rArg1,
450 const Arg2& rArg2,
451 const Arg3& rArg3,
452 const Arg4& rArg4,
453 const Arg5& rArg5,
454 const char* pStr,
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,
466 typename Arg1,
467 typename Arg2,
468 typename Arg3,
469 typename Arg4,
470 typename Arg5,
471 typename Arg6 > void verifyArgs( const Arg0& rArg0,
472 const Arg1& rArg1,
473 const Arg2& rArg2,
474 const Arg3& rArg3,
475 const Arg4& rArg4,
476 const Arg5& rArg5,
477 const Arg6& rArg6,
478 const char* pStr,
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
492 range is violated
494 template< typename NumType > inline void verifyRange( NumType arg, NumType lowerBound, NumType upperBound )
496 if( arg < lowerBound ||
497 arg > upperBound )
499 throw css::lang::IllegalArgumentException();
503 /** Range checker, which throws css::lang::IllegalArgument exception, when
504 range is violated
506 The checked range is half open, i.e. only bound by the specified value.
508 @param arg
509 Arg to check
511 @param bound
512 Bound to check against
514 @param bLowerBound
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
530 @param rect
531 Rect to verify
533 @param size
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
542 @param pos
543 Position to verify
545 @param size
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
554 @param size
555 Size to verify
557 CANVASTOOLS_DLLPUBLIC void verifyBitmapSize( const css::geometry::IntegerSize2D& size,
558 const char* pStr,
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
564 @param size
565 Size to verify
567 CANVASTOOLS_DLLPUBLIC void verifySpriteSize( const css::geometry::RealSize2D& size,
568 const char* pStr,
569 const css::uno::Reference< css::uno::XInterface >& xIf );
573 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */