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