OpenMode.h

// OpenMode.h
//
// Author David Barrett-Lennard
// (C)opyright Cedanet Pty Ltd 2007

#pragma once
#ifndef Ceda_cxUtils_OpenMode_H
#define Ceda_cxUtils_OpenMode_H

/*
Modes for opening a resource such as a file
-------------------------------------------

If the resource already exists then there are three options :  The function can either fail, open the
existing resource, or delete the old resource and create a new empty one.

If the resource doesn't exist then the options are either to create an empty resource or else to fail.

This leads to 3x2 = 6 different modes,  only 5 of which are actually useful.


       Mode                already                  doesn't already
                           exists                       exist
    --------------------------------------------------------------------
         -                 fail                         fail
    OM_CREATE_NEW          fail                         create + open
               
    OM_DELETE_EXISTING     delete + create + open       fail
    OM_CREATE_ALWAYS       delete + create + open       create + open
               
    OM_OPEN_EXISTING       open                         fail
    OM_OPEN_ALWAYS         open                         create + open

In addition, OM_OPEN_EXISTING can be split into 3 different versions

    OM_OPEN_EXISTING                :  exclusive read and write access
    OM_OPEN_EXISTING_READ_ONLY      :  exclusive read access
    OM_OPEN_EXISTING_SHARED_READ    :  shared read access
*/

namespace ceda
{

enum EOpenMode
{
    OM_CREATE_NEW,
    OM_CREATE_ALWAYS,
    OM_OPEN_EXISTING,
    OM_OPEN_EXISTING_READ_ONLY,
    OM_OPEN_EXISTING_SHARED_READ,
    OM_OPEN_ALWAYS,
    OM_DELETE_EXISTING,
};

inline bool ReadOnly(EOpenMode openMode)
{
    return openMode == OM_OPEN_EXISTING_READ_ONLY || openMode == OM_OPEN_EXISTING_SHARED_READ;
}

}

#endif // include guard