File: WidgetSet.h

package info (click to toggle)
lsp-plugins 1.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 91,856 kB
  • sloc: cpp: 427,831; xml: 57,779; makefile: 9,961; php: 1,005; sh: 18
file content (127 lines) | stat: -rw-r--r-- 5,684 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
 *           (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com>
 *
 * This file is part of lsp-tk-lib
 * Created on: 1 авг. 2020 г.
 *
 * lsp-tk-lib is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * lsp-tk-lib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with lsp-tk-lib. If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef LSP_PLUG_IN_TK_PROP_COLLECTION_WIDGETSET_H_
#define LSP_PLUG_IN_TK_PROP_COLLECTION_WIDGETSET_H_

#ifndef LSP_PLUG_IN_TK_IMPL
    #error "use <lsp-plug.in/tk/tk.h>"
#endif

#include <lsp-plug.in/lltl/phashset.h>

namespace lsp
{
    namespace tk
    {
        class GenericWidgetSet: public Property
        {
            private:
                GenericWidgetSet & operator = (const GenericWidgetSet &);
                GenericWidgetSet(const GenericWidgetSet &);

            protected:
                const w_class_t                *pMeta;
                prop::CollectionListener       *pCListener;
                mutable lltl::phashset<Widget>  sSet;

            public:
                explicit GenericWidgetSet(const w_class_t *meta, prop::Listener *listener = NULL, prop::CollectionListener *clistener = NULL);
                virtual ~GenericWidgetSet();

            public:
                status_t        add(Widget *w);
                status_t        remove(Widget *w);
                status_t        toggle(Widget *w);
                void            clear();

                status_t        swap(GenericWidgetSet *dst);
                inline status_t swap(GenericWidgetSet &dst)         { return swap(&dst);                            }

                inline bool     values(lltl::parray<Widget> *dst)   { return sSet.values(dst);                      }
                inline bool     values(lltl::parray<Widget> &dst)   { return sSet.values(&dst);                     }
        };

        template <class widget_t>
            class WidgetSet: public GenericWidgetSet
            {
                private:
                    WidgetSet<widget_t> & operator = (const WidgetSet<widget_t> &);
                    WidgetSet(const WidgetSet<widget_t> &);

                protected:
                    inline widget_t    *wcast(Widget *w)                    { return (w != NULL) ? static_cast<widget_t*>(w) : NULL;    }

                public:
                    explicit WidgetSet(prop::Listener *listener = NULL, prop::CollectionListener *clistener = NULL): GenericWidgetSet(&widget_t::metadata, listener, clistener) {}

                public:
                    inline size_t       size() const                        { return sSet.size();                           }
                    inline status_t     add(widget_t *w)                    { return GenericWidgetSet::add(w);              }
                    inline status_t     remove(widget_t *w)                 { return GenericWidgetSet::remove(w);           }
                    inline bool         contains(const widget_t *w) const   { return sSet.contains(w);                      }
                    inline status_t     toggle(widget_t *w)                 { return GenericWidgetSet::toggle(w);           }
                    inline widget_t    *any()                               { return wcast(sSet.any());                     }

                    inline bool         values(lltl::parray<widget_t> *dst)
                    {
                        union {
                            lltl::parray<widget_t> *wt;
                            lltl::parray<Widget>   *wg;
                        } x;
                        x.wt = dst;
                        if (!sSet.values(x.wg))
                            return false;

                        for (size_t i=0, n=dst->size(); i<n; ++i)
                            dst->set(i, wcast(dst->uget(i)));

                        return true;
                    }
                    inline bool         values(lltl::parray<Widget> &dst)   { return values(&dst);                          }

                    using GenericWidgetSet::values;

                    inline status_t     swap(WidgetSet<widget_t> *lst)      { return GenericWidgetSet::swap(lst);           }
                    inline status_t     swap(WidgetSet<widget_t> &lst)      { return GenericWidgetSet::swap(&lst);          }
            };

        namespace prop
        {
            template <class widget_t>
                class WidgetSet: public tk::WidgetSet<widget_t>
                {
                    private:
                        WidgetSet<widget_t> & operator = (const WidgetSet<widget_t> &);
                        WidgetSet(const WidgetSet<widget_t> &);

                    public:
                        explicit WidgetSet(prop::Listener *listener = NULL, prop::CollectionListener *clistener = NULL): tk::WidgetSet<widget_t>(listener, clistener) {}

                    public:
                        inline void         flush()                             { this->sSet.flush();                                               }
                };
        }
    
    } /* namespace tk */
} /* namespace lsp */

#endif /* LSP_PLUG_IN_TK_PROP_COLLECTION_WIDGETSET_H_ */