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 #include "unified_data.h" 17 18 namespace OHOS { 19 namespace UDMF { GetSize()20int64_t UnifiedData::GetSize() 21 { 22 int64_t totalSize = 0; 23 for (const auto &record : this->records_) { 24 totalSize += record->GetSize(); 25 } 26 return totalSize; 27 } 28 GetGroupId() const29std::string UnifiedData::GetGroupId() const 30 { 31 return this->runtime_->key.groupId; 32 } 33 GetRuntime() const34std::shared_ptr<Runtime> UnifiedData::GetRuntime() const 35 { 36 return this->runtime_; 37 } 38 SetRuntime(Runtime & runtime)39void UnifiedData::SetRuntime(Runtime &runtime) 40 { 41 this->runtime_ = std::make_shared<Runtime>(runtime); 42 } 43 AddRecord(const std::shared_ptr<UnifiedRecord> & record)44void UnifiedData::AddRecord(const std::shared_ptr<UnifiedRecord> &record) 45 { 46 if (record == nullptr) { 47 return; 48 } 49 this->records_.push_back(record); 50 } 51 GetRecordAt(std::size_t index)52std::shared_ptr<UnifiedRecord> UnifiedData::GetRecordAt(std::size_t index) 53 { 54 if (records_.size() > index) { 55 return records_[index]; 56 } 57 return nullptr; 58 } 59 SetRecords(std::vector<std::shared_ptr<UnifiedRecord>> records)60void UnifiedData::SetRecords(std::vector<std::shared_ptr<UnifiedRecord>> records) 61 { 62 this->records_ = std::move(records); 63 } 64 GetRecords() const65std::vector<std::shared_ptr<UnifiedRecord>> UnifiedData::GetRecords() const 66 { 67 return this->records_; 68 } 69 GetUDTypes()70std::vector<UDType> UnifiedData::GetUDTypes() 71 { 72 std::vector<UDType> typeSet; 73 for (const std::shared_ptr<UnifiedRecord> &record : records_) { 74 typeSet.push_back(record->GetType()); 75 } 76 return typeSet; 77 } 78 GetTypes()79std::string UnifiedData::GetTypes() 80 { 81 std::string types; 82 for (const std::shared_ptr<UnifiedRecord> &record : records_) { 83 types.append("-").append(UD_TYPE_MAP.at(record->GetType())); 84 } 85 return types; 86 } 87 IsEmpty() const88bool UnifiedData::IsEmpty() const 89 { 90 return records_.empty(); 91 } 92 } // namespace UDMF 93 } // namespace OHOS