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

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: 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 // Validate a map. A map is validated as a pair of arrays, one for the keys 19 // Validate 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 : expected_num_elements(0), 26 : expected_num_elements(0),
28 element_is_nullable(false), 27 element_is_nullable(false),
29 key_validate_params(in_key_validate_params), 28 key_validate_params(in_key_validate_params),
30 element_validate_params(in_element_validate_params), 29 element_validate_params(in_element_validate_params),
31 validate_enum_func(nullptr) { 30 validate_enum_func(nullptr) {
32 DCHECK(in_key_validate_params) 31 DCHECK(in_key_validate_params)
33 << "Map validate params require key validate params"; 32 << "Map validate params require key validate params";
34 DCHECK(in_element_validate_params) 33 DCHECK(in_element_validate_params)
35 << "Map validate params require element validate params"; 34 << "Map validate params require element validate params";
36 } 35 }
37 36
38 // Validate an array. 37 // Validate an array.
39 // 38 //
40 // ArrayValidateParams takes ownership of |in_element_validate params|. 39 // ContainerValidateParams takes ownership of |in_element_validate params|.
41 ArrayValidateParams(uint32_t in_expected_num_elements, 40 ContainerValidateParams(uint32_t in_expected_num_elements,
42 bool in_element_is_nullable, 41 bool in_element_is_nullable,
yzshen1 2016/06/02 19:57:03 incorrect indent. Have you run "git cl format"?
tibell 2016/06/03 00:01:30 Done.
43 ArrayValidateParams* in_element_validate_params) 42 ContainerValidateParams* in_element_validate_params)
44 : expected_num_elements(in_expected_num_elements), 43 : expected_num_elements(in_expected_num_elements),
45 element_is_nullable(in_element_is_nullable), 44 element_is_nullable(in_element_is_nullable),
46 key_validate_params(nullptr), 45 key_validate_params(nullptr),
47 element_validate_params(in_element_validate_params), 46 element_validate_params(in_element_validate_params),
48 validate_enum_func(nullptr) {} 47 validate_enum_func(nullptr) {}
49 48
50 // Validates an array of enums. 49 // Validates an array of enums.
51 ArrayValidateParams(uint32_t in_expected_num_elements, 50 ContainerValidateParams(uint32_t in_expected_num_elements,
52 ValidateEnumFunc in_validate_enum_func) 51 ValidateEnumFunc in_validate_enum_func)
53 : expected_num_elements(in_expected_num_elements), 52 : expected_num_elements(in_expected_num_elements),
54 element_is_nullable(false), 53 element_is_nullable(false),
55 key_validate_params(nullptr), 54 key_validate_params(nullptr),
56 element_validate_params(nullptr), 55 element_validate_params(nullptr),
57 validate_enum_func(in_validate_enum_func) {} 56 validate_enum_func(in_validate_enum_func) {}
58 57
59 ~ArrayValidateParams() { 58 ~ContainerValidateParams() {
60 if (element_validate_params) 59 if (element_validate_params)
61 delete element_validate_params; 60 delete element_validate_params;
62 if (key_validate_params) 61 if (key_validate_params)
63 delete key_validate_params; 62 delete key_validate_params;
64 } 63 }
65 64
66 // If |expected_num_elements| is not 0, the array is expected to have exactly 65 // If |expected_num_elements| is not 0, the array is expected to have exactly
67 // that number of elements. 66 // that number of elements.
68 uint32_t expected_num_elements; 67 uint32_t expected_num_elements;
69 68
70 // Whether the elements are nullable. 69 // Whether the elements are nullable.
71 bool element_is_nullable; 70 bool element_is_nullable;
72 71
73 // Validation information for map key. It is either a pointer to another 72 // Validation information for map key. It is either a pointer to another
74 // instance of ArrayValidateParams (if keys are arrays or maps), or nullptr. 73 // instance of ContainerValidateParams (if keys are arrays or maps), or
75 ArrayValidateParams* key_validate_params; 74 // nullptr.
75 ContainerValidateParams* key_validate_params;
76 76
77 // Validation information for elements. It is either a pointer to another 77 // Validation information for elements. It is either a pointer to another
78 // instance of ArrayValidateParams (if elements are arrays or maps), or 78 // instance of ContainerValidateParams (if elements are arrays or maps), or
79 // nullptr. In the case of maps, this is used to validate the value array. 79 // nullptr. In the case of maps, this is used to validate the value array.
80 ArrayValidateParams* element_validate_params; 80 ContainerValidateParams* element_validate_params;
81 81
82 // Validation function for enum elements. 82 // Validation function for enum elements.
83 ValidateEnumFunc validate_enum_func; 83 ValidateEnumFunc validate_enum_func;
84 84
85 private: 85 private:
86 DISALLOW_COPY_AND_ASSIGN(ArrayValidateParams); 86 DISALLOW_COPY_AND_ASSIGN(ContainerValidateParams);
87 }; 87 };
88 88
89 } // namespace internal 89 } // namespace internal
90 } // namespace mojo 90 } // namespace mojo
91 91
92 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATE_PARAMS_H_ 92 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATE_PARAMS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698