1 /* 2 * Copyright (c) 2023 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 UDMF_UNIFIED_RECORD_H 17 #define UDMF_UNIFIED_RECORD_H 18 19 #include <memory> 20 #include <string> 21 #include <vector> 22 #include "entry_getter.h" 23 #include "visibility.h" 24 #include "unified_types.h" 25 26 namespace OHOS { 27 namespace UDMF { 28 class API_EXPORT UnifiedRecord { 29 public: 30 UnifiedRecord(); 31 explicit UnifiedRecord(UDType type); 32 UnifiedRecord(UDType type, ValueType value); 33 virtual ~UnifiedRecord() = default; 34 35 UDType GetType() const; 36 void SetType(const UDType &type); 37 virtual int64_t GetSize(); 38 39 std::string GetUid() const; 40 void SetUid(const std::string &id); 41 ValueType GetValue(); 42 void SetValue(const ValueType &value); 43 ValueType GetOriginValue() const; 44 45 void SetUtdId(const std::string &utdId); 46 std::set<std::string> GetUtdIds() const; 47 std::string GetUtdId() const; 48 49 bool HasType(const std::string &utdId) const; 50 void AddEntry(const std::string &utdId, ValueType &&value); 51 ValueType GetEntry(const std::string &utdId); 52 std::shared_ptr<std::map<std::string, ValueType>> GetEntries() const; 53 54 void SetEntryGetter(const std::vector<std::string> &utdIds, const std::shared_ptr<EntryGetter> &entryGetter); 55 std::shared_ptr<EntryGetter> GetEntryGetter(); 56 void SetDataId(uint32_t dataId); 57 uint32_t GetDataId() const; 58 void SetRecordId(uint32_t recordId); 59 uint32_t GetRecordId() const; 60 void SetChannelName(const std::string &channelName); 61 62 virtual void InitObject(); 63 bool HasObject(); 64 protected: 65 static constexpr const char *UNIFORM_DATA_TYPE = "uniformDataType"; 66 static constexpr const char *DETAILS = "details"; 67 UDType dataType_; 68 ValueType value_; 69 bool hasObject_ = false; 70 private: 71 std::string uid_; // unique identifier 72 std::string utdId_; 73 std::shared_ptr<std::map<std::string, ValueType>> entries_ = std::make_shared<std::map<std::string, ValueType>>(); 74 uint32_t dataId_ = 0; 75 uint32_t recordId_ = 0; 76 std::string channelName_; 77 std::shared_ptr<EntryGetter> entryGetter_; 78 }; 79 } // namespace UDMF 80 } // namespace OHOS 81 #endif // UDMF_UNIFIED_RECORD_H 82