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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 } | 278 } |
279 if (!ValidateCaller<P, ElementValidateParams>::Run( | 279 if (!ValidateCaller<P, ElementValidateParams>::Run( |
280 DecodePointerRaw(&elements[i].offset), bounds_checker)) { | 280 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, |
| 289 typename Params, |
| 290 bool is_union = IsUnionDataType<T>::value> |
| 291 struct ValidateCaller {}; |
| 292 |
288 template <typename T, typename Params> | 293 template <typename T, typename Params> |
289 struct ValidateCaller { | 294 struct ValidateCaller<T, Params, false> { |
290 static bool Run(const void* data, BoundsChecker* bounds_checker) { | 295 static bool Run(const void* data, BoundsChecker* bounds_checker) { |
291 static_assert((IsSame<Params, NoValidateParams>::value), | 296 static_assert((IsSame<Params, NoValidateParams>::value), |
292 "Struct type should not have array validate params"); | 297 "Struct type should not have array validate params"); |
293 | 298 |
294 return T::Validate(data, bounds_checker); | 299 return T::Validate(data, bounds_checker); |
295 } | 300 } |
296 }; | 301 }; |
297 | 302 |
| 303 template <typename T, typename Params> |
| 304 struct ValidateCaller<T, Params, true> { |
| 305 static bool Run(const void* data, BoundsChecker* bounds_checker) { |
| 306 static_assert((IsSame<Params, NoValidateParams>::value), |
| 307 "Union type should not have array validate params"); |
| 308 |
| 309 return T::Validate(data, bounds_checker, true); |
| 310 } |
| 311 }; |
| 312 |
298 template <typename Key, typename Value, typename Params> | 313 template <typename Key, typename Value, typename Params> |
299 struct ValidateCaller<Map_Data<Key, Value>, Params> { | 314 struct ValidateCaller<Map_Data<Key, Value>, Params, false> { |
300 static bool Run(const void* data, BoundsChecker* bounds_checker) { | 315 static bool Run(const void* data, BoundsChecker* bounds_checker) { |
301 return Map_Data<Key, Value>::template Validate<Params>(data, | 316 return Map_Data<Key, Value>::template Validate<Params>(data, |
302 bounds_checker); | 317 bounds_checker); |
303 } | 318 } |
304 }; | 319 }; |
305 | 320 |
306 template <typename T, typename Params> | 321 template <typename T, typename Params> |
307 struct ValidateCaller<Array_Data<T>, Params> { | 322 struct ValidateCaller<Array_Data<T>, Params, false> { |
308 static bool Run(const void* data, BoundsChecker* bounds_checker) { | 323 static bool Run(const void* data, BoundsChecker* bounds_checker) { |
309 return Array_Data<T>::template Validate<Params>(data, bounds_checker); | 324 return Array_Data<T>::template Validate<Params>(data, bounds_checker); |
310 } | 325 } |
311 }; | 326 }; |
312 }; | 327 }; |
313 | 328 |
314 template <typename T> | 329 template <typename T> |
315 class Array_Data { | 330 class Array_Data { |
316 public: | 331 public: |
317 typedef ArrayDataTraits<T> Traits; | 332 typedef ArrayDataTraits<T> Traits; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 | 518 |
504 template <> | 519 template <> |
505 struct WrapperTraits<String, false> { | 520 struct WrapperTraits<String, false> { |
506 typedef String_Data* DataType; | 521 typedef String_Data* DataType; |
507 }; | 522 }; |
508 | 523 |
509 } // namespace internal | 524 } // namespace internal |
510 } // namespace mojo | 525 } // namespace mojo |
511 | 526 |
512 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ | 527 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ |
OLD | NEW |