1 /* 2 * Copyright (c) 2021 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 FRAMEWORKS_SURFACE_INCLUDE_BUFFER_EXTRA_DATA_IMPL_H 17 #define FRAMEWORKS_SURFACE_INCLUDE_BUFFER_EXTRA_DATA_IMPL_H 18 19 #include <buffer_extra_data.h> 20 21 #include <any> 22 23 namespace OHOS { 24 class BufferExtraDataImpl : public BufferExtraData { 25 public: 26 virtual GSError ReadFromParcel(MessageParcel &parcel) override; 27 virtual GSError WriteToParcel(MessageParcel &parcel) override; 28 virtual GSError ExtraGet(std::string &key, int32_t &value) const override; 29 virtual GSError ExtraGet(std::string &key, int64_t &value) const override; 30 virtual GSError ExtraGet(std::string &key, double &value) const override; 31 virtual GSError ExtraGet(std::string &key, std::string &value) const override; 32 virtual GSError ExtraSet(std::string &key, int32_t value) override; 33 virtual GSError ExtraSet(std::string &key, int64_t value) override; 34 virtual GSError ExtraSet(std::string &key, double value) override; 35 virtual GSError ExtraSet(std::string &key, std::string value) override; 36 37 private: 38 enum class ExtraDataType : int32_t { 39 i32, 40 i64, 41 f64, 42 string, 43 }; 44 template<class T> 45 GSError ExtraGet(std::string &key, ExtraDataType type, T &value) const; 46 GSError ExtraSet(std::string &key, ExtraDataType type, std::any val); 47 48 struct ExtraData { 49 std::any val; 50 ExtraDataType type; 51 }; 52 std::map<std::string, struct ExtraData> datas; 53 }; 54 } // namespace OHOS 55 56 #endif // FRAMEWORKS_SURFACE_INCLUDE_BUFFER_EXTRA_DATA_IMPL_H 57