Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / sal / osl / w32 / path_helper.hxx
blob3af00a52ac8ebcfde548db7e820e8d51030a4427
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 #ifdef _MSC_VER
21 #pragma warning (disable : 4800)
22 #endif
24 #ifndef _PATH_HELPER_HXX_
25 #define _PATH_HELPER_HXX_
27 #include "path_helper.h"
28 #include <rtl/ustring.hxx>
29 #include <rtl/allocator.hxx>
31 namespace osl
34 /*******************************************************************
35 osl_systemPathEnsureSeparator
36 Adds a trailing path separator to the given system path if not
37 already there and if the path is not the root path or a logical
38 drive alone
39 ******************************************************************/
41 inline void systemPathEnsureSeparator(/*inout*/ rtl::OUString& Path)
43 osl_systemPathEnsureSeparator(&Path.pData);
46 /*******************************************************************
47 osl_systemPathRemoveSeparator
48 Removes the last separator from the given system path if any and
49 if the path is not the root path '\'
50 ******************************************************************/
52 inline void systemPathRemoveSeparator(/*inout*/ rtl::OUString& Path)
54 osl_systemPathRemoveSeparator(&Path.pData);
57 /*******************************************************************
58 osl_systemPathIsLogicalDrivePattern
59 ******************************************************************/
61 inline bool systemPathIsLogicalDrivePattern(/*in*/ const rtl::OUString& path)
63 return osl_systemPathIsLogicalDrivePattern(path.pData);
66 /*******************************************************************
67 LongPathBuffer
68 ******************************************************************/
69 template< class T >
70 class LongPathBuffer
72 T* m_pBuffer;
73 sal_uInt32 m_nCharNum;
75 LongPathBuffer();
76 LongPathBuffer( const LongPathBuffer& );
77 LongPathBuffer& operator=( const LongPathBuffer& );
79 public:
80 LongPathBuffer( sal_uInt32 nCharNum )
81 : m_pBuffer( reinterpret_cast<T*>( rtl_allocateMemory( nCharNum * sizeof( T ) ) ) )
82 , m_nCharNum( nCharNum )
84 OSL_ENSURE( m_pBuffer, "Can not allocate the buffer!" );
87 ~LongPathBuffer()
89 if ( m_pBuffer )
90 rtl_freeMemory( m_pBuffer );
91 m_pBuffer = 0;
94 sal_uInt32 getBufSizeInSymbols()
96 return m_nCharNum;
99 operator T* ()
101 return m_pBuffer;
106 template< class U, class T > U mingw_reinterpret_cast(LongPathBuffer<T>& a) { return reinterpret_cast<U>(static_cast<T*>(a)); }
108 } // end namespace osl
110 #endif
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */