1 // Author:  Bruce Allen
2 // Created: 2/25/2013
3 //
4 // The software provided here is released by the Naval Postgraduate
5 // School, an agency of the U.S. Department of Navy.  The software
6 // bears no warranty, either expressed or implied. NPS does not assume
7 // legal liability nor responsibility for a User's use of the software
8 // or the results of such use.
9 //
10 // Please note that within the United States, copyright protection,
11 // under Section 105 of the United States Code, Title 17, is not
12 // available for any work of the United States Government and/or for
13 // any works created by United States Government employees. User
14 // acknowledges that this software contains work which was created by
15 // NPS government employees and is therefore in the public domain and
16 // not subject to copyright.
17 //
18 // Released into the public domain on February 25, 2013 by Bruce Allen.
19 
20 /**
21  * \file
22  * This file defines file modes used by hashdb.
23  */
24 
25 #ifndef FILE_MODES_H
26 #define FILE_MODES_H
27 
28 //#include <stdint.h>
29 #include <cassert>
30 #include <string>
31 #include <iostream>
32 
33 namespace hashdb {
34   enum file_mode_type_t {READ_ONLY,
35                          RW_NEW,
36                          RW_MODIFY};
37 
file_mode_type_to_string(file_mode_type_t type)38   inline std::string file_mode_type_to_string(file_mode_type_t type) {
39     switch(type) {
40       case READ_ONLY: return "read_only";
41       case RW_NEW: return "rw_new";
42       case RW_MODIFY: return "rw_modify";
43       default: assert(0); std::exit(1);
44     }
45   }
46 
string_to_file_mode_type(const std::string & name,file_mode_type_t & type)47   inline bool string_to_file_mode_type(const std::string& name, file_mode_type_t& type) {
48     if (name == "read_only") { type = READ_ONLY; return true; }
49     if (name == "rw_new")    { type = RW_NEW;    return true; }
50     if (name == "rw_modify") { type = RW_MODIFY; return true; }
51     type = READ_ONLY;
52     return false;
53   }
54 }
55 
56 inline std::ostream& operator<<(std::ostream& os,
57                                 const hashdb::file_mode_type_t& t) {
58   os << hashdb::file_mode_type_to_string(t);
59   return os;
60 }
61 
62 #endif
63 
64