]> git.sesse.net Git - vlc/blob - modules/gui/skins2/utils/var_list.hpp
skins2: prefer ++it over it++ for iterators
[vlc] / modules / gui / skins2 / utils / var_list.hpp
1 /*****************************************************************************
2  * var_list.hpp
3  *****************************************************************************
4  * Copyright (C) 2003 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teulière <ipkiss@via.ecp.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along
21  * with this program; if not, write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifndef VAR_LIST_HPP
26 #define VAR_LIST_HPP
27
28 #include <list>
29
30 #include "variable.hpp"
31 #include "observer.hpp"
32 #include "ustring.hpp"
33 #include "var_percent.hpp"
34
35
36 /// List variable
37 class VarList: public Variable, public Subject<VarList>
38 {
39 public:
40     VarList( intf_thread_t *pIntf );
41     virtual ~VarList();
42
43     /// Get the variable type
44     virtual const string &getType() const { return m_type; }
45
46     /// Add a pointer on a string in the list
47     virtual void add( const UStringPtr &rcString );
48
49     /// Remove the selected elements from the list
50     virtual void delSelected();
51
52     /// Remove all the elements from the list
53     virtual void clear();
54
55     /// Get the number of items in the list
56     int size() const { return m_list.size(); }
57
58     /// Type of an element in the list
59     struct Elem_t
60     {
61         UStringPtr m_cString;
62         bool m_selected;
63         bool m_playing;
64
65         Elem_t( const UStringPtr &rcString,
66                 bool selected = false, bool playing = false )
67               : m_cString( rcString ),
68                 m_selected( selected ), m_playing( playing ) { }
69     };
70
71     /// Iterators
72     typedef list<Elem_t>::iterator Iterator;
73     typedef list<Elem_t>::const_iterator ConstIterator;
74
75     /// Beginning of the list
76     Iterator begin() { return m_list.begin(); }
77     ConstIterator begin() const { return m_list.begin(); }
78
79     /// End of the list
80     Iterator end() { return m_list.end(); }
81     ConstIterator end() const { return m_list.end(); }
82
83     /// Return an iterator on the n'th element of the list
84     Iterator operator[]( int n );
85     ConstIterator operator[]( int n ) const;
86
87     /// Execute the action associated to this item
88     virtual void action( Elem_t *pItem ) { }
89
90     /// Get a reference on the position variable
91     VarPercent &getPositionVar() const
92         { return *((VarPercent*)m_cPosition.get()); }
93
94     /// Get a counted pointer on the position variable
95     const VariablePtr &getPositionVarPtr() const { return m_cPosition; }
96
97 protected:
98     /// List of elements
99     list<Elem_t> m_list;
100
101 private:
102     /// Variable type
103     static const string m_type;
104     /// Position variable
105     VariablePtr m_cPosition;
106 };
107
108
109 #endif