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

Side by Side Diff: mojo/public/cpp/bindings/lib/map_data_internal.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_MAP_DATA_INTERNAL_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_DATA_INTERNAL_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_DATA_INTERNAL_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_DATA_INTERNAL_H_
7 7
8 #include "mojo/public/cpp/bindings/lib/array_internal.h" 8 #include "mojo/public/cpp/bindings/lib/array_internal.h"
9 #include "mojo/public/cpp/bindings/lib/validate_params.h" 9 #include "mojo/public/cpp/bindings/lib/validate_params.h"
10 #include "mojo/public/cpp/bindings/lib/validation_errors.h" 10 #include "mojo/public/cpp/bindings/lib/validation_errors.h"
11 #include "mojo/public/cpp/bindings/lib/validation_util.h" 11 #include "mojo/public/cpp/bindings/lib/validation_util.h"
12 12
13 namespace mojo { 13 namespace mojo {
14 namespace internal { 14 namespace internal {
15 15
16 // Map serializes into a struct which has two arrays as struct fields, the keys 16 // Map serializes into a struct which has two arrays as struct fields, the keys
17 // and the values. 17 // and the values.
18 template <typename Key, typename Value> 18 template <typename Key, typename Value>
19 class Map_Data { 19 class Map_Data {
20 public: 20 public:
21 static Map_Data* New(Buffer* buf) { 21 static Map_Data* New(Buffer* buf) {
22 return new (buf->Allocate(sizeof(Map_Data))) Map_Data(); 22 return new (buf->Allocate(sizeof(Map_Data))) Map_Data();
23 } 23 }
24 24
25 // |validate_params| must have non-null |key_validate_params| and 25 // |validate_params| must have non-null |key_validate_params| and
26 // |element_validate_params| members. 26 // |element_validate_params| members.
27 static bool Validate(const void* data, 27 static bool Validate(const void* data,
28 BoundsChecker* bounds_checker, 28 BoundsChecker* bounds_checker,
29 const ArrayValidateParams* validate_params) { 29 const ContainerValidateParams* validate_params) {
30 if (!data) 30 if (!data)
31 return true; 31 return true;
32 32
33 if (!ValidateStructHeaderAndClaimMemory(data, bounds_checker)) 33 if (!ValidateStructHeaderAndClaimMemory(data, bounds_checker))
34 return false; 34 return false;
35 35
36 const Map_Data* object = static_cast<const Map_Data*>(data); 36 const Map_Data* object = static_cast<const Map_Data*>(data);
37 if (object->header_.num_bytes != sizeof(Map_Data) || 37 if (object->header_.num_bytes != sizeof(Map_Data) ||
38 object->header_.version != 0) { 38 object->header_.version != 0) {
39 ReportValidationError(VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER); 39 ReportValidationError(VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 header_.version = 0; 103 header_.version = 0;
104 } 104 }
105 ~Map_Data() = delete; 105 ~Map_Data() = delete;
106 }; 106 };
107 static_assert(sizeof(Map_Data<char, char>) == 24, "Bad sizeof(Map_Data)"); 107 static_assert(sizeof(Map_Data<char, char>) == 24, "Bad sizeof(Map_Data)");
108 108
109 } // namespace internal 109 } // namespace internal
110 } // namespace mojo 110 } // namespace mojo
111 111
112 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_DATA_INTERNAL_H_ 112 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_DATA_INTERNAL_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/array_serialization.h ('k') | mojo/public/cpp/bindings/lib/map_serialization.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698