1 /* 2 * Copyright (c) 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_MODULE_DATA_ACCESSOR_H 17 #define LIBPANDAFILE_MODULE_DATA_ACCESSOR_H 18 19 #include <cstddef> 20 #include <cstdint> 21 #include <variant> 22 #include <vector> 23 24 #include "macros.h" 25 #include "utils/span.h" 26 #include "file.h" 27 28 namespace panda::panda_file { 29 using StringData = panda_file::File::StringData; 30 31 enum class ModuleTag : uint8_t { 32 REGULAR_IMPORT = 0x00, 33 NAMESPACE_IMPORT = 0x01, 34 LOCAL_EXPORT = 0x02, 35 INDIRECT_EXPORT = 0x03, 36 STAR_EXPORT = 0x04, 37 }; 38 39 class ModuleDataAccessor { 40 public: 41 ModuleDataAccessor(const panda_file::File &panda_file, panda_file::File::EntityId module_data_id); 42 ~ModuleDataAccessor() = default; 43 DEFAULT_MOVE_CTOR(ModuleDataAccessor) 44 DEFAULT_COPY_CTOR(ModuleDataAccessor) 45 NO_MOVE_OPERATOR(ModuleDataAccessor); 46 NO_COPY_OPERATOR(ModuleDataAccessor); 47 48 template <class Callback> 49 inline void EnumerateModuleRecord(const Callback &cb); 50 GetPandaFile()51 const panda_file::File &GetPandaFile() const 52 { 53 return panda_file_; 54 } 55 GetModuleDataId()56 panda_file::File::EntityId GetModuleDataId() const 57 { 58 return module_data_id_; 59 } 60 getRequestModules()61 const std::vector<uint32_t> &getRequestModules() const 62 { 63 return module_requests_; 64 } 65 66 using ModuleValue = std::variant<uint32_t, StringData>; 67 68 private: 69 const panda_file::File &panda_file_; 70 panda_file::File::EntityId module_data_id_; 71 uint32_t num_module_requests_; 72 std::vector<uint32_t> module_requests_; 73 Span<const uint8_t> entry_data_sp_ {nullptr, nullptr}; 74 }; 75 } // namespace panda::panda_file 76 77 #endif // LIBPANDAFILE_MODULE_DATA_ACCESSOR_H 78