LCOV - code coverage report
Current view: top level - drawinglayer/source/attribute - strokeattribute.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 39 40 97.5 %
Date: 2015-06-13 12:38:46 Functions: 16 16 100.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 <rtl/instance.hxx>
      22             : #include <numeric>
      23             : 
      24             : 
      25             : 
      26             : namespace drawinglayer
      27             : {
      28             :     namespace attribute
      29             :     {
      30      110779 :         class ImpStrokeAttribute
      31             :         {
      32             :         public:
      33             :             // data definitions
      34             :             ::std::vector< double >                     maDotDashArray;         // array of double which defines the dot-dash pattern
      35             :             double                                      mfFullDotDashLen;       // sum of maDotDashArray (for convenience)
      36             : 
      37       37068 :             ImpStrokeAttribute(
      38             :                 const ::std::vector< double >& rDotDashArray,
      39             :                 double fFullDotDashLen)
      40             :             :   maDotDashArray(rDotDashArray),
      41       37068 :                 mfFullDotDashLen(fFullDotDashLen)
      42             :             {
      43       37068 :             }
      44             : 
      45          69 :             ImpStrokeAttribute()
      46             :             :   maDotDashArray(std::vector< double >()),
      47          69 :                 mfFullDotDashLen(0.0)
      48             :             {
      49          69 :             }
      50             : 
      51             :             // data read access
      52        5107 :             const ::std::vector< double >& getDotDashArray() const { return maDotDashArray; }
      53       55576 :             double getFullDotDashLen() const
      54             :             {
      55       55576 :                 if(0.0 == mfFullDotDashLen && maDotDashArray.size())
      56             :                 {
      57             :                     // calculate length on demand
      58         615 :                     const double fAccumulated(::std::accumulate(maDotDashArray.begin(), maDotDashArray.end(), 0.0));
      59         615 :                     const_cast< ImpStrokeAttribute* >(this)->mfFullDotDashLen = fAccumulated;
      60             :                 }
      61             : 
      62       55576 :                 return mfFullDotDashLen;
      63             :             }
      64             : 
      65          39 :             bool operator==(const ImpStrokeAttribute& rCandidate) const
      66             :             {
      67          39 :                 return (getDotDashArray() == rCandidate.getDotDashArray()
      68          39 :                     && getFullDotDashLen() == rCandidate.getFullDotDashLen());
      69             :             }
      70             :         };
      71             : 
      72             :         namespace
      73             :         {
      74             :             struct theGlobalDefault :
      75             :                 public rtl::Static< StrokeAttribute::ImplType, theGlobalDefault > {};
      76             :         }
      77             : 
      78       37068 :         StrokeAttribute::StrokeAttribute(
      79             :             const ::std::vector< double >& rDotDashArray,
      80             :             double fFullDotDashLen)
      81             :         :   mpStrokeAttribute(ImpStrokeAttribute(
      82       37068 :                 rDotDashArray, fFullDotDashLen))
      83             :         {
      84       37068 :         }
      85             : 
      86        5593 :         StrokeAttribute::StrokeAttribute()
      87        5593 :         :   mpStrokeAttribute(theGlobalDefault::get())
      88             :         {
      89        5593 :         }
      90             : 
      91       41837 :         StrokeAttribute::StrokeAttribute(const StrokeAttribute& rCandidate)
      92       41837 :         :   mpStrokeAttribute(rCandidate.mpStrokeAttribute)
      93             :         {
      94       41837 :         }
      95             : 
      96       84004 :         StrokeAttribute::~StrokeAttribute()
      97             :         {
      98       84004 :         }
      99             : 
     100       50254 :         bool StrokeAttribute::isDefault() const
     101             :         {
     102       50254 :             return mpStrokeAttribute.same_object(theGlobalDefault::get());
     103             :         }
     104             : 
     105         627 :         StrokeAttribute& StrokeAttribute::operator=(const StrokeAttribute& rCandidate)
     106             :         {
     107         627 :             mpStrokeAttribute = rCandidate.mpStrokeAttribute;
     108         627 :             return *this;
     109             :         }
     110             : 
     111          42 :         bool StrokeAttribute::operator==(const StrokeAttribute& rCandidate) const
     112             :         {
     113             :             // tdf#87509 default attr is always != non-default attr, even with same values
     114          42 :             if(rCandidate.isDefault() != isDefault())
     115           0 :                 return false;
     116             : 
     117          42 :             return rCandidate.mpStrokeAttribute == mpStrokeAttribute;
     118             :         }
     119             : 
     120        5029 :         const ::std::vector< double >& StrokeAttribute::getDotDashArray() const
     121             :         {
     122        5029 :             return mpStrokeAttribute->getDotDashArray();
     123             :         }
     124             : 
     125       55498 :         double StrokeAttribute::getFullDotDashLen() const
     126             :         {
     127       55498 :             return mpStrokeAttribute->getFullDotDashLen();
     128             :         }
     129             :     } // end of namespace attribute
     130             : } // end of namespace drawinglayer
     131             : 
     132             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11