LibreOffice Module canvas (master)  1
verifyinput.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #pragma once
21 
22 #include <com/sun/star/uno/Reference.hxx>
23 #include <com/sun/star/lang/IllegalArgumentException.hpp>
24 
26 
27 namespace com { namespace sun { namespace star { namespace geometry
28 {
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;
38 } } } }
39 
40 namespace com { namespace sun { namespace star { namespace rendering
41 {
42  struct RenderState;
43  struct StrokeAttributes;
44  struct Texture;
45  struct ViewState;
46  struct IntegerBitmapLayout;
47  struct FontRequest;
48 } } } }
49 
50 namespace com::sun::star::uno { template <class E> class Sequence; }
51 
52 namespace canvas
53 {
54  namespace tools
55  {
56 
57  // Input checking facilities
58 
59 
60  // This header provides methods to check all common
61  // css::rendering::* method input parameters against
62  // compliance to the API specification.
63 
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 );
85 
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 );
107 
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 );
129 
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 );
151 
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 );
173 
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 );
194 
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 );
220 
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 );
241 
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 );
262 
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 );
283 
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 );
304 
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 )
326  {
327  if( !rRef.is() )
328  {
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
338  }
339  }
340 
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 )
362  {
363  const SequenceContent* pCurr = rSequence.getConstArray();
364  const SequenceContent* pEnd = pCurr + rSequence.getLength();
365  while( pCurr != pEnd )
366  verifyInput( *pCurr++, pStr, xIf, nArgPos );
367  }
368 
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*/ )
374  {
375  }
376 
377  // TODO(Q2): Employ some template arglist magic here, to avoid
378  // this duplication of code...
379 
380  template< typename Arg0 > void verifyArgs( const Arg0& rArg0,
381  const char* pStr,
382  const css::uno::Reference< css::uno::XInterface >& xIf )
383  {
384  verifyInput( rArg0, pStr, xIf, 0 );
385  }
386 
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 )
392  {
393  verifyInput( rArg0, pStr, xIf, 0 );
394  verifyInput( rArg1, pStr, xIf, 1 );
395  }
396 
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 )
404  {
405  verifyInput( rArg0, pStr, xIf, 0 );
406  verifyInput( rArg1, pStr, xIf, 1 );
407  verifyInput( rArg2, pStr, xIf, 2 );
408  }
409 
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 )
419  {
420  verifyInput( rArg0, pStr, xIf, 0 );
421  verifyInput( rArg1, pStr, xIf, 1 );
422  verifyInput( rArg2, pStr, xIf, 2 );
423  verifyInput( rArg3, pStr, xIf, 3 );
424  }
425 
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 )
437  {
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 );
443  }
444 
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 )
458  {
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 );
465  }
466 
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 )
482  {
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 );
490  }
491 
492 
496  template< typename NumType > inline void verifyRange( NumType arg, NumType lowerBound, NumType upperBound )
497  {
498  if( arg < lowerBound ||
499  arg > upperBound )
500  {
501  throw css::lang::IllegalArgumentException();
502  }
503  }
504 
520  template< typename NumType > inline void verifyRange( NumType arg, NumType bound, bool bLowerBound=true )
521  {
522  if( (bLowerBound && arg < bound) ||
523  (!bLowerBound && arg > bound) )
524  {
525  throw css::lang::IllegalArgumentException();
526  }
527  }
528 
538  CANVASTOOLS_DLLPUBLIC void verifyIndexRange( const css::geometry::IntegerRectangle2D& rect,
539  const css::geometry::IntegerSize2D& size );
540 
550  CANVASTOOLS_DLLPUBLIC void verifyIndexRange( const css::geometry::IntegerPoint2D& pos,
551  const css::geometry::IntegerSize2D& size );
552 
559  CANVASTOOLS_DLLPUBLIC void verifyBitmapSize( const css::geometry::IntegerSize2D& size,
560  const char* pStr,
561  const css::uno::Reference< css::uno::XInterface >& xIf );
562 
569  CANVASTOOLS_DLLPUBLIC void verifySpriteSize( const css::geometry::RealSize2D& size,
570  const char* pStr,
571  const css::uno::Reference< css::uno::XInterface >& xIf );
572  }
573 }
574 
575 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void verifyIndexRange(const geometry::IntegerRectangle2D &rect, const geometry::IntegerSize2D &size)
#define CANVASTOOLS_DLLPUBLIC
void verifyInput(const geometry::RealPoint2D &rPoint, const char *pStr, const uno::Reference< uno::XInterface > &xIf,::sal_Int16 nArgPos)
Definition: verifyinput.cxx:51
void verifySpriteSize(const geometry::RealSize2D &size, const char *pStr, const uno::Reference< uno::XInterface > &xIf)
void verifyRange(NumType arg, NumType lowerBound, NumType upperBound)
Range checker, which throws css::lang::IllegalArgument exception, when range is violated.
void verifyBitmapSize(const geometry::IntegerSize2D &size, const char *pStr, const uno::Reference< uno::XInterface > &xIf)
ViewState
void verifyArgs(const Arg0 &rArg0, const char *pStr, const css::uno::Reference< css::uno::XInterface > &xIf)
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo