OLD | NEW |
---|---|
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 <new> | 8 #include <new> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, | 269 VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, |
270 MakeMessageWithArrayIndex("null in array expecting valid pointers", | 270 MakeMessageWithArrayIndex("null in array expecting valid pointers", |
271 header->num_elements, | 271 header->num_elements, |
272 i).c_str()); | 272 i).c_str()); |
273 return false; | 273 return false; |
274 } | 274 } |
275 if (!ValidateEncodedPointer(&elements[i].offset)) { | 275 if (!ValidateEncodedPointer(&elements[i].offset)) { |
276 ReportValidationError(VALIDATION_ERROR_ILLEGAL_POINTER); | 276 ReportValidationError(VALIDATION_ERROR_ILLEGAL_POINTER); |
277 return false; | 277 return false; |
278 } | 278 } |
279 if (!ValidateCaller<P, ElementValidateParams>::Run( | 279 if (!ValidateCaller<P, ElementValidateParams, IsUnionDataType<P>::value>:: |
280 DecodePointerRaw(&elements[i].offset), bounds_checker)) { | 280 Run(DecodePointerRaw(&elements[i].offset), bounds_checker)) { |
281 return false; | 281 return false; |
282 } | 282 } |
283 } | 283 } |
284 return true; | 284 return true; |
285 } | 285 } |
286 | 286 |
287 private: | 287 private: |
288 template <typename T, typename Params, bool isUnion> | |
viettrungluu
2015/03/04 20:58:13
nit: (FYI) camelCase is never used in (our) C++
A
azani
2015/03/05 23:59:24
I've updated the case issue. I could be wrong, but
viettrungluu
2015/03/17 20:08:02
Maybe something like the example from http://en.cp
azani
2015/03/18 01:04:39
I have not been able to get these to work.
Puttin
| |
289 struct ValidateCaller {}; | |
290 | |
288 template <typename T, typename Params> | 291 template <typename T, typename Params> |
289 struct ValidateCaller { | 292 struct ValidateCaller<T, Params, false> { |
290 static bool Run(const void* data, BoundsChecker* bounds_checker) { | 293 static bool Run(const void* data, BoundsChecker* bounds_checker) { |
291 static_assert((IsSame<Params, NoValidateParams>::value), | 294 static_assert((IsSame<Params, NoValidateParams>::value), |
292 "Struct type should not have array validate params"); | 295 "Struct type should not have array validate params"); |
293 | 296 |
294 return T::Validate(data, bounds_checker); | 297 return T::Validate(data, bounds_checker); |
295 } | 298 } |
296 }; | 299 }; |
297 | 300 |
301 template <typename T, typename Params> | |
302 struct ValidateCaller<T, Params, true> { | |
303 static bool Run(const void* data, BoundsChecker* bounds_checker) { | |
304 static_assert((IsSame<Params, NoValidateParams>::value), | |
305 "Union type should not have array validate params"); | |
306 | |
307 return T::Validate(data, bounds_checker, true); | |
308 } | |
309 }; | |
310 | |
298 template <typename Key, typename Value, typename Params> | 311 template <typename Key, typename Value, typename Params> |
299 struct ValidateCaller<Map_Data<Key, Value>, Params> { | 312 struct ValidateCaller<Map_Data<Key, Value>, Params, false> { |
300 static bool Run(const void* data, BoundsChecker* bounds_checker) { | 313 static bool Run(const void* data, BoundsChecker* bounds_checker) { |
301 return Map_Data<Key, Value>::template Validate<Params>(data, | 314 return Map_Data<Key, Value>::template Validate<Params>(data, |
302 bounds_checker); | 315 bounds_checker); |
303 } | 316 } |
304 }; | 317 }; |
305 | 318 |
306 template <typename T, typename Params> | 319 template <typename T, typename Params> |
307 struct ValidateCaller<Array_Data<T>, Params> { | 320 struct ValidateCaller<Array_Data<T>, Params, false> { |
308 static bool Run(const void* data, BoundsChecker* bounds_checker) { | 321 static bool Run(const void* data, BoundsChecker* bounds_checker) { |
309 return Array_Data<T>::template Validate<Params>(data, bounds_checker); | 322 return Array_Data<T>::template Validate<Params>(data, bounds_checker); |
310 } | 323 } |
311 }; | 324 }; |
312 }; | 325 }; |
313 | 326 |
314 template <typename T> | 327 template <typename T> |
315 class Array_Data { | 328 class Array_Data { |
316 public: | 329 public: |
317 typedef ArrayDataTraits<T> Traits; | 330 typedef ArrayDataTraits<T> Traits; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
503 | 516 |
504 template <> | 517 template <> |
505 struct WrapperTraits<String, false> { | 518 struct WrapperTraits<String, false> { |
506 typedef String_Data* DataType; | 519 typedef String_Data* DataType; |
507 }; | 520 }; |
508 | 521 |
509 } // namespace internal | 522 } // namespace internal |
510 } // namespace mojo | 523 } // namespace mojo |
511 | 524 |
512 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ | 525 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ |
OLD | NEW |