1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_fpicker.hxx"
26
27 //------------------------------------------------------------------------
28 // includes
29 //------------------------------------------------------------------------
30 #include "AutoBuffer.hxx"
31 #include <osl/diagnose.h>
32
33 #if defined _MSC_VER
34 #pragma warning(push, 1)
35 #endif
36 #include <windows.h>
37 #if defined _MSC_VER
38 #pragma warning(pop)
39 #endif
40
41 //------------------------------------------------------------------------
42 // namespace directives
43 //------------------------------------------------------------------------
44
45 using rtl::OUString;
46
47 //------------------------------------------------------------------------
48 //
49 //------------------------------------------------------------------------
50
CAutoUnicodeBuffer(size_t size,sal_Bool bLazyCreation)51 CAutoUnicodeBuffer::CAutoUnicodeBuffer( size_t size, sal_Bool bLazyCreation ) :
52 m_buffSize( size ),
53 m_pBuff( NULL )
54 {
55 if ( !bLazyCreation )
56 init( );
57 }
58
59 //------------------------------------------------------------------------
60 //
61 //------------------------------------------------------------------------
62
~CAutoUnicodeBuffer()63 CAutoUnicodeBuffer::~CAutoUnicodeBuffer( )
64 {
65 delete [] m_pBuff;
66 }
67
68 //------------------------------------------------------------------------
69 //
70 //------------------------------------------------------------------------
71
resize(size_t new_size)72 sal_Bool SAL_CALL CAutoUnicodeBuffer::resize( size_t new_size )
73 {
74 if ( new_size != m_buffSize )
75 {
76 if ( new_size > m_buffSize )
77 {
78 delete [] m_pBuff;
79 m_pBuff = NULL;
80 }
81
82 m_buffSize = new_size;
83 }
84
85 return sal_True;
86 }
87
88 //------------------------------------------------------------------------
89 //
90 //------------------------------------------------------------------------
91
empty()92 void SAL_CALL CAutoUnicodeBuffer::empty( )
93 {
94 if ( m_pBuff )
95 ZeroMemory( m_pBuff, m_buffSize * sizeof( sal_Unicode ) );
96 }
97
98 //------------------------------------------------------------------------
99 //
100 //------------------------------------------------------------------------
101
fill(const sal_Unicode * pContent,size_t nLen)102 sal_Bool SAL_CALL CAutoUnicodeBuffer::fill( const sal_Unicode* pContent, size_t nLen )
103 {
104 OSL_ASSERT( pContent && m_buffSize && (m_buffSize >= nLen) );
105
106 init( );
107
108 sal_Bool bRet = sal_False;
109
110 if ( m_pBuff && pContent && nLen )
111 {
112 CopyMemory( m_pBuff, pContent, nLen * sizeof( sal_Unicode ) );
113 bRet = sal_True;
114 }
115
116 return bRet;
117 }
118
119 //------------------------------------------------------------------------
120 //
121 //------------------------------------------------------------------------
122
size() const123 size_t SAL_CALL CAutoUnicodeBuffer::size( ) const
124 {
125 return m_buffSize;
126 }
127
128 //------------------------------------------------------------------------
129 //
130 //------------------------------------------------------------------------
131
operator sal_Unicode*()132 CAutoUnicodeBuffer::operator sal_Unicode*( )
133 {
134 return m_pBuff;
135 }
136
137 //------------------------------------------------------------------------
138 //
139 //------------------------------------------------------------------------
140
operator &()141 sal_Unicode* CAutoUnicodeBuffer::operator&( )
142 {
143 return m_pBuff;
144 }
145
146 //------------------------------------------------------------------------
147 //
148 //------------------------------------------------------------------------
149
operator &() const150 const sal_Unicode* CAutoUnicodeBuffer::operator&( ) const
151 {
152 return m_pBuff;
153 }
154
155 //------------------------------------------------------------------------
156 //
157 //------------------------------------------------------------------------
158
init()159 void SAL_CALL CAutoUnicodeBuffer::init( )
160 {
161 if ( !m_pBuff && (m_buffSize > 0) )
162 m_pBuff = new sal_Unicode[ m_buffSize ];
163
164 empty( );
165 }
166