update credits
[LibreOffice.git] / include / cosv / openclose.hxx
blobc65ce5b753e20fc21ff9658a1e5ec25526988f8c
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 #ifndef CSV_OPENCLOSE_HXX
21 #define CSV_OPENCLOSE_HXX
24 namespace csv
27 // Open modes for storages:
28 enum E_RWMode
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.
36 enum E_OpenMode
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.
42 enum E_ShareMode
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);
61 class OpenClose
63 public:
64 virtual ~OpenClose() {}
66 bool open(
67 UINT32 in_nOpenModeInfo = 0 ); /// Combination of values of E_RWMode and E_ShareMode und E_OpenMode. 0 := Keep existing mode.
68 void close();
70 bool is_open() const;
72 private:
73 virtual bool do_open(
74 UINT32 in_nOpenModeInfo ) = 0;
75 virtual void do_close() = 0;
76 virtual bool inq_is_open() const = 0;
81 class OpenCloseGuard
83 public:
84 OpenCloseGuard(
85 OpenClose & i_rOpenClose,
86 UINT32 i_nOpenModeInfo = 0 );
87 ~OpenCloseGuard();
88 operator bool() const;
90 private:
91 // Forbidden:
92 OpenCloseGuard(OpenCloseGuard&);
93 OpenCloseGuard & operator=(OpenCloseGuard&);
95 // DATA
96 OpenClose & rOpenClose;
100 // IMPLEMENTATION
102 inline bool
103 OpenClose::open( UINT32 i_nOpenModeInfo )
104 { return do_open(i_nOpenModeInfo); }
105 inline void
106 OpenClose::close()
107 { do_close(); }
108 inline bool
109 OpenClose::is_open() const
110 { return inq_is_open(); }
112 inline
113 OpenCloseGuard::OpenCloseGuard( OpenClose & i_rOpenClose,
114 UINT32 i_nOpenModeInfo )
115 : rOpenClose(i_rOpenClose)
116 { rOpenClose.open(i_nOpenModeInfo); }
117 inline
118 OpenCloseGuard::~OpenCloseGuard()
119 { if (rOpenClose.is_open()) rOpenClose.close(); }
120 inline
121 OpenCloseGuard::operator bool() const
122 { return rOpenClose.is_open(); }
127 } // namespace csv
134 #endif
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */