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

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

Issue 1618963006: Mojo C++ bindings: support enum validation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_ARRAY_INTERNAL_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <new> 10 #include <new>
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 std::vector<Handle>* handles) {} 166 std::vector<Handle>* handles) {}
167 167
168 static bool ValidateElements(const ArrayHeader* header, 168 static bool ValidateElements(const ArrayHeader* header,
169 const ElementType* elements, 169 const ElementType* elements,
170 BoundsChecker* bounds_checker, 170 BoundsChecker* bounds_checker,
171 const ArrayValidateParams* validate_params) { 171 const ArrayValidateParams* validate_params) {
172 MOJO_DCHECK(!validate_params->element_is_nullable) 172 MOJO_DCHECK(!validate_params->element_is_nullable)
173 << "Primitive type should be non-nullable"; 173 << "Primitive type should be non-nullable";
174 MOJO_DCHECK(!validate_params->element_validate_params) 174 MOJO_DCHECK(!validate_params->element_validate_params)
175 << "Primitive type should not have array validate params"; 175 << "Primitive type should not have array validate params";
176
177 for (uint32_t i = 0; i < header->num_elements; ++i) {
178 if (!ValidateCaller<ElementType>::Run(elements[i]))
179 return false;
180 }
181
176 return true; 182 return true;
177 } 183 }
184
185 private:
186 template <typename U, bool is_enum = IsEnumDataType<U>::value>
187 struct ValidateCaller {};
188
189 template <typename U>
190 struct ValidateCaller<U, false> {
191 static bool Run(const ElementType& element) { return true; }
192 };
193
194 template <typename U>
195 struct ValidateCaller<U, true> {
196 static bool Run(const ElementType& element) {
197 return ValidateEnum(element);
198 }
199 };
178 }; 200 };
179 201
180 template <> 202 template <>
181 struct ArraySerializationHelper<Handle, true> { 203 struct ArraySerializationHelper<Handle, true> {
182 typedef ArrayDataTraits<Handle>::StorageType ElementType; 204 typedef ArrayDataTraits<Handle>::StorageType ElementType;
183 205
184 static void EncodePointersAndHandles(const ArrayHeader* header, 206 static void EncodePointersAndHandles(const ArrayHeader* header,
185 ElementType* elements, 207 ElementType* elements,
186 std::vector<Handle>* handles); 208 std::vector<Handle>* handles);
187 209
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 550
529 template <> 551 template <>
530 struct WrapperTraits<String, false> { 552 struct WrapperTraits<String, false> {
531 typedef String_Data* DataType; 553 typedef String_Data* DataType;
532 }; 554 };
533 555
534 } // namespace internal 556 } // namespace internal
535 } // namespace mojo 557 } // namespace mojo
536 558
537 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ 559 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698