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 "text.h" 17 18 namespace OHOS { 19 namespace UDMF { Text()20Text::Text() : UnifiedRecord(TEXT) 21 { 22 } 23 Text(UDDetails & variantMap)24Text::Text(UDDetails &variantMap) : UnifiedRecord(TEXT) 25 { 26 this->details_ = variantMap; 27 } 28 Text(UDType type,ValueType value)29Text::Text(UDType type, ValueType value) : UnifiedRecord(type, value) 30 { 31 SetType(TEXT); 32 if (std::holds_alternative<std::shared_ptr<Object>>(value)) { 33 auto object = std::get<std::shared_ptr<Object>>(value); 34 std::shared_ptr<Object> detailObj = nullptr; 35 if (object->GetValue(DETAILS, detailObj)) { 36 details_ = ObjectUtils::ConvertToUDDetails(detailObj); 37 } 38 hasObject_ = true; 39 } 40 } 41 GetSize()42int64_t Text::GetSize() 43 { 44 return UnifiedDataUtils::GetDetailsSize(this->details_); 45 } 46 SetDetails(UDDetails & variantMap)47void Text::SetDetails(UDDetails &variantMap) 48 { 49 this->details_ = variantMap; 50 if (std::holds_alternative<std::shared_ptr<Object>>(value_)) { 51 std::get<std::shared_ptr<Object>>(value_)->value_[DETAILS] = ObjectUtils::ConvertToObject(details_); 52 } 53 } 54 GetDetails() const55UDDetails Text::GetDetails() const 56 { 57 return this->details_; 58 } 59 InitObject()60void Text::InitObject() 61 { 62 if (!std::holds_alternative<std::shared_ptr<Object>>(value_)) { 63 auto value = value_; 64 value_ = std::make_shared<Object>(); 65 auto object = std::get<std::shared_ptr<Object>>(value_); 66 object->value_[DETAILS] = ObjectUtils::ConvertToObject(details_); 67 object->value_["VALUE_TYPE"] = value; 68 } 69 } 70 } // namespace UDMF 71 } // namespace OHOS 72