1 | /* |
---|---|
2 | * Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
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 | * A copy of the License is located at |
7 | * |
8 | * http://aws.amazon.com/apache2.0 |
9 | * |
10 | * or in the "license" file accompanying this file. This file is distributed |
11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
12 | * express or implied. See the License for the specific language governing |
13 | * permissions and limitations under the License. |
14 | */ |
15 | |
16 | #include <aws/s3/model/Permission.h> |
17 | #include <aws/core/utils/HashingUtils.h> |
18 | #include <aws/core/Globals.h> |
19 | #include <aws/core/utils/EnumParseOverflowContainer.h> |
20 | |
21 | using namespace Aws::Utils; |
22 | |
23 | |
24 | namespace Aws |
25 | { |
26 | namespace S3 |
27 | { |
28 | namespace Model |
29 | { |
30 | namespace PermissionMapper |
31 | { |
32 | |
33 | static const int FULL_CONTROL_HASH = HashingUtils::HashString("FULL_CONTROL"); |
34 | static const int WRITE_HASH = HashingUtils::HashString("WRITE"); |
35 | static const int WRITE_ACP_HASH = HashingUtils::HashString("WRITE_ACP"); |
36 | static const int READ_HASH = HashingUtils::HashString("READ"); |
37 | static const int READ_ACP_HASH = HashingUtils::HashString("READ_ACP"); |
38 | |
39 | |
40 | Permission GetPermissionForName(const Aws::String& name) |
41 | { |
42 | int hashCode = HashingUtils::HashString(name.c_str()); |
43 | if (hashCode == FULL_CONTROL_HASH) |
44 | { |
45 | return Permission::FULL_CONTROL; |
46 | } |
47 | else if (hashCode == WRITE_HASH) |
48 | { |
49 | return Permission::WRITE; |
50 | } |
51 | else if (hashCode == WRITE_ACP_HASH) |
52 | { |
53 | return Permission::WRITE_ACP; |
54 | } |
55 | else if (hashCode == READ_HASH) |
56 | { |
57 | return Permission::READ; |
58 | } |
59 | else if (hashCode == READ_ACP_HASH) |
60 | { |
61 | return Permission::READ_ACP; |
62 | } |
63 | EnumParseOverflowContainer* overflowContainer = Aws::GetEnumOverflowContainer(); |
64 | if(overflowContainer) |
65 | { |
66 | overflowContainer->StoreOverflow(hashCode, name); |
67 | return static_cast<Permission>(hashCode); |
68 | } |
69 | |
70 | return Permission::NOT_SET; |
71 | } |
72 | |
73 | Aws::String GetNameForPermission(Permission enumValue) |
74 | { |
75 | switch(enumValue) |
76 | { |
77 | case Permission::FULL_CONTROL: |
78 | return "FULL_CONTROL"; |
79 | case Permission::WRITE: |
80 | return "WRITE"; |
81 | case Permission::WRITE_ACP: |
82 | return "WRITE_ACP"; |
83 | case Permission::READ: |
84 | return "READ"; |
85 | case Permission::READ_ACP: |
86 | return "READ_ACP"; |
87 | default: |
88 | EnumParseOverflowContainer* overflowContainer = Aws::GetEnumOverflowContainer(); |
89 | if(overflowContainer) |
90 | { |
91 | return overflowContainer->RetrieveOverflow(static_cast<int>(enumValue)); |
92 | } |
93 | |
94 | return {}; |
95 | } |
96 | } |
97 | |
98 | } // namespace PermissionMapper |
99 | } // namespace Model |
100 | } // namespace S3 |
101 | } // namespace Aws |
102 |