1 /* 2 * Copyright (c) 2021 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 NATIVE_RDB_VALUE_OBJECT_H 17 #define NATIVE_RDB_VALUE_OBJECT_H 18 19 #include <string> 20 #include <variant> 21 #include <vector> 22 #include <parcel.h> 23 24 namespace OHOS { 25 namespace NativeRdb { 26 27 enum class ValueObjectType { 28 TYPE_NULL = 0, 29 TYPE_INT, 30 TYPE_DOUBLE, 31 TYPE_STRING, 32 TYPE_BLOB, 33 TYPE_BOOL, 34 }; 35 36 class ValueObject : public virtual OHOS::Parcelable { 37 public: 38 ValueObject(); 39 ~ValueObject(); 40 ValueObject(ValueObject &&valueObject) noexcept; 41 ValueObject(const ValueObject &valueObject); 42 explicit ValueObject(int val); 43 explicit ValueObject(int64_t val); 44 explicit ValueObject(double val); 45 explicit ValueObject(bool val); 46 explicit ValueObject(const std::string &val); 47 explicit ValueObject(const std::vector<uint8_t> &blob); 48 ValueObject &operator=(ValueObject &&valueObject) noexcept; 49 ValueObject &operator=(const ValueObject &valueObject); 50 51 ValueObjectType GetType() const; 52 int GetInt(int &val) const; 53 int GetLong(int64_t &val) const; 54 int GetDouble(double &val) const; 55 int GetBool(bool &val) const; 56 int GetString(std::string &val) const; 57 int GetBlob(std::vector<uint8_t> &val) const; 58 59 bool Marshalling(Parcel &parcel) const override; 60 static ValueObject *Unmarshalling(Parcel &parcel); 61 private: 62 ValueObjectType type; 63 std::variant<int64_t, double, std::string, bool, std::vector<uint8_t>> value; 64 }; 65 66 } // namespace NativeRdb 67 } // namespace OHOS 68 #endif 69