mirror of
https://gitee.com/openharmony/distributeddatamgr_relational_store
synced 2024-11-23 07:00:41 +00:00
add commontype
Signed-off-by: yangliu <yangliu178@huawei.com>
This commit is contained in:
parent
5307c061b7
commit
503ae38989
@ -77,7 +77,6 @@
|
||||
"//foundation/distributeddatamgr/relational_store/interfaces/inner_api/rdb_data_share_adapter:rdb_data_share_adapter",
|
||||
"//foundation/distributeddatamgr/relational_store/interfaces/inner_api/rdb:native_rdb",
|
||||
"//foundation/distributeddatamgr/relational_store/interfaces/inner_api/rdb_bms_adapter:rdb_bms_adapter",
|
||||
"//foundation/distributeddatamgr/relational_store/interfaces/inner_api/common_type:common_type",
|
||||
"//foundation/distributeddatamgr/relational_store/frameworks/js/napi/cloud_data:clouddata",
|
||||
"//foundation/distributeddatamgr/relational_store/interfaces/ndk/src:native_rdb_ndk",
|
||||
"//foundation/distributeddatamgr/relational_store/frameworks/js/napi/dataability:dataability",
|
||||
@ -85,7 +84,7 @@
|
||||
"//foundation/distributeddatamgr/relational_store/frameworks/js/napi/rdb:napi_rdb",
|
||||
"//foundation/distributeddatamgr/relational_store/frameworks/js/napi/relationalstore:relationalstore",
|
||||
"//foundation/distributeddatamgr/relational_store/frameworks/js/napi/cloud_extension:cloudextension",
|
||||
"//foundation/distributeddatamgr/relational_store/frameworks/js/napi/common:commontype_napi"
|
||||
"//foundation/distributeddatamgr/relational_store/frameworks/js/napi/common:commontype_napi"
|
||||
],
|
||||
"inner_kits": [
|
||||
{
|
||||
|
@ -1,48 +0,0 @@
|
||||
# Copyright (c) 2021 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.
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/distributeddatamgr/relational_store/relational_store.gni")
|
||||
|
||||
config("common_type_config") {
|
||||
visibility = [ "*:*" ]
|
||||
|
||||
include_dirs = [
|
||||
"include",
|
||||
"${kvstore_path}/common",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_shared_library("common_type") {
|
||||
part_name = "relational_store"
|
||||
|
||||
ldflags = [ "-Wl,--exclude-libs,ALL" ]
|
||||
cflags_cc = [ "-fvisibility=hidden" ]
|
||||
|
||||
public_configs = [ ":common_type_config" ]
|
||||
|
||||
sources = [
|
||||
"src/common_type_util.cpp",
|
||||
"src/common_value_object.cpp",
|
||||
"src/common_values_bucket.cpp",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"ipc:ipc_single",
|
||||
]
|
||||
|
||||
innerapi_tags = [ "platformsdk" ]
|
||||
subsystem_name = "distributeddatamgr"
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 OHOS_COMMONTYPE_ERRNO_H
|
||||
#define OHOS_COMMONTYPE_ERRNO_H
|
||||
|
||||
namespace OHOS {
|
||||
namespace CommonType {
|
||||
|
||||
/**
|
||||
* @brief The error code in the correct case.
|
||||
*/
|
||||
constexpr int E_OK = 0;
|
||||
|
||||
/**
|
||||
* @brief The base code of the exception error code.
|
||||
*/
|
||||
constexpr int E_BASE = 14800000;
|
||||
|
||||
/**
|
||||
* @brief The error code for the object type is invalid.
|
||||
*/
|
||||
constexpr int E_INVALID_OBJECT_TYPE = (E_BASE + 20);
|
||||
} // namespace CommonType
|
||||
} // namespace OHOS
|
||||
#endif
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* 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 OHOS_COMMONTYPE_TYPES_UTIL_H
|
||||
#define OHOS_COMMONTYPE_TYPES_UTIL_H
|
||||
|
||||
#include "itypes_util.h"
|
||||
#include "visibility.h"
|
||||
#include "common_value_object.h"
|
||||
#include "common_values_bucket.h"
|
||||
|
||||
namespace OHOS::ITypesUtil {
|
||||
using ValueObject = CommonType::ValueObject;
|
||||
using ValuesBucket = CommonType::ValuesBucket;
|
||||
using Asset = CommonType::AssetValue;
|
||||
template<>
|
||||
API_EXPORT bool Marshalling(const ValueObject &input, MessageParcel &data);
|
||||
template<>
|
||||
API_EXPORT bool Unmarshalling(ValueObject &output, MessageParcel &data);
|
||||
template<>
|
||||
API_EXPORT bool Marshalling(const ValuesBucket &input, MessageParcel &data);
|
||||
template<>
|
||||
API_EXPORT bool Unmarshalling(ValuesBucket &output, MessageParcel &data);
|
||||
template<>
|
||||
API_EXPORT bool Marshalling(const Asset &input, MessageParcel &data);
|
||||
template<>
|
||||
API_EXPORT bool Unmarshalling(Asset &output, MessageParcel &data);
|
||||
}
|
||||
#endif // OHOS_COMMONTYPE_TYPES_UTIL_H
|
@ -13,9 +13,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_COMMONTYPE_ASSET_VALUE_H
|
||||
#define OHOS_COMMONTYPE_ASSET_VALUE_H
|
||||
#ifndef OHOS_COMMON_TYPES_H
|
||||
#define OHOS_COMMON_TYPES_H
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
namespace OHOS::CommonType {
|
||||
struct AssetValue {
|
||||
enum Status : int32_t {
|
||||
@ -41,5 +43,10 @@ struct AssetValue {
|
||||
std::string hash;
|
||||
std::string path;
|
||||
};
|
||||
using Bytes = std::vector<uint8_t>;
|
||||
using Asset = AssetValue;
|
||||
using Assets = std::vector<AssetValue>;
|
||||
using Value = std::variant<std::monostate, int64_t, double, std::string, bool, Bytes, Asset, Assets>;
|
||||
using ValuesBucket = std::map<std::string, Value>;
|
||||
}
|
||||
#endif // OHOS_COMMONTYPE_H
|
||||
#endif // OHOS_COMMON_TYPES_H
|
@ -1,383 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 OHOS_COMMONTYPE_VALUE_OBJECT_H
|
||||
#define OHOS_COMMONTYPE_VALUE_OBJECT_H
|
||||
|
||||
#include <string>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include "common_asset_value.h"
|
||||
#include "visibility.h"
|
||||
namespace OHOS {
|
||||
namespace CommonType {
|
||||
/**
|
||||
* The ValueObject class of CommonType.
|
||||
*/
|
||||
class API_EXPORT ValueObject {
|
||||
public:
|
||||
/**
|
||||
* @brief Use Type replace std::variant.
|
||||
*/
|
||||
using Nil = std::monostate;
|
||||
using Blob = std::vector<uint8_t>;
|
||||
using Asset = AssetValue;
|
||||
using Assets = std::vector<Asset>;
|
||||
using Type = std::variant<Nil, int64_t, double, std::string, bool, Blob, Asset, Assets>;
|
||||
template<typename Tp, typename... Types>
|
||||
struct index_of : std::integral_constant<size_t, 0> {};
|
||||
|
||||
template<typename Tp, typename... Types>
|
||||
inline static constexpr size_t index_of_v = index_of<Tp, Types...>::value;
|
||||
|
||||
template<typename Tp, typename First, typename... Rest>
|
||||
struct index_of<Tp, First, Rest...>
|
||||
: std::integral_constant<size_t, std::is_same_v<Tp, First> ? 0 : index_of_v<Tp, Rest...> + 1> {};
|
||||
|
||||
template<typename... Types>
|
||||
struct variant_size_of {
|
||||
static constexpr size_t value = sizeof...(Types);
|
||||
};
|
||||
|
||||
template<typename T, typename... Types>
|
||||
struct variant_index_of {
|
||||
static constexpr size_t value = index_of_v<T, Types...>;
|
||||
};
|
||||
|
||||
template<typename... Types>
|
||||
static variant_size_of<Types...> variant_size_test(const std::variant<Types...> &);
|
||||
|
||||
template<typename T, typename... Types>
|
||||
static variant_index_of<T, Types...> variant_index_test(const T &, const std::variant<Types...> &);
|
||||
|
||||
template<typename T>
|
||||
inline constexpr static int32_t TYPE_INDEX =
|
||||
decltype(variant_index_test(std::declval<T>(), std::declval<Type>()))::value;
|
||||
|
||||
inline constexpr static int32_t TYPE_MAX = decltype(variant_size_test(std::declval<Type>()))::value;
|
||||
|
||||
/**
|
||||
* @brief Indicates the ValueObject {@link ValueObject} type.
|
||||
* */
|
||||
enum TypeId : int32_t {
|
||||
/** Indicates the ValueObject type is NULL.*/
|
||||
TYPE_NULL = TYPE_INDEX<Nil>,
|
||||
/** Indicates the ValueObject type is int.*/
|
||||
TYPE_INT = TYPE_INDEX<int64_t>,
|
||||
/** Indicates the ValueObject type is double.*/
|
||||
TYPE_DOUBLE = TYPE_INDEX<double>,
|
||||
/** Indicates the ValueObject type is string.*/
|
||||
TYPE_STRING = TYPE_INDEX<std::string>,
|
||||
/** Indicates the ValueObject type is bool.*/
|
||||
TYPE_BOOL = TYPE_INDEX<bool>,
|
||||
/** Indicates the ValueObject type is blob.*/
|
||||
TYPE_BLOB = TYPE_INDEX<Blob>,
|
||||
/** Indicates the ValueObject type is asset.*/
|
||||
TYPE_ASSET = TYPE_INDEX<Asset>,
|
||||
/** Indicates the ValueObject type is assets.*/
|
||||
TYPE_ASSETS = TYPE_INDEX<Assets>,
|
||||
/** the BUTT.*/
|
||||
TYPE_BUTT = TYPE_MAX
|
||||
};
|
||||
Type value;
|
||||
|
||||
/**
|
||||
* @brief convert a std::variant input to another std::variant output with different (..._Types)
|
||||
*/
|
||||
template<typename T>
|
||||
static inline std::enable_if_t<(TYPE_INDEX<T>) < TYPE_MAX, const char *> DeclType()
|
||||
{
|
||||
return DECLARE_TYPES[TYPE_INDEX<T>];
|
||||
}
|
||||
/**
|
||||
* @brief Constructor.
|
||||
*/
|
||||
API_EXPORT ValueObject();
|
||||
|
||||
/**
|
||||
* @brief Destructor.
|
||||
*/
|
||||
API_EXPORT ~ValueObject();
|
||||
|
||||
/**
|
||||
* @brief Constructor.
|
||||
*
|
||||
* A parameterized constructor used to create a ValueObject instance.
|
||||
*/
|
||||
API_EXPORT ValueObject(Type val) noexcept;
|
||||
|
||||
/**
|
||||
* @brief Move constructor.
|
||||
*/
|
||||
API_EXPORT ValueObject(ValueObject &&val) noexcept;
|
||||
|
||||
/**
|
||||
* @brief Copy constructor.
|
||||
*/
|
||||
API_EXPORT ValueObject(const ValueObject &val);
|
||||
|
||||
/**
|
||||
* @brief Constructor.
|
||||
*
|
||||
* This constructor is used to convert the int input parameter to a value of type ValueObject.
|
||||
*
|
||||
* @param val Indicates an int input parameter.
|
||||
*/
|
||||
API_EXPORT ValueObject(int32_t val);
|
||||
|
||||
/**
|
||||
* @brief Constructor.
|
||||
*
|
||||
* This constructor is used to convert the int64_t input parameter to a value of type ValueObject.
|
||||
*
|
||||
* @param val Indicates an int64_t input parameter.
|
||||
*/
|
||||
API_EXPORT ValueObject(int64_t val);
|
||||
|
||||
/**
|
||||
* @brief Constructor.
|
||||
*
|
||||
* This constructor is used to convert the double input parameter to a value of type ValueObject.
|
||||
*
|
||||
* @param val Indicates an double input parameter.
|
||||
*/
|
||||
API_EXPORT ValueObject(double val);
|
||||
|
||||
/**
|
||||
* @brief Constructor.
|
||||
*
|
||||
* This constructor is used to convert the bool input parameter to a value of type ValueObject.
|
||||
*
|
||||
* @param val Indicates an bool input parameter.
|
||||
*/
|
||||
API_EXPORT ValueObject(bool val);
|
||||
|
||||
/**
|
||||
* @brief Constructor.
|
||||
*
|
||||
* This constructor is used to convert the string input parameter to a value of type ValueObject.
|
||||
*
|
||||
* @param val Indicates an string input parameter.
|
||||
*/
|
||||
API_EXPORT ValueObject(std::string val);
|
||||
|
||||
/**
|
||||
* @brief Constructor.
|
||||
*
|
||||
* This constructor is used to convert the const char * input parameter to a value of type ValueObject.
|
||||
*
|
||||
* @param val Indicates an const char * input parameter.
|
||||
*/
|
||||
API_EXPORT ValueObject(const char *val);
|
||||
|
||||
/**
|
||||
* @brief Constructor.
|
||||
*
|
||||
* This constructor is used to convert the vector<uint8_t> input parameter to a value of type ValueObject.
|
||||
*
|
||||
* @param val Indicates an vector<uint8_t> input parameter.
|
||||
*/
|
||||
API_EXPORT ValueObject(const std::vector<uint8_t> &blob);
|
||||
|
||||
/**
|
||||
* @brief Constructor.
|
||||
*
|
||||
* This constructor is used to convert the Asset input parameter to a value of type ValueObject.
|
||||
*
|
||||
* @param val Indicates an Asset input parameter.
|
||||
*/
|
||||
API_EXPORT ValueObject(Asset val);
|
||||
|
||||
/**
|
||||
* @brief Constructor.
|
||||
*
|
||||
* This constructor is used to convert the Assets input parameter to a value of type ValueObject.
|
||||
*
|
||||
* @param val Indicates an Assets input parameter.
|
||||
*/
|
||||
API_EXPORT ValueObject(Assets val);
|
||||
|
||||
/**
|
||||
* @brief Move assignment operator overloaded function.
|
||||
*/
|
||||
API_EXPORT ValueObject &operator=(ValueObject &&valueObject) noexcept;
|
||||
|
||||
/**
|
||||
* @brief Copy assignment operator overloaded function.
|
||||
*/
|
||||
API_EXPORT ValueObject &operator=(const ValueObject &valueObject);
|
||||
|
||||
/**
|
||||
* @brief Obtains the type in this {@code ValueObject} object.
|
||||
*/
|
||||
API_EXPORT TypeId GetType() const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the int value in this {@code ValueObject} object.
|
||||
*/
|
||||
API_EXPORT int GetInt(int &val) const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the long value in this {@code ValueObject} object.
|
||||
*/
|
||||
API_EXPORT int GetLong(int64_t &val) const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the double value in this {@code ValueObject} object.
|
||||
*/
|
||||
API_EXPORT int GetDouble(double &val) const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the bool value in this {@code ValueObject} object.
|
||||
*/
|
||||
API_EXPORT int GetBool(bool &val) const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the string value in this {@code ValueObject} object.
|
||||
*/
|
||||
API_EXPORT int GetString(std::string &val) const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the vector<uint8_t> value in this {@code ValueObject} object.
|
||||
*/
|
||||
API_EXPORT int GetBlob(std::vector<uint8_t> &val) const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the vector<uint8_t> value in this {@code ValueObject} object.
|
||||
*/
|
||||
API_EXPORT int GetAsset(Asset &val) const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the vector<uint8_t> value in this {@code ValueObject} object.
|
||||
*/
|
||||
API_EXPORT int GetAssets(Assets &val) const;
|
||||
|
||||
/**
|
||||
* @brief Type conversion function.
|
||||
*
|
||||
* @return Returns the int type ValueObject.
|
||||
*/
|
||||
operator int() const
|
||||
{
|
||||
return static_cast<int>(std::get<int64_t>(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Type conversion function.
|
||||
*
|
||||
* @return Returns the int64_t type ValueObject.
|
||||
*/
|
||||
operator int64_t() const
|
||||
{
|
||||
return std::get<int64_t>(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Type conversion function.
|
||||
*
|
||||
* @return Returns the double type ValueObject.
|
||||
*/
|
||||
operator double() const
|
||||
{
|
||||
return std::get<double>(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Type conversion function.
|
||||
*
|
||||
* @return Returns the bool type ValueObject.
|
||||
*/
|
||||
operator bool() const
|
||||
{
|
||||
return std::get<bool>(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Type conversion function.
|
||||
*
|
||||
* @return Returns the string type ValueObject.
|
||||
*/
|
||||
operator std::string() const
|
||||
{
|
||||
return std::get<std::string>(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Type conversion function.
|
||||
*
|
||||
* @return Returns the vector<uint8_t> type ValueObject.
|
||||
*/
|
||||
operator Blob() const
|
||||
{
|
||||
return std::get<Blob>(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Type conversion function.
|
||||
*
|
||||
* @return Returns the vector<uint8_t> type ValueObject.
|
||||
*/
|
||||
operator Asset() const
|
||||
{
|
||||
return std::get<Asset>(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Type conversion function.
|
||||
*
|
||||
* @return Returns the vector<uint8_t> type ValueObject.
|
||||
*/
|
||||
operator Assets() const
|
||||
{
|
||||
return std::get<Assets>(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Type conversion function.
|
||||
*
|
||||
* @return Returns the Type type ValueObject.
|
||||
*/
|
||||
operator Type() const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
private:
|
||||
template<class T>
|
||||
int Get(T &output) const;
|
||||
static constexpr const char *DECLARE_TYPES[TypeId::TYPE_BUTT] = {
|
||||
/** Indicates the ValueObject type is NULL.*/
|
||||
"",
|
||||
/** Indicates the ValueObject type is int.*/
|
||||
"INT",
|
||||
/** Indicates the ValueObject type is double.*/
|
||||
"REAL",
|
||||
/** Indicates the ValueObject type is string.*/
|
||||
"TEXT",
|
||||
/** Indicates the ValueObject type is bool.*/
|
||||
"INT",
|
||||
/** Indicates the ValueObject type is blob.*/
|
||||
"BLOB",
|
||||
/** Indicates the ValueObject type is asset.*/
|
||||
"ASSET",
|
||||
/** Indicates the ValueObject type is assets.*/
|
||||
"ASSETS"
|
||||
};
|
||||
};
|
||||
using ValueObjectType = ValueObject::TypeId;
|
||||
} // namespace CommonType
|
||||
} // namespace OHOS
|
||||
#endif
|
@ -1,176 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 OHOS_COMMONTYPE_VALUE_BUCKET_H
|
||||
#define OHOS_COMMONTYPE_VALUE_BUCKET_H
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
#include "common_value_object.h"
|
||||
namespace OHOS {
|
||||
class Parcel;
|
||||
namespace CommonType {
|
||||
/**
|
||||
* The ValuesBucket class of CommonType.
|
||||
*/
|
||||
class API_EXPORT ValuesBucket {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor.
|
||||
*/
|
||||
API_EXPORT ValuesBucket();
|
||||
|
||||
/**
|
||||
* @brief Constructor.
|
||||
*
|
||||
* A parameterized constructor used to create a ValuesBucket instance.
|
||||
*/
|
||||
API_EXPORT ValuesBucket(std::map<std::string, ValueObject> values);
|
||||
API_EXPORT ValuesBucket(const ValuesBucket &values);
|
||||
API_EXPORT ValuesBucket &operator =(const ValuesBucket &values);
|
||||
API_EXPORT ValuesBucket(ValuesBucket &&values) noexcept;
|
||||
API_EXPORT ValuesBucket &operator =(ValuesBucket &&values) noexcept;
|
||||
|
||||
/**
|
||||
* @brief Destructor.
|
||||
*/
|
||||
API_EXPORT ~ValuesBucket();
|
||||
|
||||
/**
|
||||
* @brief Put the string value to this {@code ValuesBucket} object for the given column name.
|
||||
*
|
||||
* @param columnName Indicates the name of the column.
|
||||
* @param value Indicates the string value.
|
||||
*/
|
||||
API_EXPORT void PutString(const std::string &columnName, const std::string &value);
|
||||
|
||||
/**
|
||||
* @brief Put the int value to this {@code ValuesBucket} object for the given column name.
|
||||
*
|
||||
* @param columnName Indicates the name of the column.
|
||||
* @param value Indicates the int value.
|
||||
*/
|
||||
API_EXPORT void PutInt(const std::string &columnName, int value);
|
||||
|
||||
/**
|
||||
* @brief Put the long value to this {@code ValuesBucket} object for the given column name.
|
||||
*
|
||||
* @param columnName Indicates the name of the column.
|
||||
* @param value Indicates the long value.
|
||||
*/
|
||||
API_EXPORT void PutLong(const std::string &columnName, int64_t value);
|
||||
|
||||
/**
|
||||
* @brief Put the double value to this {@code ValuesBucket} object for the given column name.
|
||||
*
|
||||
* @param columnName Indicates the name of the column.
|
||||
* @param value Indicates the double value.
|
||||
*/
|
||||
API_EXPORT void PutDouble(const std::string &columnName, double value);
|
||||
|
||||
/**
|
||||
* @brief Put the bool value to this {@code ValuesBucket} object for the given column name.
|
||||
*
|
||||
* @param columnName Indicates the name of the column.
|
||||
* @param value Indicates the bool value.
|
||||
*/
|
||||
API_EXPORT void PutBool(const std::string &columnName, bool value);
|
||||
|
||||
/**
|
||||
* @brief Put the vector<uint8_t> value to this {@code ValuesBucket} object for the given column name.
|
||||
*
|
||||
* @param columnName Indicates the name of the column.
|
||||
* @param value Indicates the vector<uint8_t> value.
|
||||
*/
|
||||
API_EXPORT void PutBlob(const std::string &columnName, const std::vector<uint8_t> &value);
|
||||
|
||||
/**
|
||||
* @brief Put NULL to this {@code ValuesBucket} object for the given column name.
|
||||
*
|
||||
* @param columnName Indicates the name of the column.
|
||||
*/
|
||||
API_EXPORT void PutNull(const std::string &columnName);
|
||||
|
||||
/**
|
||||
* @brief Put the integer double bool string bytes asset asset and so on
|
||||
* to this {@code ValuesBucket} object for the given column name.
|
||||
*
|
||||
* @param columnName Indicates the name of the column.
|
||||
*/
|
||||
API_EXPORT void Put(const std::string &columnName, const ValueObject &value);
|
||||
|
||||
/**
|
||||
* @brief Delete the ValueObject object for the given column name.
|
||||
*
|
||||
* @param columnName Indicates the name of the column.
|
||||
*/
|
||||
API_EXPORT void Delete(const std::string &columnName);
|
||||
|
||||
/**
|
||||
* @brief Clear the ValuesBucket object's valuesmap.
|
||||
*/
|
||||
API_EXPORT void Clear();
|
||||
|
||||
/**
|
||||
* @brief Obtains the ValuesBucket object's valuesmap size.
|
||||
*/
|
||||
API_EXPORT int Size() const;
|
||||
|
||||
/**
|
||||
* @brief Checks whether the ValuesBucket object's valuesmap is empty.
|
||||
*/
|
||||
API_EXPORT bool IsEmpty() const;
|
||||
|
||||
/**
|
||||
* @brief Checks whether the ValuesBucket object's valuesmap contain the specified columnName.
|
||||
*
|
||||
* @param columnName Indicates the name of the column.
|
||||
*/
|
||||
API_EXPORT bool HasColumn(const std::string &columnName) const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the specified value for the given column name.
|
||||
*
|
||||
* @param columnName Indicates the name of the column.
|
||||
*/
|
||||
API_EXPORT bool GetObject(const std::string &columnName, ValueObject &value) const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the ValuesBucket object's valuesmap.
|
||||
*/
|
||||
API_EXPORT std::map<std::string, ValueObject> GetAll() const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the ValuesBucket object's valuesmap.
|
||||
*/
|
||||
API_EXPORT void GetAll(std::map<std::string, ValueObject> &output) const;
|
||||
|
||||
/**
|
||||
* @brief set a ValuesBucket object to parcel.
|
||||
*/
|
||||
API_EXPORT bool Marshalling(Parcel &parcel) const;
|
||||
|
||||
/**
|
||||
* @brief Obtains a ValuesBucket object from parcel.
|
||||
*/
|
||||
API_EXPORT static ValuesBucket Unmarshalling(Parcel &parcel);
|
||||
|
||||
std::map<std::string, ValueObject> values_;
|
||||
};
|
||||
|
||||
} // namespace CommonType
|
||||
} // namespace OHOS
|
||||
#endif
|
@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 COMMON_TYPE_VISIBILITY_H
|
||||
#define COMMON_TYPE_VISIBILITY_H
|
||||
#ifndef API_EXPORT
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define API_EXPORT __attribute__((visibility ("default")))
|
||||
#else
|
||||
#define API_EXPORT
|
||||
#endif
|
||||
#endif
|
||||
#endif // COMMON_TYPE_VISIBILITY_H
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "common_type_util.h"
|
||||
namespace OHOS::ITypesUtil {
|
||||
template<>
|
||||
bool Marshalling(const ValueObject &input, MessageParcel &data)
|
||||
{
|
||||
return Marshal(data, input.value);
|
||||
}
|
||||
template<>
|
||||
bool Unmarshalling(ValueObject &output, MessageParcel &data)
|
||||
{
|
||||
return Unmarshal(data, output.value);
|
||||
}
|
||||
|
||||
template<>
|
||||
bool Marshalling(const ValuesBucket &input, MessageParcel &data)
|
||||
{
|
||||
return Marshal(data, input.values_);
|
||||
}
|
||||
template<>
|
||||
bool Unmarshalling(ValuesBucket &output, MessageParcel &data)
|
||||
{
|
||||
return Unmarshal(data, output.values_);
|
||||
}
|
||||
|
||||
template<>
|
||||
bool Marshalling(const Asset &input, MessageParcel &data)
|
||||
{
|
||||
return Marshal(data, input.name, input.uri, input.path, input.createTime,
|
||||
input.modifyTime, input.size, input.status, input.hash);
|
||||
}
|
||||
template<>
|
||||
bool Unmarshalling(Asset &output, MessageParcel &data)
|
||||
{
|
||||
return Unmarshal(data, output.name, output.uri, output.path, output.createTime,
|
||||
output.modifyTime, output.size, output.status, output.hash);
|
||||
}
|
||||
}
|
@ -1,183 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#include "common_value_object.h"
|
||||
#include "common_errno.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CommonType {
|
||||
ValueObject::ValueObject()
|
||||
{
|
||||
}
|
||||
|
||||
ValueObject::ValueObject(Type val) noexcept : value(std::move(val))
|
||||
{
|
||||
}
|
||||
|
||||
ValueObject::ValueObject(ValueObject &&val) noexcept
|
||||
{
|
||||
if (this == &val) {
|
||||
return;
|
||||
}
|
||||
value = std::move(val.value);
|
||||
}
|
||||
|
||||
ValueObject::ValueObject(const ValueObject &val)
|
||||
{
|
||||
if (this == &val) {
|
||||
return;
|
||||
}
|
||||
value = val.value;
|
||||
}
|
||||
|
||||
ValueObject::~ValueObject()
|
||||
{
|
||||
}
|
||||
|
||||
ValueObject::ValueObject(int val) : value(static_cast<int64_t>(val))
|
||||
{
|
||||
}
|
||||
|
||||
ValueObject::ValueObject(int64_t val) : value(val)
|
||||
{
|
||||
}
|
||||
|
||||
ValueObject::ValueObject(double val) : value(val)
|
||||
{
|
||||
}
|
||||
|
||||
ValueObject::ValueObject(bool val) : value(val)
|
||||
{
|
||||
}
|
||||
|
||||
ValueObject::ValueObject(std::string val) : value(std::move(val))
|
||||
{
|
||||
}
|
||||
|
||||
ValueObject::ValueObject(const char *val) : ValueObject(std::string(val))
|
||||
{
|
||||
}
|
||||
|
||||
ValueObject::ValueObject(const std::vector<uint8_t> &val) : value(val)
|
||||
{
|
||||
}
|
||||
|
||||
ValueObject::ValueObject(ValueObject::Asset val) : value(std::move(val))
|
||||
{
|
||||
}
|
||||
|
||||
ValueObject::ValueObject(ValueObject::Assets val) : value(std::move(val))
|
||||
{
|
||||
}
|
||||
|
||||
ValueObject &ValueObject::operator=(ValueObject &&val) noexcept
|
||||
{
|
||||
if (this == &val) {
|
||||
return *this;
|
||||
}
|
||||
value = std::move(val.value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
ValueObject &ValueObject::operator=(const ValueObject &val)
|
||||
{
|
||||
if (this == &val) {
|
||||
return *this;
|
||||
}
|
||||
value = val.value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ValueObjectType ValueObject::GetType() const
|
||||
{
|
||||
return ValueObjectType(value.index());
|
||||
}
|
||||
|
||||
int ValueObject::GetInt(int &val) const
|
||||
{
|
||||
int64_t value = 0;
|
||||
auto ret = Get(value);
|
||||
val = value;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ValueObject::GetLong(int64_t &val) const
|
||||
{
|
||||
return Get(val);
|
||||
}
|
||||
|
||||
int ValueObject::GetDouble(double &val) const
|
||||
{
|
||||
return Get(val);
|
||||
}
|
||||
|
||||
int ValueObject::GetBool(bool &val) const
|
||||
{
|
||||
return Get(val);
|
||||
}
|
||||
|
||||
int ValueObject::GetString(std::string &val) const
|
||||
{
|
||||
if (Get(val) == 0) {
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
double ftmp;
|
||||
if (Get(ftmp) == 0) {
|
||||
val = std::to_string(ftmp);
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int64_t itmp;
|
||||
if (Get(itmp) == 0) {
|
||||
val = std::to_string(itmp);
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
bool btmp;
|
||||
if (Get(btmp) == 0) {
|
||||
val = std::to_string(btmp);
|
||||
return E_OK;
|
||||
}
|
||||
return E_INVALID_OBJECT_TYPE;
|
||||
}
|
||||
|
||||
int ValueObject::GetBlob(std::vector<uint8_t> &val) const
|
||||
{
|
||||
return Get(val);
|
||||
}
|
||||
|
||||
int ValueObject::GetAsset(Asset &val) const
|
||||
{
|
||||
return Get(val);
|
||||
}
|
||||
|
||||
int ValueObject::GetAssets(Assets &val) const
|
||||
{
|
||||
return Get(val);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
int ValueObject::Get(T &output) const
|
||||
{
|
||||
const T *v = std::get_if<T>(&value);
|
||||
if (v == nullptr) {
|
||||
return E_INVALID_OBJECT_TYPE;
|
||||
}
|
||||
output = static_cast<T>(*v);
|
||||
return E_OK;
|
||||
}
|
||||
} // namespace CommonType
|
||||
} // namespace OHOS
|
@ -1,162 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#include "common_values_bucket.h"
|
||||
#include "itypes_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CommonType {
|
||||
ValuesBucket::ValuesBucket()
|
||||
{
|
||||
}
|
||||
|
||||
ValuesBucket::ValuesBucket(std::map<std::string, ValueObject> values) : values_(std::move(values))
|
||||
{
|
||||
}
|
||||
|
||||
ValuesBucket::ValuesBucket(const ValuesBucket &values) : values_(values.values_)
|
||||
{
|
||||
}
|
||||
|
||||
ValuesBucket &ValuesBucket::operator=(const ValuesBucket &values)
|
||||
{
|
||||
values_ = values.values_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ValuesBucket::ValuesBucket(ValuesBucket &&values) noexcept : values_(std::move(values.values_))
|
||||
{
|
||||
}
|
||||
|
||||
ValuesBucket &ValuesBucket::operator=(ValuesBucket &&values) noexcept
|
||||
{
|
||||
values_ = std::move(values.values_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
ValuesBucket::~ValuesBucket()
|
||||
{
|
||||
}
|
||||
|
||||
void ValuesBucket::PutString(const std::string &columnName, const std::string &value)
|
||||
{
|
||||
values_.insert(std::make_pair(columnName, ValueObject(value)));
|
||||
}
|
||||
|
||||
void ValuesBucket::PutInt(const std::string &columnName, int value)
|
||||
{
|
||||
values_.insert(std::make_pair(columnName, ValueObject(value)));
|
||||
}
|
||||
|
||||
void ValuesBucket::PutLong(const std::string &columnName, int64_t value)
|
||||
{
|
||||
values_.insert(std::make_pair(columnName, ValueObject(value)));
|
||||
}
|
||||
|
||||
void ValuesBucket::PutDouble(const std::string &columnName, double value)
|
||||
{
|
||||
values_.insert(std::make_pair(columnName, ValueObject(value)));
|
||||
}
|
||||
|
||||
void ValuesBucket::PutBool(const std::string &columnName, bool value)
|
||||
{
|
||||
values_.insert(std::make_pair(columnName, ValueObject(value)));
|
||||
}
|
||||
|
||||
void ValuesBucket::PutBlob(const std::string &columnName, const std::vector<uint8_t> &value)
|
||||
{
|
||||
values_.insert(std::make_pair(columnName, ValueObject(value)));
|
||||
}
|
||||
|
||||
void ValuesBucket::PutNull(const std::string &columnName)
|
||||
{
|
||||
values_.insert(std::make_pair(columnName, ValueObject()));
|
||||
}
|
||||
|
||||
void ValuesBucket::Put(const std::string &columnName, const ValueObject &value)
|
||||
{
|
||||
values_.insert_or_assign(columnName, value);
|
||||
}
|
||||
|
||||
void ValuesBucket::Delete(const std::string &columnName)
|
||||
{
|
||||
values_.erase(columnName);
|
||||
}
|
||||
|
||||
void ValuesBucket::Clear()
|
||||
{
|
||||
values_.clear();
|
||||
}
|
||||
|
||||
int ValuesBucket::Size() const
|
||||
{
|
||||
return values_.size();
|
||||
}
|
||||
|
||||
bool ValuesBucket::IsEmpty() const
|
||||
{
|
||||
return values_.empty();
|
||||
}
|
||||
|
||||
bool ValuesBucket::HasColumn(const std::string &columnName) const
|
||||
{
|
||||
auto iter = values_.find(columnName);
|
||||
if (iter == values_.end()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ValuesBucket::GetObject(const std::string &columnName, ValueObject &value) const
|
||||
{
|
||||
auto iter = values_.find(columnName);
|
||||
if (iter == values_.end()) {
|
||||
return false;
|
||||
}
|
||||
value = iter->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::map<std::string, ValueObject> ValuesBucket::GetAll() const
|
||||
{
|
||||
return values_;
|
||||
}
|
||||
|
||||
void ValuesBucket::GetAll(std::map<std::string, ValueObject> &output) const
|
||||
{
|
||||
output = values_;
|
||||
}
|
||||
|
||||
bool ValuesBucket::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
MessageParcel *data = static_cast<MessageParcel *>(&parcel);
|
||||
if (data == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return ITypesUtil::Marshal(*data, values_);
|
||||
}
|
||||
|
||||
ValuesBucket ValuesBucket::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
MessageParcel *data = static_cast<MessageParcel *>(&parcel);
|
||||
if (data == nullptr) {
|
||||
return {};
|
||||
}
|
||||
ValuesBucket bucket;
|
||||
ITypesUtil::Unmarshal(*data, bucket.values_);
|
||||
return bucket;
|
||||
}
|
||||
} // namespace CommonType
|
||||
} // namespace OHOS
|
Loading…
Reference in New Issue
Block a user