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 XML_PARSE_H 17 #define XML_PARSE_H 18 19 #include <libxml/parser.h> 20 #include <libxml/tree.h> 21 #include <vector> 22 #include <string> 23 #include <unordered_map> 24 #include "avcodec_info.h" 25 26 namespace OHOS { 27 namespace Media { 28 class __attribute__((visibility("default"))) XmlParser { 29 public: 30 virtual ~XmlParser(); 31 virtual bool LoadConfiguration(const char *xmlPath) final; 32 virtual bool Parse() final; 33 virtual void Destroy() final; 34 35 protected: 36 xmlDoc *mDoc_ = nullptr; 37 virtual bool ParseInternal(xmlNode *node) = 0; 38 virtual bool SetCapabilityIntData(std::unordered_map<std::string, int32_t&> dataMap, 39 const std::string &capabilityKey, const std::string &capabilityValue) const = 0; 40 virtual bool SetCapabilityVectorData(std::unordered_map<std::string, std::vector<int32_t>&> dataMap, 41 const std::string &capabilityKey, const std::string &capabilityValue) const = 0; 42 virtual bool IsNumberArray(const std::vector<std::string> &strArray) const final; 43 virtual bool TransStrAsRange(const std::string &str, Range &range) const final; 44 virtual std::vector<int32_t> TransMapAsIntegerArray( 45 const std::unordered_map<std::string, int> &capabilityMap, const std::vector<std::string> &spilt) const final; 46 virtual std::vector<int32_t> TransStrAsIntegerArray(const std::vector<std::string> &spilt) const final; 47 virtual bool SpiltKeyList( 48 const std::string &str, const std::string &delim, std::vector<std::string> &spilt) const final; 49 virtual bool SetCapabilityStringData(std::unordered_map<std::string, std::string&> dataMap, 50 const std::string &capabilityKey, const std::string &capabilityValue) const final; 51 virtual bool SetCapabilityBoolData(std::unordered_map<std::string, bool&> dataMap, 52 const std::string &capabilityKey, const std::string &capabilityValue) const final; 53 virtual bool SetCapabilityRangeData(std::unordered_map<std::string, Range&> dataMap, 54 const std::string &capabilityKey, const std::string &capabilityValue) const final; 55 }; 56 } // namespace Media 57 } // namespace OHOS 58 59 #endif // XML_PARSE_H