James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2021 Google Inc. All rights reserved. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef FLATBUFFERS_STRUCT_H_ |
| 18 | #define FLATBUFFERS_STRUCT_H_ |
| 19 | |
| 20 | #include "flatbuffers/base.h" |
| 21 | |
| 22 | namespace flatbuffers { |
| 23 | |
| 24 | // "structs" are flat structures that do not have an offset table, thus |
| 25 | // always have all members present and do not support forwards/backwards |
| 26 | // compatible extensions. |
| 27 | |
| 28 | class Struct FLATBUFFERS_FINAL_CLASS { |
| 29 | public: |
| 30 | template<typename T> T GetField(uoffset_t o) const { |
| 31 | return ReadScalar<T>(&data_[o]); |
| 32 | } |
| 33 | |
| 34 | template<typename T> T GetStruct(uoffset_t o) const { |
| 35 | return reinterpret_cast<T>(&data_[o]); |
| 36 | } |
| 37 | |
| 38 | const uint8_t *GetAddressOf(uoffset_t o) const { return &data_[o]; } |
| 39 | uint8_t *GetAddressOf(uoffset_t o) { return &data_[o]; } |
| 40 | |
| 41 | private: |
| 42 | // private constructor & copy constructor: you obtain instances of this |
| 43 | // class by pointing to existing data only |
| 44 | Struct(); |
| 45 | Struct(const Struct &); |
| 46 | Struct &operator=(const Struct &); |
| 47 | |
| 48 | uint8_t data_[1]; |
| 49 | }; |
| 50 | |
| 51 | } // namespace flatbuffers |
| 52 | |
| 53 | #endif // FLATBUFFERS_STRUCT_H_ |