LCOV - code coverage report
Current view: top level - libreoffice/drawinglayer/source/attribute - strokeattribute.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 37 54 68.5 %
Date: 2012-12-27 Functions: 12 15 80.0 %
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             : #include <drawinglayer/attribute/strokeattribute.hxx>
      21             : #include <numeric>
      22             : 
      23             : //////////////////////////////////////////////////////////////////////////////
      24             : 
      25             : namespace drawinglayer
      26             : {
      27             :     namespace attribute
      28             :     {
      29         126 :         class ImpStrokeAttribute
      30             :         {
      31             :         public:
      32             :             // refcounter
      33             :             sal_uInt32                              mnRefCount;
      34             : 
      35             :             // data definitions
      36             :             ::std::vector< double >                     maDotDashArray;         // array of double which defines the dot-dash pattern
      37             :             double                                      mfFullDotDashLen;       // sum of maDotDashArray (for convenience)
      38             : 
      39         157 :             ImpStrokeAttribute(
      40             :                 const ::std::vector< double >& rDotDashArray,
      41             :                 double fFullDotDashLen)
      42             :             :   mnRefCount(0),
      43             :                 maDotDashArray(rDotDashArray),
      44         157 :                 mfFullDotDashLen(fFullDotDashLen)
      45             :             {
      46         157 :             }
      47             : 
      48             :             // data read access
      49          20 :             const ::std::vector< double >& getDotDashArray() const { return maDotDashArray; }
      50         125 :             double getFullDotDashLen() const
      51             :             {
      52         125 :                 if(0.0 == mfFullDotDashLen && maDotDashArray.size())
      53             :                 {
      54             :                     // calculate length on demand
      55           8 :                     const double fAccumulated(::std::accumulate(maDotDashArray.begin(), maDotDashArray.end(), 0.0));
      56           8 :                     const_cast< ImpStrokeAttribute* >(this)->mfFullDotDashLen = fAccumulated;
      57             :                 }
      58             : 
      59         125 :                 return mfFullDotDashLen;
      60             :             }
      61             : 
      62           0 :             bool operator==(const ImpStrokeAttribute& rCandidate) const
      63             :             {
      64           0 :                 return (getDotDashArray() == rCandidate.getDotDashArray()
      65           0 :                     && getFullDotDashLen() == rCandidate.getFullDotDashLen());
      66             :             }
      67             : 
      68         117 :             static ImpStrokeAttribute* get_global_default()
      69             :             {
      70             :                 static ImpStrokeAttribute* pDefault = 0;
      71             : 
      72         117 :                 if(!pDefault)
      73             :                 {
      74             :                     pDefault = new ImpStrokeAttribute(
      75             :                         std::vector< double >(),
      76          12 :                         0.0);
      77             : 
      78             :                     // never delete; start with RefCount 1, not 0
      79          12 :                     pDefault->mnRefCount++;
      80             :                 }
      81             : 
      82         117 :                 return pDefault;
      83             :             }
      84             :         };
      85             : 
      86         145 :         StrokeAttribute::StrokeAttribute(
      87             :             const ::std::vector< double >& rDotDashArray,
      88             :             double fFullDotDashLen)
      89             :         :   mpStrokeAttribute(new ImpStrokeAttribute(
      90         145 :                 rDotDashArray, fFullDotDashLen))
      91             :         {
      92         145 :         }
      93             : 
      94          23 :         StrokeAttribute::StrokeAttribute()
      95          23 :         :   mpStrokeAttribute(ImpStrokeAttribute::get_global_default())
      96             :         {
      97          23 :             mpStrokeAttribute->mnRefCount++;
      98          23 :         }
      99             : 
     100         165 :         StrokeAttribute::StrokeAttribute(const StrokeAttribute& rCandidate)
     101         165 :         :   mpStrokeAttribute(rCandidate.mpStrokeAttribute)
     102             :         {
     103         165 :             mpStrokeAttribute->mnRefCount++;
     104         165 :         }
     105             : 
     106         299 :         StrokeAttribute::~StrokeAttribute()
     107             :         {
     108         299 :             if(mpStrokeAttribute->mnRefCount)
     109             :             {
     110         173 :                 mpStrokeAttribute->mnRefCount--;
     111             :             }
     112             :             else
     113             :             {
     114         126 :                 delete mpStrokeAttribute;
     115             :             }
     116         299 :         }
     117             : 
     118          94 :         bool StrokeAttribute::isDefault() const
     119             :         {
     120          94 :             return mpStrokeAttribute == ImpStrokeAttribute::get_global_default();
     121             :         }
     122             : 
     123           0 :         StrokeAttribute& StrokeAttribute::operator=(const StrokeAttribute& rCandidate)
     124             :         {
     125           0 :             if(rCandidate.mpStrokeAttribute != mpStrokeAttribute)
     126             :             {
     127           0 :                 if(mpStrokeAttribute->mnRefCount)
     128             :                 {
     129           0 :                     mpStrokeAttribute->mnRefCount--;
     130             :                 }
     131             :                 else
     132             :                 {
     133           0 :                     delete mpStrokeAttribute;
     134             :                 }
     135             : 
     136           0 :                 mpStrokeAttribute = rCandidate.mpStrokeAttribute;
     137           0 :                 mpStrokeAttribute->mnRefCount++;
     138             :             }
     139             : 
     140           0 :             return *this;
     141             :         }
     142             : 
     143           0 :         bool StrokeAttribute::operator==(const StrokeAttribute& rCandidate) const
     144             :         {
     145           0 :             if(rCandidate.mpStrokeAttribute == mpStrokeAttribute)
     146             :             {
     147           0 :                 return true;
     148             :             }
     149             : 
     150           0 :             if(rCandidate.isDefault() != isDefault())
     151             :             {
     152           0 :                 return false;
     153             :             }
     154             : 
     155           0 :             return (*rCandidate.mpStrokeAttribute == *mpStrokeAttribute);
     156             :         }
     157             : 
     158          20 :         const ::std::vector< double >& StrokeAttribute::getDotDashArray() const
     159             :         {
     160          20 :             return mpStrokeAttribute->getDotDashArray();
     161             :         }
     162             : 
     163         125 :         double StrokeAttribute::getFullDotDashLen() const
     164             :         {
     165         125 :             return mpStrokeAttribute->getFullDotDashLen();
     166             :         }
     167             :     } // end of namespace attribute
     168             : } // end of namespace drawinglayer
     169             : 
     170             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10