Update Changelog
[profile/ivi/libgee.git] / gee / readonlybidirlist.vala
1 /* readonlybidirlist.vala
2  *
3  * Copyright (C) 2011  Maciej Piechotka
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
18  *
19  * Author:
20  *      Maciej Piechotka <uzytkownik2@gmail.com>
21  */
22
23 internal class Gee.ReadOnlyBidirList<G> : Gee.ReadOnlyList<G>, BidirList<G> {
24
25         /**
26          * Constructs a read-only list that mirrors the content of the specified
27          * list.
28          *
29          * @param list the list to decorate.
30          */
31         public ReadOnlyBidirList (BidirList<G> list) {
32                 base (list);
33         }
34
35         /**
36          * {@inheritDoc}
37          */
38         public BidirListIterator<G> bidir_list_iterator () {
39                 return new Iterator<G> (((Gee.BidirList<G>) _collection).bidir_list_iterator ());
40         }
41
42         /**
43          * The read-only view of this list.
44          */
45         public virtual new BidirList<G> read_only_view { owned get { return this; } }
46
47         private class Iterator<G> : ReadOnlyList.Iterator<G>, BidirIterator<G>, BidirListIterator<G> {
48                 public Iterator (ListIterator<G> iterator) {
49                         base (iterator);
50                 }
51
52                 public bool previous () {
53                         return ((BidirIterator<G>) _iter).previous ();
54                 }
55
56                 public bool has_previous () {
57                         return ((BidirIterator<G>) _iter).has_previous ();
58                 }
59
60                 public bool first () {
61                         return ((BidirIterator<G>) _iter).first ();
62                 }
63
64                 public bool last () {
65                         return ((BidirIterator<G>) _iter).last ();
66                 }
67
68                 public void insert (G item) {
69                         assert_not_reached ();
70                 }
71         }
72 }
73