1 /** 2 * Copyright (c) 2024-2025 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 ABC2PROGRAM_ABC_FILE_ENTITY_PROCESSOR_H 17 #define ABC2PROGRAM_ABC_FILE_ENTITY_PROCESSOR_H 18 19 #include "abc2program_key_data.h" 20 #include "abc2program_log.h" 21 #include "abc_file_utils.h" 22 23 namespace ark::abc2program { 24 25 class AbcFileEntityProcessor { 26 public: 27 AbcFileEntityProcessor(panda_file::File::EntityId entityId, Abc2ProgramKeyData &keyData); 28 29 protected: 30 template <typename T> SetEntityAttribute(T & entity,const std::function<bool ()> & shouldSet,std::string_view attribute)31 static void SetEntityAttribute(T &entity, const std::function<bool()> &shouldSet, std::string_view attribute) 32 { 33 LOG(DEBUG, ABC2PROGRAM) << attribute; 34 if (shouldSet()) { 35 auto err = entity.metadata->SetAttribute(attribute); 36 if (err.has_value()) { 37 LOG(DEBUG, ABC2PROGRAM) << err.value().GetMessage(); 38 } 39 } 40 } 41 42 template <typename T> SetEntityAttributeValue(T & entity,const std::function<bool ()> & shouldSet,std::string_view attribute,const char * value)43 static void SetEntityAttributeValue(T &entity, const std::function<bool()> &shouldSet, std::string_view attribute, 44 const char *value) 45 { 46 LOG(DEBUG, ABC2PROGRAM) << attribute; 47 if (shouldSet()) { 48 auto err = entity.metadata->SetAttributeValue(attribute, value); 49 if (err.has_value()) { 50 LOG(DEBUG, ABC2PROGRAM) << err.value().GetMessage(); 51 } 52 } 53 } 54 panda_file::File::EntityId entityId_; // NOLINT(misc-non-private-member-variables-in-classes) 55 Abc2ProgramKeyData &keyData_; // NOLINT(misc-non-private-member-variables-in-classes) 56 const panda_file::File *file_ = nullptr; // NOLINT(misc-non-private-member-variables-in-classes) 57 AbcStringTable *stringTable_ = nullptr; // NOLINT(misc-non-private-member-variables-in-classes) 58 pandasm::Program *program_ = nullptr; // NOLINT(misc-non-private-member-variables-in-classes) 59 friend class AbcFileProcessor; // NOLINT(misc-non-private-member-variables-in-classes) 60 }; // class AbcFileEntityProcessor 61 62 } // namespace ark::abc2program 63 64 #endif // ABC2PROGRAM_ABC_FILE_ENTITY_PROCESSOR_H 65