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