LCOV - code coverage report
Current view: top level - libreoffice/basegfx/inc/basegfx/tuple - b2ituple.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 20 40 50.0 %
Date: 2012-12-17 Functions: 7 12 58.3 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : #ifndef _BGFX_TUPLE_B2ITUPLE_HXX
      21             : #define _BGFX_TUPLE_B2ITUPLE_HXX
      22             : 
      23             : #include <sal/types.h>
      24             : #include <basegfx/basegfxdllapi.h>
      25             : 
      26             : namespace basegfx
      27             : {
      28             :     /** Base class for all Points/Vectors with two sal_Int32 values
      29             : 
      30             :         This class provides all methods common to Point
      31             :         avd Vector classes which are derived from here.
      32             : 
      33             :         @derive Use this class to implement Points or Vectors
      34             :         which are based on two sal_Int32 values
      35             :     */
      36             :     class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED B2ITuple
      37             :     {
      38             :     protected:
      39             :         sal_Int32                                       mnX;
      40             :         sal_Int32                                       mnY;
      41             : 
      42             :     public:
      43             :         /** Create a 2D Tuple
      44             : 
      45             :             The tuple is initialized to (0, 0)
      46             :         */
      47             :         B2ITuple()
      48             :         :   mnX(0),
      49             :             mnY(0)
      50             :         {}
      51             : 
      52             :         /** Create a 2D Tuple
      53             : 
      54             :             @param fX
      55             :             This parameter is used to initialize the X-coordinate
      56             :             of the 2D Tuple.
      57             : 
      58             :             @param fY
      59             :             This parameter is used to initialize the Y-coordinate
      60             :             of the 2D Tuple.
      61             :         */
      62       65512 :         B2ITuple(sal_Int32 fX, sal_Int32 fY)
      63             :         :   mnX( fX ),
      64       65512 :             mnY( fY )
      65       65512 :         {}
      66             : 
      67             :         /** Create a copy of a 2D Tuple
      68             : 
      69             :             @param rTup
      70             :             The 2D Tuple which will be copied.
      71             :         */
      72      336652 :         B2ITuple(const B2ITuple& rTup)
      73             :         :   mnX( rTup.mnX ),
      74      336652 :             mnY( rTup.mnY )
      75      336652 :         {}
      76             : 
      77           4 :         ~B2ITuple()
      78           4 :         {}
      79             : 
      80             :         /// Get X-Coordinate of 2D Tuple
      81           4 :         sal_Int32 getX() const
      82             :         {
      83           4 :             return mnX;
      84             :         }
      85             : 
      86             :         /// Get Y-Coordinate of 2D Tuple
      87           4 :         sal_Int32 getY() const
      88             :         {
      89           4 :             return mnY;
      90             :         }
      91             : 
      92             :         /// Set X-Coordinate of 2D Tuple
      93             :         void setX(sal_Int32 fX)
      94             :         {
      95             :             mnX = fX;
      96             :         }
      97             : 
      98             :         /// Set Y-Coordinate of 2D Tuple
      99             :         void setY(sal_Int32 fY)
     100             :         {
     101             :             mnY = fY;
     102             :         }
     103             : 
     104             :         /// Array-access to 2D Tuple
     105             :         const sal_Int32& operator[] (int nPos) const
     106             :         {
     107             :             // Here, normally one if(...) should be used. In the assumption that
     108             :             // both sal_Int32 members can be accessed as an array a shortcut is used here.
     109             :             // if(0 == nPos) return mnX; return mnY;
     110             :             return *((&mnX) + nPos);
     111             :         }
     112             : 
     113             :         /// Array-access to 2D Tuple
     114             :         sal_Int32& operator[] (int nPos)
     115             :         {
     116             :             // Here, normally one if(...) should be used. In the assumption that
     117             :             // both sal_Int32 members can be accessed as an array a shortcut is used here.
     118             :             // if(0 == nPos) return mnX; return mnY;
     119             :             return *((&mnX) + nPos);
     120             :         }
     121             : 
     122             :         // operators
     123             :         //////////////////////////////////////////////////////////////////////
     124             : 
     125      156970 :         B2ITuple& operator+=( const B2ITuple& rTup )
     126             :         {
     127      156970 :             mnX += rTup.mnX;
     128      156970 :             mnY += rTup.mnY;
     129      156970 :             return *this;
     130             :         }
     131             : 
     132      179682 :         B2ITuple& operator-=( const B2ITuple& rTup )
     133             :         {
     134      179682 :             mnX -= rTup.mnX;
     135      179682 :             mnY -= rTup.mnY;
     136      179682 :             return *this;
     137             :         }
     138             : 
     139           0 :         B2ITuple& operator/=( const B2ITuple& rTup )
     140             :         {
     141           0 :             mnX /= rTup.mnX;
     142           0 :             mnY /= rTup.mnY;
     143           0 :             return *this;
     144             :         }
     145             : 
     146           0 :         B2ITuple& operator*=( const B2ITuple& rTup )
     147             :         {
     148           0 :             mnX *= rTup.mnX;
     149           0 :             mnY *= rTup.mnY;
     150           0 :             return *this;
     151             :         }
     152             : 
     153           0 :         B2ITuple& operator*=(sal_Int32 t)
     154             :         {
     155           0 :             mnX *= t;
     156           0 :             mnY *= t;
     157           0 :             return *this;
     158             :         }
     159             : 
     160           0 :         B2ITuple& operator/=(sal_Int32 t)
     161             :         {
     162           0 :             mnX /= t;
     163           0 :             mnY /= t;
     164           0 :             return *this;
     165             :         }
     166             : 
     167             :         B2ITuple operator-(void) const
     168             :         {
     169             :             return B2ITuple(-mnX, -mnY);
     170             :         }
     171             : 
     172             :         bool equalZero() const { return mnX == 0 && mnY == 0; }
     173             : 
     174             :         bool operator==( const B2ITuple& rTup ) const
     175             :         {
     176             :             return this == &rTup || (rTup.mnX == mnX && rTup.mnY == mnY);
     177             :         }
     178             : 
     179             :         bool operator!=( const B2ITuple& rTup ) const
     180             :         {
     181             :             return !(*this == rTup);
     182             :         }
     183             : 
     184           0 :         B2ITuple& operator=( const B2ITuple& rTup )
     185             :         {
     186           0 :             mnX = rTup.mnX;
     187           0 :             mnY = rTup.mnY;
     188           0 :             return *this;
     189             :         }
     190             :     };
     191             : 
     192             :     // external operators
     193             :     //////////////////////////////////////////////////////////////////////////
     194             :     class B2DTuple;
     195             : 
     196             :     BASEGFX_DLLPUBLIC B2ITuple operator+(const B2ITuple& rTupA, const B2ITuple& rTupB);
     197             :     BASEGFX_DLLPUBLIC B2ITuple operator-(const B2ITuple& rTupA, const B2ITuple& rTupB);
     198             :     BASEGFX_DLLPUBLIC B2ITuple operator/(const B2ITuple& rTupA, const B2ITuple& rTupB);
     199             :     BASEGFX_DLLPUBLIC B2ITuple operator*(const B2ITuple& rTupA, const B2ITuple& rTupB);
     200             :     BASEGFX_DLLPUBLIC B2ITuple operator*(const B2ITuple& rTup, sal_Int32 t);
     201             :     BASEGFX_DLLPUBLIC B2ITuple operator*(sal_Int32 t, const B2ITuple& rTup);
     202             :     BASEGFX_DLLPUBLIC B2ITuple operator/(const B2ITuple& rTup, sal_Int32 t);
     203             :     BASEGFX_DLLPUBLIC B2ITuple operator/(sal_Int32 t, const B2ITuple& rTup);
     204             : } // end of namespace basegfx
     205             : 
     206             : #endif /* _BGFX_TUPLE_B2ITUPLE_HXX */
     207             : 
     208             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10