LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/cosv - stringdata.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 12 12 100.0 %
Date: 2012-12-27 Functions: 4 4 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             : #ifndef COSV_STRINGDATA_HXX
      21             : #define COSV_STRINGDATA_HXX
      22             : 
      23             : 
      24             : #include <cosv/str_types.hxx>
      25             : 
      26             : 
      27             : 
      28             : namespace csv
      29             : {
      30             : 
      31             : /** @tpl CHAR
      32             :     The expression CHAR(0) has to be valid.
      33             : */
      34             : template <class CHAR>
      35             : class StringData
      36             : {
      37             :   public:
      38             :     typedef StringData          self;
      39             : 
      40             :     typedef str::size           size_type;
      41             :     typedef str::position       position_type;
      42             : 
      43             :     // LIFECYCLE
      44             :                         StringData();
      45             :     /** @precond i_pData != 0
      46             :         @precond i_nValidLength <= strlen(i_pData)
      47             :     */
      48             :                         StringData(
      49             :                             const CHAR *        i_pData,
      50             :                             size_type           i_nValidLength );
      51             :                         ~StringData();
      52             :     // OPERATORS
      53             : 
      54             :     // OPERATIONS
      55             : 
      56             :     // INQUIRY
      57             :     const CHAR *        Data() const;
      58             : 
      59             :     /** @returns the allocated number of CHAR.
      60             :         This may be different from the number of bytes.
      61             :         There is actually allocated one more CHAR,
      62             :         which is guaranteed to be CHAR(0) in all circumstances.
      63             :     */
      64             :     size_type           Size() const;
      65             : 
      66             :   private:
      67             :     /*  Because this is used only within a refcounted structure,
      68             :         these functions are forbidden - at least yet.
      69             :     */
      70             :                         StringData(const self&);
      71             :     self &              operator=(const self&);
      72             : 
      73             :     // DATA
      74             :     DYN CHAR *          dpData;
      75             :     size_type           nSize;      /// The allocated size - 1 (for the finishing 0).
      76             : };
      77             : 
      78             : 
      79             : 
      80             : // IMPLEMENTATION
      81             : 
      82             : template <class CHAR>
      83             : StringData<CHAR>::StringData()
      84             :     :   dpData( new CHAR[1] ),
      85             :         nSize(0)
      86             : {
      87             :     *dpData = CHAR(0);
      88             : }
      89             : 
      90             : template <class CHAR>
      91     6071876 : StringData<CHAR>::StringData( const CHAR *        i_pData,
      92             :                               size_type           i_nValidLength )
      93             :     :   dpData( new CHAR[i_nValidLength + 1] ),
      94     6071876 :         nSize(i_nValidLength)
      95             : {
      96     6071876 :     memcpy( dpData, i_pData, i_nValidLength * sizeof(CHAR) );
      97     6071876 :     dpData[nSize] = CHAR(0);
      98     6071876 : }
      99             : 
     100             : template <class CHAR>
     101     5851329 : StringData<CHAR>::~StringData()
     102             : {
     103     5851329 :     delete [] dpData;
     104     5851329 : }
     105             : 
     106             : template <class CHAR>
     107             : const CHAR *
     108    21021689 : StringData<CHAR>::Data() const
     109             : {
     110    21021689 :     return dpData;
     111             : }
     112             : 
     113             : template <class CHAR>
     114             : typename StringData<CHAR>::size_type
     115    12878984 : StringData<CHAR>::Size() const
     116             : {
     117    12878984 :     return nSize;
     118             : }
     119             : 
     120             : 
     121             : 
     122             : }   // namespace csv
     123             : 
     124             : 
     125             : #endif
     126             : 
     127             : 
     128             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10