1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef CSV_OPENCLOSE_HXX
21 #define CSV_OPENCLOSE_HXX
27 // Open modes for storages:
30 rwDefault
= 0x0000, // Keep old settings. If there are none, set default.
31 rwRead
= 0x0001, // Reads only
32 rwWrite
= 0x0002, // Writes only
33 rwReadWrite
= 0x0003 // Reads and writes.
38 omCreateIfNecessary
= 0x0000, // Creates a new file only, if file does not exist.
39 omCreateNot
= 0x0010, // Open fails, if file does not exist.
40 omCreate
= 0x0020 // Existing file will be deleted.
44 shmShareNot
= 0x0000, // Allow others nothing
45 shmShareRead
= 0x0004, // Allow others to read
46 shmShareAll
= 0x000C // Allow others to read and write
49 /** Constants for filemode combinations
50 These combinations are the only ones, guaranteed to be supported.
52 const UINT32 CFM_RW
= rwReadWrite
;
53 const UINT32 CFM_CREATE
=
54 static_cast< UINT32
>(rwReadWrite
) | static_cast< UINT32
>(omCreate
);
55 const UINT32 CFM_READ
=
56 static_cast< UINT32
>(rwRead
) | static_cast< UINT32
>(omCreateNot
) |
57 static_cast< UINT32
>(shmShareRead
);
64 virtual ~OpenClose() {}
67 UINT32 in_nOpenModeInfo
= 0 ); /// Combination of values of E_RWMode and E_ShareMode und E_OpenMode. 0 := Keep existing mode.
74 UINT32 in_nOpenModeInfo
) = 0;
75 virtual void do_close() = 0;
76 virtual bool inq_is_open() const = 0;
85 OpenClose
& i_rOpenClose
,
86 UINT32 i_nOpenModeInfo
= 0 );
88 operator bool() const;
92 OpenCloseGuard(OpenCloseGuard
&);
93 OpenCloseGuard
& operator=(OpenCloseGuard
&);
96 OpenClose
& rOpenClose
;
103 OpenClose::open( UINT32 i_nOpenModeInfo
)
104 { return do_open(i_nOpenModeInfo
); }
109 OpenClose::is_open() const
110 { return inq_is_open(); }
113 OpenCloseGuard::OpenCloseGuard( OpenClose
& i_rOpenClose
,
114 UINT32 i_nOpenModeInfo
)
115 : rOpenClose(i_rOpenClose
)
116 { rOpenClose
.open(i_nOpenModeInfo
); }
118 OpenCloseGuard::~OpenCloseGuard()
119 { if (rOpenClose
.is_open()) rOpenClose
.close(); }
121 OpenCloseGuard::operator bool() const
122 { return rOpenClose
.is_open(); }
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */