LCOV - code coverage report
Current view: top level - basegfx/inc/basegfx/tuple - b2ituple.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 20 40 50.0 %
Date: 2012-08-25 Functions: 7 12 58.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef _BGFX_TUPLE_B2ITUPLE_HXX
      30                 :            : #define _BGFX_TUPLE_B2ITUPLE_HXX
      31                 :            : 
      32                 :            : #include <sal/types.h>
      33                 :            : #include <basegfx/basegfxdllapi.h>
      34                 :            : 
      35                 :            : namespace basegfx
      36                 :            : {
      37                 :            :     /** Base class for all Points/Vectors with two sal_Int32 values
      38                 :            : 
      39                 :            :         This class provides all methods common to Point
      40                 :            :         avd Vector classes which are derived from here.
      41                 :            : 
      42                 :            :         @derive Use this class to implement Points or Vectors
      43                 :            :         which are based on two sal_Int32 values
      44                 :            :     */
      45                 :            :     class BASEGFX_DLLPUBLIC B2ITuple
      46                 :            :     {
      47                 :            :     protected:
      48                 :            :         sal_Int32                                       mnX;
      49                 :            :         sal_Int32                                       mnY;
      50                 :            : 
      51                 :            :     public:
      52                 :            :         /** Create a 2D Tuple
      53                 :            : 
      54                 :            :             The tuple is initialized to (0, 0)
      55                 :            :         */
      56                 :            :         B2ITuple()
      57                 :            :         :   mnX(0),
      58                 :            :             mnY(0)
      59                 :            :         {}
      60                 :            : 
      61                 :            :         /** Create a 2D Tuple
      62                 :            : 
      63                 :            :             @param fX
      64                 :            :             This parameter is used to initialize the X-coordinate
      65                 :            :             of the 2D Tuple.
      66                 :            : 
      67                 :            :             @param fY
      68                 :            :             This parameter is used to initialize the Y-coordinate
      69                 :            :             of the 2D Tuple.
      70                 :            :         */
      71                 :    2893124 :         B2ITuple(sal_Int32 fX, sal_Int32 fY)
      72                 :            :         :   mnX( fX ),
      73                 :    2893124 :             mnY( fY )
      74                 :    2893124 :         {}
      75                 :            : 
      76                 :            :         /** Create a copy of a 2D Tuple
      77                 :            : 
      78                 :            :             @param rTup
      79                 :            :             The 2D Tuple which will be copied.
      80                 :            :         */
      81                 :   16107670 :         B2ITuple(const B2ITuple& rTup)
      82                 :            :         :   mnX( rTup.mnX ),
      83                 :   16107670 :             mnY( rTup.mnY )
      84                 :   16107670 :         {}
      85                 :            : 
      86                 :         10 :         ~B2ITuple()
      87                 :         10 :         {}
      88                 :            : 
      89                 :            :         /// Get X-Coordinate of 2D Tuple
      90                 :         10 :         sal_Int32 getX() const
      91                 :            :         {
      92                 :         10 :             return mnX;
      93                 :            :         }
      94                 :            : 
      95                 :            :         /// Get Y-Coordinate of 2D Tuple
      96                 :         10 :         sal_Int32 getY() const
      97                 :            :         {
      98                 :         10 :             return mnY;
      99                 :            :         }
     100                 :            : 
     101                 :            :         /// Set X-Coordinate of 2D Tuple
     102                 :            :         void setX(sal_Int32 fX)
     103                 :            :         {
     104                 :            :             mnX = fX;
     105                 :            :         }
     106                 :            : 
     107                 :            :         /// Set Y-Coordinate of 2D Tuple
     108                 :            :         void setY(sal_Int32 fY)
     109                 :            :         {
     110                 :            :             mnY = fY;
     111                 :            :         }
     112                 :            : 
     113                 :            :         /// Array-access to 2D Tuple
     114                 :            :         const sal_Int32& operator[] (int nPos) const
     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                 :            :         /// Array-access to 2D Tuple
     123                 :            :         sal_Int32& operator[] (int nPos)
     124                 :            :         {
     125                 :            :             // Here, normally one if(...) should be used. In the assumption that
     126                 :            :             // both sal_Int32 members can be accessed as an array a shortcut is used here.
     127                 :            :             // if(0 == nPos) return mnX; return mnY;
     128                 :            :             return *((&mnX) + nPos);
     129                 :            :         }
     130                 :            : 
     131                 :            :         // operators
     132                 :            :         //////////////////////////////////////////////////////////////////////
     133                 :            : 
     134                 :    6748664 :         B2ITuple& operator+=( const B2ITuple& rTup )
     135                 :            :         {
     136                 :    6748664 :             mnX += rTup.mnX;
     137                 :    6748664 :             mnY += rTup.mnY;
     138                 :    6748664 :             return *this;
     139                 :            :         }
     140                 :            : 
     141                 :    9359006 :         B2ITuple& operator-=( const B2ITuple& rTup )
     142                 :            :         {
     143                 :    9359006 :             mnX -= rTup.mnX;
     144                 :    9359006 :             mnY -= rTup.mnY;
     145                 :    9359006 :             return *this;
     146                 :            :         }
     147                 :            : 
     148                 :          0 :         B2ITuple& operator/=( const B2ITuple& rTup )
     149                 :            :         {
     150                 :          0 :             mnX /= rTup.mnX;
     151                 :          0 :             mnY /= rTup.mnY;
     152                 :          0 :             return *this;
     153                 :            :         }
     154                 :            : 
     155                 :          0 :         B2ITuple& operator*=( const B2ITuple& rTup )
     156                 :            :         {
     157                 :          0 :             mnX *= rTup.mnX;
     158                 :          0 :             mnY *= rTup.mnY;
     159                 :          0 :             return *this;
     160                 :            :         }
     161                 :            : 
     162                 :          0 :         B2ITuple& operator*=(sal_Int32 t)
     163                 :            :         {
     164                 :          0 :             mnX *= t;
     165                 :          0 :             mnY *= t;
     166                 :          0 :             return *this;
     167                 :            :         }
     168                 :            : 
     169                 :          0 :         B2ITuple& operator/=(sal_Int32 t)
     170                 :            :         {
     171                 :          0 :             mnX /= t;
     172                 :          0 :             mnY /= t;
     173                 :          0 :             return *this;
     174                 :            :         }
     175                 :            : 
     176                 :            :         B2ITuple operator-(void) const
     177                 :            :         {
     178                 :            :             return B2ITuple(-mnX, -mnY);
     179                 :            :         }
     180                 :            : 
     181                 :            :         bool equalZero() const { return mnX == 0 && mnY == 0; }
     182                 :            : 
     183                 :            :         bool operator==( const B2ITuple& rTup ) const
     184                 :            :         {
     185                 :            :             return this == &rTup || (rTup.mnX == mnX && rTup.mnY == mnY);
     186                 :            :         }
     187                 :            : 
     188                 :            :         bool operator!=( const B2ITuple& rTup ) const
     189                 :            :         {
     190                 :            :             return !(*this == rTup);
     191                 :            :         }
     192                 :            : 
     193                 :          0 :         B2ITuple& operator=( const B2ITuple& rTup )
     194                 :            :         {
     195                 :          0 :             mnX = rTup.mnX;
     196                 :          0 :             mnY = rTup.mnY;
     197                 :          0 :             return *this;
     198                 :            :         }
     199                 :            :     };
     200                 :            : 
     201                 :            :     // external operators
     202                 :            :     //////////////////////////////////////////////////////////////////////////
     203                 :            :     class B2DTuple;
     204                 :            : 
     205                 :            :     BASEGFX_DLLPUBLIC B2ITuple operator+(const B2ITuple& rTupA, const B2ITuple& rTupB);
     206                 :            :     BASEGFX_DLLPUBLIC B2ITuple operator-(const B2ITuple& rTupA, const B2ITuple& rTupB);
     207                 :            :     BASEGFX_DLLPUBLIC B2ITuple operator/(const B2ITuple& rTupA, const B2ITuple& rTupB);
     208                 :            :     BASEGFX_DLLPUBLIC B2ITuple operator*(const B2ITuple& rTupA, const B2ITuple& rTupB);
     209                 :            :     BASEGFX_DLLPUBLIC B2ITuple operator*(const B2ITuple& rTup, sal_Int32 t);
     210                 :            :     BASEGFX_DLLPUBLIC B2ITuple operator*(sal_Int32 t, const B2ITuple& rTup);
     211                 :            :     BASEGFX_DLLPUBLIC B2ITuple operator/(const B2ITuple& rTup, sal_Int32 t);
     212                 :            :     BASEGFX_DLLPUBLIC B2ITuple operator/(sal_Int32 t, const B2ITuple& rTup);
     213                 :            : } // end of namespace basegfx
     214                 :            : 
     215                 :            : #endif /* _BGFX_TUPLE_B2ITUPLE_HXX */
     216                 :            : 
     217                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10