bump product version to 4.1.6.2
[LibreOffice.git] / include / cosv / stringdata.hxx
blob0187cb4265a920fb5143ac8e9641826d16a23ebb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef COSV_STRINGDATA_HXX
21 #define COSV_STRINGDATA_HXX
24 #include <cosv/str_types.hxx>
28 namespace csv
31 /** @tpl CHAR
32 The expression CHAR(0) has to be valid.
34 template <class CHAR>
35 class StringData
37 public:
38 typedef StringData self;
40 typedef str::size size_type;
41 typedef str::position position_type;
43 // LIFECYCLE
44 StringData();
45 /** @precond i_pData != 0
46 @precond i_nValidLength <= strlen(i_pData)
48 StringData(
49 const CHAR * i_pData,
50 size_type i_nValidLength );
51 ~StringData();
52 // OPERATORS
54 // OPERATIONS
56 // INQUIRY
57 const CHAR * Data() const;
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.
64 size_type Size() const;
66 private:
67 /* Because this is used only within a refcounted structure,
68 these functions are forbidden - at least yet.
70 StringData(const self&);
71 self & operator=(const self&);
73 // DATA
74 DYN CHAR * dpData;
75 size_type nSize; /// The allocated size - 1 (for the finishing 0).
80 // IMPLEMENTATION
82 template <class CHAR>
83 StringData<CHAR>::StringData()
84 : dpData( new CHAR[1] ),
85 nSize(0)
87 *dpData = CHAR(0);
90 template <class CHAR>
91 StringData<CHAR>::StringData( const CHAR * i_pData,
92 size_type i_nValidLength )
93 : dpData( new CHAR[i_nValidLength + 1] ),
94 nSize(i_nValidLength)
96 memcpy( dpData, i_pData, i_nValidLength * sizeof(CHAR) );
97 dpData[nSize] = CHAR(0);
100 template <class CHAR>
101 StringData<CHAR>::~StringData()
103 delete [] dpData;
106 template <class CHAR>
107 const CHAR *
108 StringData<CHAR>::Data() const
110 return dpData;
113 template <class CHAR>
114 typename StringData<CHAR>::size_type
115 StringData<CHAR>::Size() const
117 return nSize;
122 } // namespace csv
125 #endif
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */