LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/cosv - openclose.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 15 15 100.0 %
Date: 2012-12-27 Functions: 8 9 88.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifndef CSV_OPENCLOSE_HXX
      21             : #define CSV_OPENCLOSE_HXX
      22             : 
      23             : 
      24             : namespace csv
      25             : {
      26             : 
      27             : // Open modes for storages:
      28             : enum E_RWMode
      29             : {
      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.
      34             : };
      35             : 
      36             : enum E_OpenMode
      37             : {
      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.
      41             : };
      42             : enum E_ShareMode
      43             : {
      44             :     shmShareNot     = 0x0000,       // Allow others nothing
      45             :     shmShareRead    = 0x0004,       // Allow others to read
      46             :     shmShareAll     = 0x000C        // Allow others to read and write
      47             : };
      48             : 
      49             : /** Constants for filemode combinations
      50             :     These combinations are the only ones, guaranteed to be supported.
      51             : */
      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);
      58             : 
      59             : 
      60             : 
      61       11971 : class OpenClose
      62             : {
      63             :   public:
      64       11971 :     virtual ~OpenClose() {}
      65             : 
      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();
      69             : 
      70             :     bool                is_open() const;
      71             : 
      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;
      77             : };
      78             : 
      79             : 
      80             : 
      81             : class OpenCloseGuard
      82             : {
      83             :   public:
      84             :                         OpenCloseGuard(
      85             :                             OpenClose &         i_rOpenClose,
      86             :                             UINT32              i_nOpenModeInfo = 0 );
      87             :                         ~OpenCloseGuard();
      88             :                         operator bool() const;
      89             : 
      90             :   private:
      91             :     // Forbidden:
      92             :                         OpenCloseGuard(OpenCloseGuard&);
      93             :     OpenCloseGuard &    operator=(OpenCloseGuard&);
      94             : 
      95             :     // DATA
      96             :     OpenClose &         rOpenClose;
      97             : };
      98             : 
      99             : 
     100             : // IMPLEMENTATION
     101             : 
     102             : inline bool
     103       11971 : OpenClose::open( UINT32 i_nOpenModeInfo )
     104       11971 :     { return do_open(i_nOpenModeInfo); }
     105             : inline void
     106       11971 : OpenClose::close()
     107       11971 :     { do_close(); }
     108             : inline bool
     109           4 : OpenClose::is_open() const
     110           4 :     { return inq_is_open(); }
     111             : 
     112             : inline
     113           2 : OpenCloseGuard::OpenCloseGuard( OpenClose & i_rOpenClose,
     114             :                                 UINT32      i_nOpenModeInfo )
     115           2 :     :   rOpenClose(i_rOpenClose)
     116           2 :     { rOpenClose.open(i_nOpenModeInfo); }
     117             : inline
     118           2 : OpenCloseGuard::~OpenCloseGuard()
     119           2 :     { if (rOpenClose.is_open()) rOpenClose.close(); }
     120             : inline
     121           2 : OpenCloseGuard::operator bool() const
     122           2 :     { return rOpenClose.is_open(); }
     123             : 
     124             : 
     125             : 
     126             : 
     127             : }   // namespace csv
     128             : 
     129             : 
     130             : 
     131             : 
     132             : 
     133             : 
     134             : #endif
     135             : 
     136             : 
     137             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10