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-17 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         250 :         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         316 :             ImpStrokeAttribute(
      40             :                 const ::std::vector< double >& rDotDashArray,
      41             :                 double fFullDotDashLen)
      42             :             :   mnRefCount(0),
      43             :                 maDotDashArray(rDotDashArray),
      44         316 :                 mfFullDotDashLen(fFullDotDashLen)
      45             :             {
      46         316 :             }
      47             : 
      48             :             // data read access
      49          52 :             const ::std::vector< double >& getDotDashArray() const { return maDotDashArray; }
      50         278 :             double getFullDotDashLen() const
      51             :             {
      52         278 :                 if(0.0 == mfFullDotDashLen && maDotDashArray.size())
      53             :                 {
      54             :                     // calculate length on demand
      55          24 :                     const double fAccumulated(::std::accumulate(maDotDashArray.begin(), maDotDashArray.end(), 0.0));
      56          24 :                     const_cast< ImpStrokeAttribute* >(this)->mfFullDotDashLen = fAccumulated;
      57             :                 }
      58             : 
      59         278 :                 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         242 :             static ImpStrokeAttribute* get_global_default()
      69             :             {
      70             :                 static ImpStrokeAttribute* pDefault = 0;
      71             : 
      72         242 :                 if(!pDefault)
      73             :                 {
      74             :                     pDefault = new ImpStrokeAttribute(
      75             :                         std::vector< double >(),
      76          26 :                         0.0);
      77             : 
      78             :                     // never delete; start with RefCount 1, not 0
      79          26 :                     pDefault->mnRefCount++;
      80             :                 }
      81             : 
      82         242 :                 return pDefault;
      83             :             }
      84             :         };
      85             : 
      86         290 :         StrokeAttribute::StrokeAttribute(
      87             :             const ::std::vector< double >& rDotDashArray,
      88             :             double fFullDotDashLen)
      89             :         :   mpStrokeAttribute(new ImpStrokeAttribute(
      90         290 :                 rDotDashArray, fFullDotDashLen))
      91             :         {
      92         290 :         }
      93             : 
      94          46 :         StrokeAttribute::StrokeAttribute()
      95          46 :         :   mpStrokeAttribute(ImpStrokeAttribute::get_global_default())
      96             :         {
      97          46 :             mpStrokeAttribute->mnRefCount++;
      98          46 :         }
      99             : 
     100         338 :         StrokeAttribute::StrokeAttribute(const StrokeAttribute& rCandidate)
     101         338 :         :   mpStrokeAttribute(rCandidate.mpStrokeAttribute)
     102             :         {
     103         338 :             mpStrokeAttribute->mnRefCount++;
     104         338 :         }
     105             : 
     106         602 :         StrokeAttribute::~StrokeAttribute()
     107             :         {
     108         602 :             if(mpStrokeAttribute->mnRefCount)
     109             :             {
     110         352 :                 mpStrokeAttribute->mnRefCount--;
     111             :             }
     112             :             else
     113             :             {
     114         250 :                 delete mpStrokeAttribute;
     115             :             }
     116         602 :         }
     117             : 
     118         196 :         bool StrokeAttribute::isDefault() const
     119             :         {
     120         196 :             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          52 :         const ::std::vector< double >& StrokeAttribute::getDotDashArray() const
     159             :         {
     160          52 :             return mpStrokeAttribute->getDotDashArray();
     161             :         }
     162             : 
     163         278 :         double StrokeAttribute::getFullDotDashLen() const
     164             :         {
     165         278 :             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