1 /* 2 * Copyright (C) 2024 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 RINGTONE_FETCH_RESULT_H 17 #define RINGTONE_FETCH_RESULT_H 18 19 #include "abs_shared_result_set.h" 20 #include "datashare_result_set.h" 21 #include "rdb_errno.h" 22 #include "ringtone_asset.h" 23 #include "vibrate_asset.h" 24 #include "ringtone_db_const.h" 25 #include "ringtone_type.h" 26 #include "simcard_setting_asset.h" 27 28 namespace OHOS { 29 namespace Media { 30 #define EXPORT __attribute__ ((visibility ("default"))) 31 /** 32 * @brief Class for returning the data cursor to application. 33 * 34 * @since 1.0 35 * @version 1.0 36 */ 37 template <class T> 38 class RingtoneFetchResult { 39 public: 40 EXPORT explicit RingtoneFetchResult(const std::shared_ptr<DataShare::DataShareResultSet> &resultset); 41 EXPORT RingtoneFetchResult(); 42 EXPORT virtual ~RingtoneFetchResult(); 43 44 EXPORT void Close(); 45 EXPORT int32_t GetCount(); 46 EXPORT bool IsAtLastRow(); 47 48 EXPORT std::shared_ptr<DataShare::DataShareResultSet> &GetDataShareResultSet(); 49 50 EXPORT std::unique_ptr<T> GetObjectAtPosition(int32_t index); 51 EXPORT std::unique_ptr<T> GetFirstObject(); 52 EXPORT std::unique_ptr<T> GetObjectFromRdb(std::shared_ptr<NativeRdb::ResultSet> &resultSet, int idx); 53 EXPORT std::unique_ptr<T> GetNextObject(); 54 EXPORT std::unique_ptr<T> GetLastObject(); 55 EXPORT std::unique_ptr<T> GetObject(); 56 57 private: 58 EXPORT std::unique_ptr<T> GetObject(std::shared_ptr<NativeRdb::ResultSet> &resultSet); 59 EXPORT std::variant<int32_t, int64_t, std::string, double> GetRowValFromColumn(std::string columnName, 60 RingtoneResultSetDataType dataType, std::shared_ptr<NativeRdb::ResultSet> &resultSet); 61 std::variant<int32_t, int64_t, std::string, double> GetValByIndex(int32_t index, RingtoneResultSetDataType dataType, 62 std::shared_ptr<NativeRdb::ResultSet> &resultSet); 63 64 void SetRingtoneAsset(std::unique_ptr<T>& asset, std::shared_ptr<NativeRdb::ResultSet> &resultSet); 65 66 void GetObjectFromResultSet(std::unique_ptr<T>& asset, std::shared_ptr<NativeRdb::ResultSet> &resultSet); 67 68 std::shared_ptr<DataShare::DataShareResultSet> resultset_ = nullptr; 69 }; 70 } // namespace Media 71 } // namespace OHOS 72 73 #endif // INTERFACES_INNERKITS_NATIVE_INCLUDE_FETCH_RESULT_H 74