1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef INCLUDED_CANVAS_VERIFYINPUT_HXX 25 #define INCLUDED_CANVAS_VERIFYINPUT_HXX 26 27 #include <com/sun/star/uno/Reference.hxx> 28 #include <com/sun/star/uno/Sequence.hxx> 29 #include <com/sun/star/uno/RuntimeException.hpp> 30 #include <com/sun/star/lang/IllegalArgumentException.hpp> 31 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> 32 33 #include <algorithm> 34 #include <boost/bind.hpp> 35 #include <boost/current_function.hpp> 36 37 #include <canvas/canvastoolsdllapi.h> 38 39 namespace com { namespace sun { namespace star { namespace geometry 40 { 41 struct RealPoint2D; 42 struct RealSize2D; 43 struct RealBezierSegment2D; 44 struct RealRectangle2D; 45 struct AffineMatrix2D; 46 struct Matrix2D; 47 struct IntegerPoint2D; 48 struct IntegerSize2D; 49 struct IntegerRectangle2D; 50 } } } } 51 52 namespace com { namespace sun { namespace star { namespace rendering 53 { 54 struct RenderState; 55 struct StrokeAttributes; 56 struct Texture; 57 struct ViewState; 58 struct IntegerBitmapLayout; 59 struct FloatingPointBitmapLayout; 60 struct FontRequest; 61 struct FontInfo; 62 class XCanvas; 63 } } } } 64 65 66 namespace canvas 67 { 68 namespace tools 69 { 70 71 // Input checking facilities 72 // =================================================================== 73 74 // This header provides methods to check all common 75 // css::rendering::* method input parameters against 76 // compliance to the API specification. 77 78 /** Verify that the given transformation contains valid floating point 79 values. 80 81 @param rMatrix 82 Matrix to check 83 84 @param xIf 85 The interface that should be reported as the one 86 generating the exception. 87 88 @param nArgPos 89 Argument position on the call site (i.e. the position of 90 the argument, checked here, on the UNO interface 91 method. Counting starts at 0). 92 93 @throws an lang::IllegalArgumentException, if anything is wrong 94 */ 95 CANVASTOOLS_DLLPUBLIC void verifyInput( const ::com::sun::star::geometry::AffineMatrix2D& rMatrix, 96 const char* pStr, 97 const ::com::sun::star::uno::Reference< 98 ::com::sun::star::uno::XInterface >& xIf, 99 ::sal_Int16 nArgPos ); 100 101 /** Verify that the given transformation contains valid floating point 102 values. 103 104 @param rMatrix 105 Matrix to check 106 107 @param xIf 108 The interface that should be reported as the one 109 generating the exception. 110 111 @param nArgPos 112 Argument position on the call site (i.e. the position of 113 the argument, checked here, on the UNO interface 114 method. Counting starts at 0). 115 116 @throws an lang::IllegalArgumentException, if anything is wrong 117 */ 118 CANVASTOOLS_DLLPUBLIC void verifyInput( const ::com::sun::star::geometry::Matrix2D& rMatrix, 119 const char* pStr, 120 const ::com::sun::star::uno::Reference< 121 ::com::sun::star::uno::XInterface >& xIf, 122 ::sal_Int16 nArgPos ); 123 124 /** Verify that the given point contains valid floating point 125 values. 126 127 @param rPoint 128 Point to check 129 130 @param xIf 131 The interface that should be reported as the one 132 generating the exception. 133 134 @param nArgPos 135 Argument position on the call site (i.e. the position of 136 the argument, checked here, on the UNO interface 137 method. Counting starts at 0). 138 139 @throws an lang::IllegalArgumentException, if anything is wrong 140 */ 141 CANVASTOOLS_DLLPUBLIC void verifyInput( const ::com::sun::star::geometry::RealPoint2D& rPoint, 142 const char* pStr, 143 const ::com::sun::star::uno::Reference< 144 ::com::sun::star::uno::XInterface >& xIf, 145 ::sal_Int16 nArgPos ); 146 147 /** Verify that the given size contains valid floating point 148 values. 149 150 @param rSize 151 Size to check 152 153 @param xIf 154 The interface that should be reported as the one 155 generating the exception. 156 157 @param nArgPos 158 Argument position on the call site (i.e. the position of 159 the argument, checked here, on the UNO interface 160 method. Counting starts at 0). 161 162 @throws an lang::IllegalArgumentException, if anything is wrong 163 */ 164 CANVASTOOLS_DLLPUBLIC void verifyInput( const ::com::sun::star::geometry::RealSize2D& rSize, 165 const char* pStr, 166 const ::com::sun::star::uno::Reference< 167 ::com::sun::star::uno::XInterface >& xIf, 168 ::sal_Int16 nArgPos ); 169 170 /** Verify that the given bezier segment contains valid 171 floating point values. 172 173 @param rSegment 174 Segment to check 175 176 @param xIf 177 The interface that should be reported as the one 178 generating the exception. 179 180 @param nArgPos 181 Argument position on the call site (i.e. the position of 182 the argument, checked here, on the UNO interface 183 method. Counting starts at 0). 184 185 @throws an lang::IllegalArgumentException, if anything is wrong 186 */ 187 CANVASTOOLS_DLLPUBLIC void verifyInput( const ::com::sun::star::geometry::RealBezierSegment2D& rSegment, 188 const char* pStr, 189 const ::com::sun::star::uno::Reference< 190 ::com::sun::star::uno::XInterface >& xIf, 191 ::sal_Int16 nArgPos ); 192 193 /** Verify that the given point contains valid floating point 194 values. 195 196 @param rPoint 197 Point to check 198 199 @param xIf 200 The interface that should be reported as the one 201 generating the exception. 202 203 @param nArgPos 204 Argument position on the call site (i.e. the position of 205 the argument, checked here, on the UNO interface 206 method. Counting starts at 0). 207 208 @throws an lang::IllegalArgumentException, if anything is wrong 209 */ 210 CANVASTOOLS_DLLPUBLIC void verifyInput( const ::com::sun::star::geometry::RealPoint2D& rPoint, 211 const char* pStr, 212 const ::com::sun::star::uno::Reference< 213 ::com::sun::star::uno::XInterface >& xIf, 214 ::sal_Int16 nArgPos ); 215 216 /** Verify that the given rectangle contains valid floating 217 point values. 218 219 @param rRect 220 Rect to check 221 222 @param xIf 223 The interface that should be reported as the one 224 generating the exception. 225 226 @param nArgPos 227 Argument position on the call site (i.e. the position of 228 the argument, checked here, on the UNO interface 229 method. Counting starts at 0). 230 231 @throws an lang::IllegalArgumentException, if anything is wrong 232 */ 233 CANVASTOOLS_DLLPUBLIC void verifyInput( const ::com::sun::star::geometry::RealRectangle2D& rRect, 234 const char* pStr, 235 const ::com::sun::star::uno::Reference< 236 ::com::sun::star::uno::XInterface >& xIf, 237 ::sal_Int16 nArgPos ); 238 239 /** Basic check for view state validity. 240 241 @param viewState 242 Viewstate to check 243 244 @param xIf 245 The interface that should be reported as the one 246 generating the exception. 247 248 @param nArgPos 249 Argument position on the call site (i.e. the position of 250 the argument, checked here, on the UNO interface 251 method. Counting starts at 0). 252 253 @throws an lang::IllegalArgumentException, if anything is wrong 254 */ 255 CANVASTOOLS_DLLPUBLIC void verifyInput( const ::com::sun::star::rendering::ViewState& viewState, 256 const char* pStr, 257 const ::com::sun::star::uno::Reference< 258 ::com::sun::star::uno::XInterface >& xIf, 259 ::sal_Int16 nArgPos ); 260 261 /** Basic check for render state validity. 262 263 @param renderState 264 Renderstate to check 265 266 @param xIf 267 The interface that should be reported as the one 268 generating the exception. 269 270 @param nArgPos 271 Argument position on the call site (i.e. the position of 272 the argument, checked here, on the UNO interface 273 method. Counting starts at 0). 274 275 @param nMinColorComponents 276 Minimal number of color components available in 277 RenderState::DeviceColor 278 279 @throws an lang::IllegalArgumentException, if anything is wrong 280 */ 281 CANVASTOOLS_DLLPUBLIC void verifyInput( const ::com::sun::star::rendering::RenderState& renderState, 282 const char* pStr, 283 const ::com::sun::star::uno::Reference< 284 ::com::sun::star::uno::XInterface >& xIf, 285 ::sal_Int16 nArgPos, 286 sal_Int32 nMinColorComponents=0 ); 287 288 /** Basic check for stroke attributes validity. 289 290 @param strokeAttributes 291 Attributes to check 292 293 @param xIf 294 The interface that should be reported as the one 295 generating the exception. 296 297 @param nArgPos 298 Argument position on the call site (i.e. the position of 299 the argument, checked here, on the UNO interface 300 method. Counting starts at 0). 301 302 @throws an lang::IllegalArgumentException, if anything is wrong 303 */ 304 CANVASTOOLS_DLLPUBLIC void verifyInput( const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes, 305 const char* pStr, 306 const ::com::sun::star::uno::Reference< 307 ::com::sun::star::uno::XInterface >& xIf, 308 ::sal_Int16 nArgPos ); 309 310 /** Basic check for texture validity. 311 312 @param texture 313 Texture to check 314 315 @param xIf 316 The interface that should be reported as the one 317 generating the exception. 318 319 @param nArgPos 320 Argument position on the call site (i.e. the position of 321 the argument, checked here, on the UNO interface 322 method. Counting starts at 0). 323 324 @throws an lang::IllegalArgumentException, if anything is wrong 325 */ 326 CANVASTOOLS_DLLPUBLIC void verifyInput( const ::com::sun::star::rendering::Texture& texture, 327 const char* pStr, 328 const ::com::sun::star::uno::Reference< 329 ::com::sun::star::uno::XInterface >& xIf, 330 ::sal_Int16 nArgPos ); 331 332 /** Basic check for bitmap layout validity. 333 334 @param bitmapLayout 335 Bitmap layout to check 336 337 @param xIf 338 The interface that should be reported as the one 339 generating the exception. 340 341 @param nArgPos 342 Argument position on the call site (i.e. the position of 343 the argument, checked here, on the UNO interface 344 method. Counting starts at 0). 345 346 @throws an lang::IllegalArgumentException, if anything is wrong 347 */ 348 CANVASTOOLS_DLLPUBLIC void verifyInput( const ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout, 349 const char* pStr, 350 const ::com::sun::star::uno::Reference< 351 ::com::sun::star::uno::XInterface >& xIf, 352 ::sal_Int16 nArgPos ); 353 354 /** Basic check for bitmap layout validity. 355 356 @param bitmapLayout 357 Bitmap layout to check 358 359 @param xIf 360 The interface that should be reported as the one 361 generating the exception. 362 363 @param nArgPos 364 Argument position on the call site (i.e. the position of 365 the argument, checked here, on the UNO interface 366 method. Counting starts at 0). 367 368 @throws an lang::IllegalArgumentException, if anything is wrong 369 */ 370 CANVASTOOLS_DLLPUBLIC void verifyInput( const ::com::sun::star::rendering::FloatingPointBitmapLayout& bitmapLayout, 371 const char* pStr, 372 const ::com::sun::star::uno::Reference< 373 ::com::sun::star::uno::XInterface >& xIf, 374 ::sal_Int16 nArgPos ); 375 376 /** Basic check for font info validity. 377 378 @param fontInfo 379 Font info to check 380 381 @param xIf 382 The interface that should be reported as the one 383 generating the exception. 384 385 @param nArgPos 386 Argument position on the call site (i.e. the position of 387 the argument, checked here, on the UNO interface 388 method. Counting starts at 0). 389 390 @throws an lang::IllegalArgumentException, if anything is wrong 391 */ 392 CANVASTOOLS_DLLPUBLIC void verifyInput( const ::com::sun::star::rendering::FontInfo& fontInfo, 393 const char* pStr, 394 const ::com::sun::star::uno::Reference< 395 ::com::sun::star::uno::XInterface >& xIf, 396 ::sal_Int16 nArgPos ); 397 398 /** Basic check for font request validity. 399 400 @param fontRequest 401 Font request to check 402 403 @param xIf 404 The interface that should be reported as the one 405 generating the exception. 406 407 @param nArgPos 408 Argument position on the call site (i.e. the position of 409 the argument, checked here, on the UNO interface 410 method. Counting starts at 0). 411 412 @throws an lang::IllegalArgumentException, if anything is wrong 413 */ 414 CANVASTOOLS_DLLPUBLIC void verifyInput( const ::com::sun::star::rendering::FontRequest& fontRequest, 415 const char* pStr, 416 const ::com::sun::star::uno::Reference< 417 ::com::sun::star::uno::XInterface >& xIf, 418 ::sal_Int16 nArgPos ); 419 420 /** Templatized check for uno::Reference validity. 421 422 @param rRef 423 Reference to check against non-NILness 424 425 @param xIf 426 The interface that should be reported as the one 427 generating the exception. 428 429 @param nArgPos 430 Argument position on the call site (i.e. the position of 431 the argument, checked here, on the UNO interface 432 method. Counting starts at 0). 433 434 @throws an lang::IllegalArgumentException, if anything is wrong 435 */ verifyInput(const::com::sun::star::uno::Reference<Interface> & rRef,const char * pStr,const::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & xIf,::sal_Int16 nArgPos)436 template< class Interface > void verifyInput( 437 const ::com::sun::star::uno::Reference< Interface >& rRef, 438 const char* pStr, 439 const ::com::sun::star::uno::Reference< 440 ::com::sun::star::uno::XInterface >& xIf, 441 ::sal_Int16 nArgPos ) 442 { 443 (void)pStr; (void)xIf; (void)nArgPos; 444 445 if( !rRef.is() ) 446 { 447 #if OSL_DEBUG_LEVEL > 0 448 throw ::com::sun::star::lang::IllegalArgumentException( 449 ::rtl::OUString::createFromAscii(pStr) + 450 ::rtl::OUString::createFromAscii(": reference is NULL"), 451 xIf, 452 nArgPos ); 453 #else 454 throw ::com::sun::star::lang::IllegalArgumentException(); 455 #endif 456 } 457 } 458 459 /** Templatized check for content-of-sequence validity. 460 461 @param rSequence 462 Sequence of things to check 463 464 @param xIf 465 The interface that should be reported as the one 466 generating the exception. 467 468 @param nArgPos 469 Argument position on the call site (i.e. the position of 470 the argument, checked here, on the UNO interface 471 method. Counting starts at 0). 472 473 @throws an lang::IllegalArgumentException, if anything is wrong 474 */ verifyInput(const::com::sun::star::uno::Sequence<SequenceContent> & rSequence,const char * pStr,const::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & xIf,::sal_Int16 nArgPos)475 template< typename SequenceContent > void verifyInput( 476 const ::com::sun::star::uno::Sequence< SequenceContent >& rSequence, 477 const char* pStr, 478 const ::com::sun::star::uno::Reference< 479 ::com::sun::star::uno::XInterface >& xIf, 480 ::sal_Int16 nArgPos ) 481 { 482 const SequenceContent* pCurr = rSequence.getConstArray(); 483 const SequenceContent* pEnd = pCurr + rSequence.getLength(); 484 while( pCurr != pEnd ) 485 verifyInput( *pCurr++, pStr, xIf, nArgPos ); 486 } 487 488 /// Catch-all, to handle cases that DON'T need input checking (i.e. the Integer geometry ones) verifyInput(const T &,const char *,const::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> &,::sal_Int16)489 template< typename T > void verifyInput( const T& /*rDummy*/, 490 const char* /*pStr*/, 491 const ::com::sun::star::uno::Reference< 492 ::com::sun::star::uno::XInterface >& /*xIf*/, 493 ::sal_Int16 /*nArgPos*/ ) 494 { 495 } 496 497 // TODO(Q2): Employ some template arglist magic here, to avoid 498 // this duplication of code... 499 verifyArgs(const Arg0 & rArg0,const char * pStr,const::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & xIf)500 template< typename Arg0 > void verifyArgs( const Arg0& rArg0, 501 const char* pStr, 502 const ::com::sun::star::uno::Reference< 503 ::com::sun::star::uno::XInterface >& xIf ) 504 { 505 verifyInput( rArg0, pStr, xIf, 0 ); 506 } 507 508 template< typename Arg0, verifyArgs(const Arg0 & rArg0,const Arg1 & rArg1,const char * pStr,const::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & xIf)509 typename Arg1 > void verifyArgs( const Arg0& rArg0, 510 const Arg1& rArg1, 511 const char* pStr, 512 const ::com::sun::star::uno::Reference< 513 ::com::sun::star::uno::XInterface >& xIf ) 514 { 515 verifyInput( rArg0, pStr, xIf, 0 ); 516 verifyInput( rArg1, pStr, xIf, 1 ); 517 } 518 519 template< typename Arg0, 520 typename Arg1, verifyArgs(const Arg0 & rArg0,const Arg1 & rArg1,const Arg2 & rArg2,const char * pStr,const::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & xIf)521 typename Arg2 > void verifyArgs( const Arg0& rArg0, 522 const Arg1& rArg1, 523 const Arg2& rArg2, 524 const char* pStr, 525 const ::com::sun::star::uno::Reference< 526 ::com::sun::star::uno::XInterface >& xIf ) 527 { 528 verifyInput( rArg0, pStr, xIf, 0 ); 529 verifyInput( rArg1, pStr, xIf, 1 ); 530 verifyInput( rArg2, pStr, xIf, 2 ); 531 } 532 533 template< typename Arg0, 534 typename Arg1, 535 typename Arg2, verifyArgs(const Arg0 & rArg0,const Arg1 & rArg1,const Arg2 & rArg2,const Arg3 & rArg3,const char * pStr,const::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & xIf)536 typename Arg3 > void verifyArgs( const Arg0& rArg0, 537 const Arg1& rArg1, 538 const Arg2& rArg2, 539 const Arg3& rArg3, 540 const char* pStr, 541 const ::com::sun::star::uno::Reference< 542 ::com::sun::star::uno::XInterface >& xIf ) 543 { 544 verifyInput( rArg0, pStr, xIf, 0 ); 545 verifyInput( rArg1, pStr, xIf, 1 ); 546 verifyInput( rArg2, pStr, xIf, 2 ); 547 verifyInput( rArg3, pStr, xIf, 3 ); 548 } 549 550 template< typename Arg0, 551 typename Arg1, 552 typename Arg2, 553 typename Arg3, verifyArgs(const Arg0 & rArg0,const Arg1 & rArg1,const Arg2 & rArg2,const Arg3 & rArg3,const Arg4 & rArg4,const char * pStr,const::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & xIf)554 typename Arg4 > void verifyArgs( const Arg0& rArg0, 555 const Arg1& rArg1, 556 const Arg2& rArg2, 557 const Arg3& rArg3, 558 const Arg4& rArg4, 559 const char* pStr, 560 const ::com::sun::star::uno::Reference< 561 ::com::sun::star::uno::XInterface >& xIf ) 562 { 563 verifyInput( rArg0, pStr, xIf, 0 ); 564 verifyInput( rArg1, pStr, xIf, 1 ); 565 verifyInput( rArg2, pStr, xIf, 2 ); 566 verifyInput( rArg3, pStr, xIf, 3 ); 567 verifyInput( rArg4, pStr, xIf, 4 ); 568 } 569 570 template< typename Arg0, 571 typename Arg1, 572 typename Arg2, 573 typename Arg3, 574 typename Arg4, verifyArgs(const Arg0 & rArg0,const Arg1 & rArg1,const Arg2 & rArg2,const Arg3 & rArg3,const Arg4 & rArg4,const Arg5 & rArg5,const char * pStr,const::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & xIf)575 typename Arg5 > void verifyArgs( const Arg0& rArg0, 576 const Arg1& rArg1, 577 const Arg2& rArg2, 578 const Arg3& rArg3, 579 const Arg4& rArg4, 580 const Arg5& rArg5, 581 const char* pStr, 582 const ::com::sun::star::uno::Reference< 583 ::com::sun::star::uno::XInterface >& xIf ) 584 { 585 verifyInput( rArg0, pStr, xIf, 0 ); 586 verifyInput( rArg1, pStr, xIf, 1 ); 587 verifyInput( rArg2, pStr, xIf, 2 ); 588 verifyInput( rArg3, pStr, xIf, 3 ); 589 verifyInput( rArg4, pStr, xIf, 4 ); 590 verifyInput( rArg5, pStr, xIf, 5 ); 591 } 592 593 template< typename Arg0, 594 typename Arg1, 595 typename Arg2, 596 typename Arg3, 597 typename Arg4, 598 typename Arg5, verifyArgs(const Arg0 & rArg0,const Arg1 & rArg1,const Arg2 & rArg2,const Arg3 & rArg3,const Arg4 & rArg4,const Arg5 & rArg5,const Arg6 & rArg6,const char * pStr,const::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & xIf)599 typename Arg6 > void verifyArgs( const Arg0& rArg0, 600 const Arg1& rArg1, 601 const Arg2& rArg2, 602 const Arg3& rArg3, 603 const Arg4& rArg4, 604 const Arg5& rArg5, 605 const Arg6& rArg6, 606 const char* pStr, 607 const ::com::sun::star::uno::Reference< 608 ::com::sun::star::uno::XInterface >& xIf ) 609 { 610 verifyInput( rArg0, pStr, xIf, 0 ); 611 verifyInput( rArg1, pStr, xIf, 1 ); 612 verifyInput( rArg2, pStr, xIf, 2 ); 613 verifyInput( rArg3, pStr, xIf, 3 ); 614 verifyInput( rArg4, pStr, xIf, 4 ); 615 verifyInput( rArg5, pStr, xIf, 5 ); 616 verifyInput( rArg6, pStr, xIf, 6 ); 617 } 618 619 620 /** Range checker, which throws ::com::sun::star::lang::IllegalArgument exception, when 621 range is violated 622 */ verifyRange(NumType arg,NumType lowerBound,NumType upperBound)623 template< typename NumType > inline void verifyRange( NumType arg, NumType lowerBound, NumType upperBound ) 624 { 625 if( arg < lowerBound || 626 arg > upperBound ) 627 { 628 throw ::com::sun::star::lang::IllegalArgumentException(); 629 } 630 } 631 632 /** Range checker, which throws ::com::sun::star::lang::IllegalArgument exception, when 633 range is violated 634 635 The checked range is half open, i.e. only bound by the specified value. 636 637 @param arg 638 Arg to check 639 640 @param bound 641 Bound to check against 642 643 @param bLowerBound 644 When true, given bound is the lower bound. When false, 645 given bound is the upper bound. 646 */ verifyRange(NumType arg,NumType bound,bool bLowerBound=true)647 template< typename NumType > inline void verifyRange( NumType arg, NumType bound, bool bLowerBound=true ) 648 { 649 if( (bLowerBound && arg < bound) || 650 (!bLowerBound && arg > bound) ) 651 { 652 throw ::com::sun::star::lang::IllegalArgumentException(); 653 } 654 } 655 656 /** Range checker, which throws ::com::sun::star::lang::IndexOutOfBounds exception, when 657 index range is violated 658 */ verifyIndexRange(NumType arg,NumType lowerBound,NumType upperBound)659 template< typename NumType > inline void verifyIndexRange( NumType arg, NumType lowerBound, NumType upperBound ) 660 { 661 if( arg < lowerBound || 662 arg > upperBound ) 663 { 664 throw ::com::sun::star::lang::IndexOutOfBoundsException(); 665 } 666 } 667 668 /** Range checker, which throws ::com::sun::star::lang::IndexOutOfBounds exception, when 669 index range is violated 670 671 @param rect 672 Rect to verify 673 674 @param size 675 Given rectangle must be within ((0,0), (size.Width, size.Height)) 676 */ 677 CANVASTOOLS_DLLPUBLIC void verifyIndexRange( const ::com::sun::star::geometry::IntegerRectangle2D& rect, 678 const ::com::sun::star::geometry::IntegerSize2D& size ); 679 680 /** Range checker, which throws ::com::sun::star::lang::IndexOutOfBounds exception, when 681 index range is violated 682 683 @param pos 684 Position to verify 685 686 @param size 687 Given position must be within ((0,0), (size.Width, size.Height)) 688 */ 689 CANVASTOOLS_DLLPUBLIC void verifyIndexRange( const ::com::sun::star::geometry::IntegerPoint2D& pos, 690 const ::com::sun::star::geometry::IntegerSize2D& size ); 691 692 /** Range checker, which throws ::com::sun::star::lang::IndexOutOfBounds exception, when 693 the size is negative or null 694 695 @param size 696 Size to verify 697 */ 698 CANVASTOOLS_DLLPUBLIC void verifyBitmapSize( const ::com::sun::star::geometry::IntegerSize2D& size, 699 const char* pStr, 700 const ::com::sun::star::uno::Reference< 701 ::com::sun::star::uno::XInterface >& xIf ); 702 703 /** Range checker, which throws ::com::sun::star::lang::IndexOutOfBounds exception, when 704 the size is negative or null 705 706 @param size 707 Size to verify 708 */ 709 CANVASTOOLS_DLLPUBLIC void verifySpriteSize( const ::com::sun::star::geometry::RealSize2D& size, 710 const char* pStr, 711 const ::com::sun::star::uno::Reference< 712 ::com::sun::star::uno::XInterface >& xIf ); 713 } 714 } 715 716 #endif /* INCLUDED_CANVAS_VERIFYINPUT_HXX */ 717 // eof 718