bump product version to 4.1.6.2
[LibreOffice.git] / fpicker / source / win32 / misc / AutoBuffer.cxx
blob17162e3c479bdb4cdbf300ff3064c6729e801294
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 #include "AutoBuffer.hxx"
21 #include <osl/diagnose.h>
23 #if defined _MSC_VER
24 #pragma warning(push, 1)
25 #endif
26 #include <windows.h>
27 #if defined _MSC_VER
28 #pragma warning(pop)
29 #endif
31 //------------------------------------------------------------------------
32 // namespace directives
33 //------------------------------------------------------------------------
36 //------------------------------------------------------------------------
38 //------------------------------------------------------------------------
40 CAutoUnicodeBuffer::CAutoUnicodeBuffer( size_t nSize, sal_Bool bLazyCreation ) :
41 m_buffSize( nSize ),
42 m_pBuff( NULL )
44 if ( !bLazyCreation )
45 init( );
48 //------------------------------------------------------------------------
50 //------------------------------------------------------------------------
52 CAutoUnicodeBuffer::~CAutoUnicodeBuffer( )
54 delete [] m_pBuff;
57 //------------------------------------------------------------------------
59 //------------------------------------------------------------------------
61 sal_Bool SAL_CALL CAutoUnicodeBuffer::resize( size_t new_size )
63 if ( new_size != m_buffSize )
65 if ( new_size > m_buffSize )
67 delete [] m_pBuff;
68 m_pBuff = NULL;
71 m_buffSize = new_size;
74 return sal_True;
77 //------------------------------------------------------------------------
79 //------------------------------------------------------------------------
81 void SAL_CALL CAutoUnicodeBuffer::empty( )
83 if ( m_pBuff )
84 ZeroMemory( m_pBuff, m_buffSize * sizeof( sal_Unicode ) );
87 //------------------------------------------------------------------------
89 //------------------------------------------------------------------------
91 sal_Bool SAL_CALL CAutoUnicodeBuffer::fill( const sal_Unicode* pContent, size_t nLen )
93 OSL_ASSERT( pContent && m_buffSize && (m_buffSize >= nLen) );
95 init( );
97 sal_Bool bRet = sal_False;
99 if ( m_pBuff && pContent && nLen )
101 CopyMemory( m_pBuff, pContent, nLen * sizeof( sal_Unicode ) );
102 bRet = sal_True;
105 return bRet;
108 //------------------------------------------------------------------------
110 //------------------------------------------------------------------------
112 size_t SAL_CALL CAutoUnicodeBuffer::size( ) const
114 return m_buffSize;
117 //------------------------------------------------------------------------
119 //------------------------------------------------------------------------
121 CAutoUnicodeBuffer::operator sal_Unicode*( )
123 return m_pBuff;
126 //------------------------------------------------------------------------
128 //------------------------------------------------------------------------
130 sal_Unicode* CAutoUnicodeBuffer::operator&( )
132 return m_pBuff;
135 //------------------------------------------------------------------------
137 //------------------------------------------------------------------------
139 const sal_Unicode* CAutoUnicodeBuffer::operator&( ) const
141 return m_pBuff;
144 //------------------------------------------------------------------------
146 //------------------------------------------------------------------------
148 void SAL_CALL CAutoUnicodeBuffer::init( )
150 if ( !m_pBuff && (m_buffSize > 0) )
151 m_pBuff = new sal_Unicode[ m_buffSize ];
153 empty( );
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */