2
* Copyright (C) 2016 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this library; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef __LIBFM_QT_FM_LIST_H__
21
#define __LIBFM_QT_FM_LIST_H__
26
#include "libfmqtglobals.h"
32
class LIBFM_QT_API List {
36
List(FmListFuncs* funcs) {
37
dataPtr_ = reinterpret_cast<FmList*>(fm_list_new(funcs));
41
// default constructor
47
List(FmList* dataPtr){
48
dataPtr_ = dataPtr != nullptr ? reinterpret_cast<FmList*>(fm_list_ref(dataPtr)) : nullptr;
53
List(const List& other) {
54
dataPtr_ = other.dataPtr_ != nullptr ? reinterpret_cast<FmList*>(fm_list_ref(other.dataPtr_)) : nullptr;
60
dataPtr_ = reinterpret_cast<FmList*>(other.takeDataPtr());
66
if(dataPtr_ != nullptr) {
67
fm_list_unref(dataPtr_);
72
// create a wrapper for the data pointer without increasing the reference count
73
static List wrapPtr(FmList* dataPtr) {
75
obj.dataPtr_ = reinterpret_cast<FmList*>(dataPtr);
79
// disown the managed data pointer
80
FmList* takeDataPtr() {
81
FmList* data = reinterpret_cast<FmList*>(dataPtr_);
86
// get the raw pointer wrapped
88
return reinterpret_cast<FmList*>(dataPtr_);
91
// automatic type casting
96
// automatic type casting
103
List& operator=(const List& other) {
104
if(dataPtr_ != nullptr) {
105
fm_list_unref(dataPtr_);
107
dataPtr_ = other.dataPtr_ != nullptr ? reinterpret_cast<FmList*>(fm_list_ref(other.dataPtr_)) : nullptr;
113
List& operator=(List&& other) {
114
dataPtr_ = reinterpret_cast<FmList*>(other.takeDataPtr());
119
return (dataPtr_ == nullptr);
124
void deleteLink(GList* l_) {
125
fm_list_delete_link(dataPtr(), l_);
129
void removeAll(gpointer data) {
130
fm_list_remove_all(dataPtr(), data);
134
void remove(gpointer data) {
135
fm_list_remove(dataPtr(), data);
140
fm_list_clear(dataPtr());
146
FmList* dataPtr_; // data pointer for the underlying C struct
153
#endif // __LIBFM_QT_FM_LIST_H__