/* * Copyright (c) 2022 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 DATASHARE_PREDICATES_OBJECTS_H #define DATASHARE_PREDICATES_OBJECTS_H #include #include #include namespace OHOS { namespace DataShare { /** * @brief DataShare Predicates Object Type . */ enum class DataSharePredicatesObjectsType { /** Predicates Object Types is null.*/ TYPE_NULL = 0x06, /** Predicates Object Types is int.*/ TYPE_INT_VECTOR, /** Predicates Object Types is long.*/ TYPE_LONG_VECTOR, /** Predicates Object Types is double.*/ TYPE_DOUBLE_VECTOR, /** Predicates Object Types is string.*/ TYPE_STRING_VECTOR, }; /** * @brief Use ObjectType replace DataSharePredicatesObjectsType namespace. */ using ObjectsType = DataSharePredicatesObjectsType; class MutliValue { public: /** * @brief Use Type replace variant namespace. */ using Type = std::variant, std::vector, std::vector, std::vector>; Type value; /** * @brief Constructor. */ MutliValue() = default; /** * @brief Destructor. */ ~MutliValue() = default; /** * @brief Move Constructor. */ MutliValue(MutliValue::Type val) noexcept : value(std::move(val)) { } /** * @brief Copy constructor. */ MutliValue(const MutliValue &val) : value(val.value) {} MutliValue &operator=(MutliValue &&object) noexcept { if (this == &object) { return *this; } value = std::move(object.value); return *this; } MutliValue &operator=(const MutliValue &object) { if (this == &object) { return *this; } value = object.value; return *this; } /** * @brief constructor. * * @param int Specifies the parameter of the type. */ MutliValue(const std::vector &val) : value(val) {} /** * @brief constructor. * * @param int64_t Specifies the parameter of the type. */ MutliValue(const std::vector &val) : value(val) {} /** * @brief constructor. * * @param double Specifies the parameter of the type. */ MutliValue(const std::vector &val) : value(val) {} /** * @brief constructor. * * @param string Specifies the parameter of the type. */ MutliValue(const std::vector &val) : value(val) {} operator std::vector () const { if (std::get_if>(&value) != nullptr) { return std::get>(value); } else { return {}; } } operator std::vector () const { if (std::get_if>(&value) != nullptr) { return std::get>(value); } else { return {}; } } operator std::vector () const { if (std::get_if>(&value) != nullptr) { return std::get>(value); } else { return {}; } } operator std::vector () const { if (std::get_if>(&value) != nullptr) { return std::get>(value); } else { return {}; } } }; } // namespace DataShare } // namespace OHOS #endif