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 #ifndef _AUTO_BUFFER_HXX_
25 #define _AUTO_BUFFER_HXX_
26 
27 //------------------------------------------------------------------------
28 // includes
29 //------------------------------------------------------------------------
30 
31 #include <sal/types.h>
32 
33 #ifndef _RTL_USTRING_HXX_
34 #include <rtl/ustring>
35 #endif
36 
37 //-------------------------------------------------------------
38 // A simple unicode buffer management class, the class itself
39 // is responsible for the allocated unicode buffer, any
40 // modification of the buffer size outside the class may lead
41 // to undefined behaviour
42 //-------------------------------------------------------------
43 
44 class CAutoUnicodeBuffer
45 {
46 public:
47 
48 	// if bLazyCreation is true the buffer will be created
49 	// when someone wants to fill the buffer
50 	CAutoUnicodeBuffer( size_t size, sal_Bool bLazyCreation = sal_False );
51 	~CAutoUnicodeBuffer( );
52 
53 	// resizes the buffer
54 	sal_Bool SAL_CALL resize( size_t new_size );
55 
56 	// zeros the buffer
57 	void SAL_CALL empty( );
58 
59 	// fills the buffer with a given content
60 	sal_Bool SAL_CALL fill( const sal_Unicode* pContent, size_t nLen );
61 
62 	// returns the size of the buffer
63 	size_t SAL_CALL size( ) const;
64 
65 	// conversion operator
66 	operator sal_Unicode*( );
67 
68 	// address operator
69 	sal_Unicode* operator&( );
70 
71 	const sal_Unicode* operator&( ) const;
72 
73 private:
74 	void SAL_CALL init( );
75 
76 private:
77 	size_t m_buffSize; // the number of unicode chars
78 	sal_Unicode* m_pBuff;
79 };
80 
81 #endif
82