/* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef META_API_NUMBER_H #define META_API_NUMBER_H #include #include #include META_BEGIN_NAMESPACE() template using EnableIfBasicType = BASE_NS::enable_if_t && !BASE_NS::is_convertible_v, IAny&>>; REGISTER_CLASS(Number, "751c6067-4fb8-404b-a240-4fa6f32c725a", ObjectCategoryBits::NO_CATEGORY) class Number { public: Number() : number_(META_NS::GetObjectRegistry().Create(META_NS::ClassId::Number)) {} template> Number(T t) : Number() { if constexpr (is_enum_v) { number_->SetValue(static_cast>(t)); } else { number_->SetValue(t); } } Number(IAny::ConstPtr any) : Number() { number_->CopyFrom(*any); } Number(const IAny& any) : Number() { number_->CopyFrom(any); } template> Number& operator=(T t) { if constexpr (is_enum_v) { number_->SetValue(static_cast>(t)); } else { number_->SetValue(t); } return *this; } Number& operator=(IAny::ConstPtr any) { number_->CopyFrom(*any); return *this; } Number& operator=(const IAny& any) { number_->CopyFrom(any); return *this; } template T Get() const { T t; if constexpr (is_enum_v) { BASE_NS::underlying_type_t ut; number_->GetValue(ut); t = static_cast(ut); } else { number_->GetValue(t); } return t; } private: IAny::Ptr number_; }; META_END_NAMESPACE() #endif