Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: mojo/public/cpp/bindings/lib/validate_params.h

Issue 2030873002: Mojo C++ bindings: rename ArrayValidateParams for clarity (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cc-enums
Patch Set: Rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATE_PARAMS_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATE_PARAMS_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATE_PARAMS_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATE_PARAMS_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 11
12 namespace mojo { 12 namespace mojo {
13 namespace internal { 13 namespace internal {
14 14
15 using ValidateEnumFunc = bool (*)(int32_t); 15 using ValidateEnumFunc = bool (*)(int32_t);
16 16
17 // TODO(tibell): Rename to ContainerValidateParams. 17 class ContainerValidateParams {
18 class ArrayValidateParams {
19 public: 18 public:
20 // Validates a map. A map is validated as a pair of arrays, one for the keys 19 // Validates a map. A map is validated as a pair of arrays, one for the keys
21 // and one for the values. Both arguments must be non-null. 20 // and one for the values. Both arguments must be non-null.
22 // 21 //
23 // ArrayValidateParams takes ownership of |in_key_validate params| and 22 // ContainerValidateParams takes ownership of |in_key_validate params| and
24 // |in_element_validate params|. 23 // |in_element_validate params|.
25 ArrayValidateParams(ArrayValidateParams* in_key_validate_params, 24 ContainerValidateParams(ContainerValidateParams* in_key_validate_params,
26 ArrayValidateParams* in_element_validate_params) 25 ContainerValidateParams* in_element_validate_params)
27 : key_validate_params(in_key_validate_params), 26 : key_validate_params(in_key_validate_params),
28 element_validate_params(in_element_validate_params) { 27 element_validate_params(in_element_validate_params) {
29 DCHECK(in_key_validate_params) 28 DCHECK(in_key_validate_params)
30 << "Map validate params require key validate params"; 29 << "Map validate params require key validate params";
31 DCHECK(in_element_validate_params) 30 DCHECK(in_element_validate_params)
32 << "Map validate params require element validate params"; 31 << "Map validate params require element validate params";
33 } 32 }
34 33
35 // Validates an array. 34 // Validates an array.
36 // 35 //
37 // ArrayValidateParams takes ownership of |in_element_validate params|. 36 // ContainerValidateParams takes ownership of |in_element_validate params|.
38 ArrayValidateParams(uint32_t in_expected_num_elements, 37 ContainerValidateParams(uint32_t in_expected_num_elements,
39 bool in_element_is_nullable, 38 bool in_element_is_nullable,
40 ArrayValidateParams* in_element_validate_params) 39 ContainerValidateParams* in_element_validate_params)
41 : expected_num_elements(in_expected_num_elements), 40 : expected_num_elements(in_expected_num_elements),
42 element_is_nullable(in_element_is_nullable), 41 element_is_nullable(in_element_is_nullable),
43 element_validate_params(in_element_validate_params) {} 42 element_validate_params(in_element_validate_params) {}
44 43
45 // Validates an array of enums. 44 // Validates an array of enums.
46 ArrayValidateParams(uint32_t in_expected_num_elements, 45 ContainerValidateParams(uint32_t in_expected_num_elements,
47 ValidateEnumFunc in_validate_enum_func) 46 ValidateEnumFunc in_validate_enum_func)
48 : expected_num_elements(in_expected_num_elements), 47 : expected_num_elements(in_expected_num_elements),
49 validate_enum_func(in_validate_enum_func) {} 48 validate_enum_func(in_validate_enum_func) {}
50 49
51 ~ArrayValidateParams() { 50 ~ContainerValidateParams() {
52 if (element_validate_params) 51 if (element_validate_params)
53 delete element_validate_params; 52 delete element_validate_params;
54 if (key_validate_params) 53 if (key_validate_params)
55 delete key_validate_params; 54 delete key_validate_params;
56 } 55 }
57 56
58 // If |expected_num_elements| is not 0, the array is expected to have exactly 57 // If |expected_num_elements| is not 0, the array is expected to have exactly
59 // that number of elements. 58 // that number of elements.
60 uint32_t expected_num_elements = 0; 59 uint32_t expected_num_elements = 0;
61 60
62 // Whether the elements are nullable. 61 // Whether the elements are nullable.
63 bool element_is_nullable = false; 62 bool element_is_nullable = false;
64 63
65 // Validation information for the map key array. May contain other 64 // Validation information for the map key array. May contain other
66 // ArrayValidateParams e.g. if the keys are strings. 65 // ArrayValidateParams e.g. if the keys are strings.
67 ArrayValidateParams* key_validate_params = nullptr; 66 ContainerValidateParams* key_validate_params = nullptr;
68 67
69 // For arrays: validation information for elements. It is either a pointer to 68 // For arrays: validation information for elements. It is either a pointer to
70 // another instance of ArrayValidateParams (if elements are arrays or maps), 69 // another instance of ArrayValidateParams (if elements are arrays or maps),
71 // or nullptr. 70 // or nullptr.
72 // 71 //
73 // For maps: validation information for the whole value array. May contain 72 // For maps: validation information for the whole value array. May contain
74 // other ArrayValidateParams e.g. if the values are arrays or maps. 73 // other ArrayValidateParams e.g. if the values are arrays or maps.
75 ArrayValidateParams* element_validate_params = nullptr; 74 ContainerValidateParams* element_validate_params = nullptr;
76 75
77 // Validation function for enum elements. 76 // Validation function for enum elements.
78 ValidateEnumFunc validate_enum_func = nullptr; 77 ValidateEnumFunc validate_enum_func = nullptr;
79 78
80 private: 79 private:
81 DISALLOW_COPY_AND_ASSIGN(ArrayValidateParams); 80 DISALLOW_COPY_AND_ASSIGN(ContainerValidateParams);
82 }; 81 };
83 82
84 } // namespace internal 83 } // namespace internal
85 } // namespace mojo 84 } // namespace mojo
86 85
87 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATE_PARAMS_H_ 86 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATE_PARAMS_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/native_struct_serialization.cc ('k') | mojo/public/cpp/bindings/lib/validation_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698