OLD | NEW |
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 // Functions to help with verifying various |Mojo...Options| structs from the | 5 // Functions to help with verifying various |Mojo...Options| structs from the |
6 // (public, C) API. These are "extensible" structs, which all have |struct_size| | 6 // (public, C) API. These are "extensible" structs, which all have |struct_size| |
7 // as their first member. All fields (other than |struct_size|) are optional, | 7 // as their first member. All fields (other than |struct_size|) are optional, |
8 // but any |flags| specified must be known to the system (otherwise, an error of | 8 // but any |flags| specified must be known to the system (otherwise, an error of |
9 // |MOJO_RESULT_UNIMPLEMENTED| should be returned). | 9 // |MOJO_RESULT_UNIMPLEMENTED| should be returned). |
10 | 10 |
11 #ifndef MOJO_EDK_SYSTEM_OPTIONS_VALIDATION_H_ | 11 #ifndef MOJO_EDK_SYSTEM_OPTIONS_VALIDATION_H_ |
12 #define MOJO_EDK_SYSTEM_OPTIONS_VALIDATION_H_ | 12 #define MOJO_EDK_SYSTEM_OPTIONS_VALIDATION_H_ |
13 | 13 |
14 #include <stddef.h> | 14 #include <stddef.h> |
15 #include <stdint.h> | 15 #include <stdint.h> |
16 | 16 |
17 #include <algorithm> | 17 #include <algorithm> |
18 | 18 |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
20 #include "mojo/edk/system/system_impl_export.h" | 20 #include "mojo/edk/system/system_impl_export.h" |
21 #include "mojo/public/c/system/types.h" | 21 #include "third_party/mojo/src/mojo/public/c/system/types.h" |
22 #include "mojo/public/cpp/system/macros.h" | 22 #include "third_party/mojo/src/mojo/public/cpp/system/macros.h" |
23 | 23 |
24 namespace mojo { | 24 namespace mojo { |
25 namespace edk { | 25 namespace edk { |
26 | 26 |
27 template <class Options> | 27 template <class Options> |
28 class UserOptionsReader { | 28 class UserOptionsReader { |
29 public: | 29 public: |
30 // Constructor from a |const* Options| (which it checks -- this constructor | 30 // Constructor from a |const* Options| (which it checks -- this constructor |
31 // has side effects!). | 31 // has side effects!). |
32 // Note: We initialize |options_reader_| without checking, since we do a check | 32 // Note: We initialize |options_reader_| without checking, since we do a check |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 // TODO(vtl): With C++11, use |sizeof(Options::member)| instead of (the | 88 // TODO(vtl): With C++11, use |sizeof(Options::member)| instead of (the |
89 // contortion below). We might also be able to pull out the type |Options| from | 89 // contortion below). We might also be able to pull out the type |Options| from |
90 // |reader| (using |decltype|) instead of requiring a parameter. | 90 // |reader| (using |decltype|) instead of requiring a parameter. |
91 #define OPTIONS_STRUCT_HAS_MEMBER(Options, member, reader) \ | 91 #define OPTIONS_STRUCT_HAS_MEMBER(Options, member, reader) \ |
92 reader.HasMember(offsetof(Options, member), sizeof(reader.options().member)) | 92 reader.HasMember(offsetof(Options, member), sizeof(reader.options().member)) |
93 | 93 |
94 } // namespace edk | 94 } // namespace edk |
95 } // namespace mojo | 95 } // namespace mojo |
96 | 96 |
97 #endif // MOJO_EDK_SYSTEM_OPTIONS_VALIDATION_H_ | 97 #endif // MOJO_EDK_SYSTEM_OPTIONS_VALIDATION_H_ |
OLD | NEW |