1 // Copyright (C) 2016 The Android Open Source Project 2 // 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 #ifndef ABI_DIFF_WRAPPERS_H 16 #define ABI_DIFF_WRAPPERS_H 17 18 #pragma clang diagnostic push 19 #pragma clang diagnostic ignored "-Wunused-parameter" 20 #pragma clang diagnostic ignored "-Wnested-anon-types" 21 #include "proto/abi_dump.pb.h" 22 #include "proto/abi_diff.pb.h" 23 #pragma clang diagnostic pop 24 25 namespace abi_diff_wrappers { 26 27 template <typename T> 28 static bool IgnoreSymbol(const T *element, 29 const std::set<std::string> &ignored_symbols) { 30 return ignored_symbols.find(element->basic_abi().linker_set_key()) != 31 ignored_symbols.end(); 32 } 33 34 template <typename T, typename TDiff> 35 class DiffWrapperBase { 36 public: 37 virtual std::unique_ptr<TDiff> Get() = 0 ; 38 protected: 39 DiffWrapperBase(const T *oldp, const T *newp) : oldp_(oldp), newp_(newp) { } 40 template <typename Element, typename ElementDiff> 41 bool GetElementDiffs( 42 google::protobuf::RepeatedPtrField<ElementDiff> *dst, 43 const google::protobuf::RepeatedPtrField<Element> &old_elements, 44 const google::protobuf::RepeatedPtrField<Element> &new_elements); 45 46 private: 47 template <typename Element, typename ElementDiff> 48 void GetExtraElementDiffs( 49 google::protobuf::RepeatedPtrField<ElementDiff> *dst, int i, int j, 50 const google::protobuf::RepeatedPtrField<Element> &old_elements, 51 const google::protobuf::RepeatedPtrField<Element> &new_elements); 52 53 protected: 54 const T *oldp_; 55 const T *newp_; 56 }; 57 58 template <typename T, typename TDiff> 59 class DiffWrapper : public DiffWrapperBase<T, TDiff> { 60 public: 61 DiffWrapper(const T *oldp, const T *newp) 62 : DiffWrapperBase<T, TDiff>(oldp, newp) { } 63 std::unique_ptr<TDiff> Get() override; 64 }; 65 66 } // abi_diff_wrappers 67 68 #endif // ABI_DIFF_WRAPPERS_H 69