MinIO C++ SDK
types.h
1 // MinIO C++ Library for Amazon S3 Compatible Cloud Storage
2 // Copyright 2022 MinIO, Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef _MINIO_S3_TYPES_H
17 #define _MINIO_S3_TYPES_H
18 
19 #include <iostream>
20 
21 #include "utils.h"
22 
23 namespace minio {
24 namespace s3 {
25 enum class RetentionMode { kGovernance, kCompliance };
26 
27 // StringToRetentionMode converts string to retention mode enum.
28 RetentionMode StringToRetentionMode(std::string_view str) throw();
29 
30 constexpr bool IsRetentionModeValid(RetentionMode& retention) {
31  switch (retention) {
32  case RetentionMode::kGovernance:
33  case RetentionMode::kCompliance:
34  return true;
35  }
36  return false;
37 }
38 
39 // RetentionModeToString converts retention mode enum to string.
40 constexpr const char* RetentionModeToString(RetentionMode& retention) throw() {
41  switch (retention) {
42  case RetentionMode::kGovernance:
43  return "GOVERNANCE";
44  case RetentionMode::kCompliance:
45  return "COMPLIANCE";
46  default: {
47  std::cerr << "ABORT: Unknown retention mode. This should not happen."
48  << std::endl;
49  std::terminate();
50  }
51  }
52  return NULL;
53 }
54 
55 enum class LegalHold { kOn, kOff };
56 
57 // StringToLegalHold converts string to legal hold enum.
58 LegalHold StringToLegalHold(std::string_view str) throw();
59 
60 constexpr bool IsLegalHoldValid(LegalHold& legal_hold) {
61  switch (legal_hold) {
62  case LegalHold::kOn:
63  case LegalHold::kOff:
64  return true;
65  }
66  return false;
67 }
68 
69 // LegalHoldToString converts legal hold enum to string.
70 constexpr const char* LegalHoldToString(LegalHold& legal_hold) throw() {
71  switch (legal_hold) {
72  case LegalHold::kOn:
73  return "ON";
74  case LegalHold::kOff:
75  return "OFF";
76  default: {
77  std::cerr << "ABORT: Unknown legal hold. This should not happen."
78  << std::endl;
79  std::terminate();
80  }
81  }
82  return NULL;
83 }
84 
85 enum class Directive { kCopy, kReplace };
86 
87 // StringToDirective converts string to directive enum.
88 Directive StringToDirective(std::string_view str) throw();
89 
90 // DirectiveToString converts directive enum to string.
91 constexpr const char* DirectiveToString(Directive& directive) throw() {
92  switch (directive) {
93  case Directive::kCopy:
94  return "COPY";
95  case Directive::kReplace:
96  return "REPLACE";
97  default: {
98  std::cerr << "ABORT: Unknown directive. This should not happen."
99  << std::endl;
100  std::terminate();
101  }
102  }
103  return NULL;
104 }
105 
106 struct Bucket {
107  std::string name;
108  utils::Time creation_date;
109 }; // struct Bucket
110 
111 struct Part {
112  unsigned int number;
113  std::string etag;
114  utils::Time last_modified;
115  size_t size;
116 }; // struct Part
117 
118 struct Retention {
119  RetentionMode mode;
120  utils::Time retain_until_date;
121 }; // struct Retention
122 } // namespace s3
123 } // namespace minio
124 #endif // #ifndef __MINIO_S3_TYPES_H
Definition: utils.h:97
Definition: types.h:106
Definition: types.h:111
Definition: types.h:118