Chromium Code Reviews| Index: mojo/public/cpp/bindings/array_traits_carray.h |
| diff --git a/mojo/public/cpp/bindings/array_traits_carray.h b/mojo/public/cpp/bindings/array_traits_carray.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9efa88bb648e7170e06610af5ccaf271b37081ca |
| --- /dev/null |
| +++ b/mojo/public/cpp/bindings/array_traits_carray.h |
| @@ -0,0 +1,53 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_CARRAY_H_ |
| +#define MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_CARRAY_H_ |
| + |
| +#include <vector> |
|
yzshen1
2016/06/07 22:29:29
No need to have this include.
Fady Samuel
2016/06/08 00:50:06
Done.
|
| + |
| +#include "mojo/public/cpp/bindings/array_traits.h" |
| + |
| +namespace mojo { |
| + |
| +template <typename T> |
| +struct CArray { |
| + CArray() : size(0), max_size(0), data(nullptr) {} |
| + explicit CArray(size_t max_size) |
| + : size(0), max_size(max_size), data(nullptr) {} |
| + CArray(size_t size, size_t max_size, T* data) |
| + : size(size), max_size(max_size), data(data) {} |
| + size_t size; |
| + size_t max_size; |
|
yzshen1
2016/06/07 22:29:29
Does it make sense to:
- either making this const
Fady Samuel
2016/06/08 00:50:06
Made it const. I'd prefer not to have it in and ou
|
| + T* data; |
| +}; |
| + |
| +template <typename T> |
| +struct ArrayTraits<CArray<T>> { |
| + using Element = T; |
| + |
| + static size_t GetSize(const CArray<T>& input) { return input.size; } |
| + |
| + static T* GetData(CArray<T>& input) { return input.data; } |
| + |
| + static const T* GetData(const CArray<T>& input) { return input.data; } |
| + |
| + static T& GetAt(CArray<T>& input, size_t index) { return input.data[index]; } |
| + |
| + static const T& GetAt(const CArray<T>& input, size_t index) { |
| + return input.data[index]; |
| + } |
| + |
| + static bool Resize(CArray<T>& input, size_t size) { |
| + if (size > input.max_size) |
| + return false; |
| + |
| + input.size = size; |
| + return true; |
| + } |
| +}; |
| + |
| +} // namespace mojo |
| + |
| +#endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_CARRAY_H_ |