]> git.tdb.fi Git - libs/core.git/commitdiff
Add some useful shortcuts for CreateMode combinations
authorMikko Rasa <tdb@tdb.fi>
Thu, 27 Sep 2012 22:04:31 +0000 (01:04 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 27 Sep 2012 22:04:31 +0000 (01:04 +0300)
All valid modes can now be referred to with a single enumerator.
C_EXCLUSIVE alone is not valid.

source/io/file.cpp
source/io/file.h

index 208371df8bff5b33bedb5ddbd72847dfc6fcf7d2..d4b2da3454f0a29e3ba32808256780ba6aa8954d 100644 (file)
@@ -39,8 +39,8 @@ File::File(const string &fn, Mode m, CreateMode cm)
                case C_NONE:     create_flags = OPEN_EXISTING; break;
                case C_CREATE:   create_flags = OPEN_ALWAYS; break;
                case C_TRUNCATE: create_flags = TRUNCATE_EXISTING; break;
                case C_NONE:     create_flags = OPEN_EXISTING; break;
                case C_CREATE:   create_flags = OPEN_ALWAYS; break;
                case C_TRUNCATE: create_flags = TRUNCATE_EXISTING; break;
-               case C_CREATE+C_TRUNCATE: create_flags = CREATE_ALWAYS; break;
-               case C_CREATE+C_EXCLUSIVE: create_flags = CREATE_NEW; break;
+               case C_OVERWRITE: create_flags = CREATE_ALWAYS; break;
+               case C_NEW:      create_flags = CREATE_NEW; break;
                }
        }
 
                }
        }
 
index 4f8e5ddf8612b559f82ce5bfc7c2623ba5860cc9..5fb0353211b2e99d23384afa2924e87ee78acc10 100644 (file)
@@ -37,7 +37,9 @@ public:
                C_NONE = 0,
                C_CREATE = 1,
                C_TRUNCATE = 2,
                C_NONE = 0,
                C_CREATE = 1,
                C_TRUNCATE = 2,
-               C_EXCLUSIVE = 4
+               C_OVERWRITE = C_CREATE+C_TRUNCATE,
+               C_EXCLUSIVE = 4,
+               C_NEW = C_CREATE+C_EXCLUSIVE
        };
 
 private:
        };
 
 private:
@@ -47,7 +49,7 @@ public:
        /** Creates a new file object and opens it.  If the create flag is set and
        write access is requested and the file does exist, it is created.  Otherwise
        a missing file is an error. */
        /** Creates a new file object and opens it.  If the create flag is set and
        write access is requested and the file does exist, it is created.  Otherwise
        a missing file is an error. */
-       File(const std::string &, Mode = M_READ, CreateMode = CreateMode(C_CREATE+C_TRUNCATE));
+       File(const std::string &, Mode = M_READ, CreateMode = C_OVERWRITE);
        virtual ~File();
 
        void set_block(bool);
        virtual ~File();
 
        void set_block(bool);