1 /** 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef LIBPANDAFILE_ANNOTATION_DATA_ACCESSOR_H 17 #define LIBPANDAFILE_ANNOTATION_DATA_ACCESSOR_H 18 19 #include "file.h" 20 #include "helpers.h" 21 #include "value.h" 22 23 namespace panda::panda_file { 24 25 class AnnotationDataAccessor { 26 public: 27 class Elem { 28 public: Elem(const File & panda_file,File::EntityId name_id,uint32_t value)29 Elem(const File &panda_file, File::EntityId name_id, uint32_t value) 30 : panda_file_(panda_file), name_id_(name_id), value_(value) 31 { 32 } 33 ~Elem() = default; 34 35 NO_COPY_SEMANTIC(Elem); 36 NO_MOVE_SEMANTIC(Elem); 37 GetNameId()38 File::EntityId GetNameId() const 39 { 40 return name_id_; 41 } 42 GetScalarValue()43 ScalarValue GetScalarValue() const 44 { 45 return ScalarValue(panda_file_, value_); 46 } 47 GetArrayValue()48 ArrayValue GetArrayValue() const 49 { 50 return ArrayValue(panda_file_, File::EntityId(value_)); 51 } 52 53 private: 54 const File &panda_file_; 55 File::EntityId name_id_; 56 uint32_t value_; 57 }; 58 59 class Tag { 60 public: Tag(char item)61 explicit Tag(char item) : item_(item) {} 62 ~Tag() = default; 63 64 NO_COPY_SEMANTIC(Tag); 65 NO_MOVE_SEMANTIC(Tag); 66 GetItem()67 char GetItem() const 68 { 69 return item_; 70 } 71 72 private: 73 char item_; 74 }; 75 76 AnnotationDataAccessor(const File &panda_file, File::EntityId annotation_id); 77 ~AnnotationDataAccessor() = default; 78 79 NO_COPY_SEMANTIC(AnnotationDataAccessor); 80 NO_MOVE_SEMANTIC(AnnotationDataAccessor); 81 GetClassId()82 File::EntityId GetClassId() const 83 { 84 return File::EntityId(class_off_); 85 } 86 GetCount()87 uint32_t GetCount() const 88 { 89 return count_; 90 } 91 92 Elem GetElement(size_t i) const; 93 94 Tag GetTag(size_t i) const; 95 GetSize()96 size_t GetSize() const 97 { 98 return size_; 99 } 100 GetAnnotationId()101 File::EntityId GetAnnotationId() const 102 { 103 return annotation_id_; 104 } 105 106 private: 107 static constexpr size_t COUNT_SIZE = sizeof(uint16_t); 108 static constexpr size_t VALUE_SIZE = sizeof(uint32_t); 109 static constexpr size_t TYPE_TAG_SIZE = sizeof(uint8_t); 110 111 const File &panda_file_; 112 File::EntityId annotation_id_; 113 114 uint32_t class_off_; 115 uint32_t count_; 116 Span<const uint8_t> elements_sp_ {nullptr, nullptr}; 117 Span<const uint8_t> elements_tags_ {nullptr, nullptr}; 118 size_t size_; 119 }; 120 121 } // namespace panda::panda_file 122 123 #endif // LIBPANDAFILE_ANNOTATION_DATA_ACCESSOR_H 124