MuseScore  3.4
Music composition and notation
segmentlist.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2011 Werner Schweer
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __SEGMENTLIST_H__
14 #define __SEGMENTLIST_H__
15 
16 #include "segment.h"
17 
18 namespace Ms {
19 
20 class Segment;
21 
22 //---------------------------------------------------------
23 // SegmentList
24 //---------------------------------------------------------
25 
26 class SegmentList {
29  int _size;
30 
31  public:
32  SegmentList() { clear(); }
33  void clear() { _first = _last = 0; _size = 0; }
34 #ifndef NDEBUG
35  void check();
36 #else
37  void check() {}
38 #endif
39  SegmentList clone() const;
40  int size() const { return _size; }
41 
42  Segment* first() const { return _first; }
43  Segment* first(SegmentType) const;
44  Segment* first(ElementFlag) const;
45 
46  Segment* last() const { return _last; }
47  Segment* firstCRSegment() const;
48  void remove(Segment*);
49  void push_back(Segment*);
50  void push_front(Segment*);
51  void insert(Segment* e, Segment* el); // insert e before el
52 
53  class iterator {
55  public:
56  iterator(Segment* s) { p = s; }
57  iterator operator++() { iterator i(p); p = p->next(); return i; }
58  bool operator !=(const iterator& i) const { return p != i.p; }
59  Segment& operator*() { return *p; }
60  };
62  const Segment* p;
63  public:
64  const_iterator(const Segment* s) { p = s; }
65  const_iterator operator++() { const_iterator i(p); p = p->next(); return i; }
66  bool operator !=(const const_iterator& i) const { return p != i.p; }
67  const Segment& operator*() const { return *p; }
68  };
69 
70  iterator begin() { return _first; }
71  iterator end() { return 0; }
72  const_iterator begin() const { return _first; }
73  const_iterator end() const { return 0; }
74  };
75 
76 // Segment* begin(SegmentList& l) { return l.first(); }
77 // Segment* end(SegmentList&) { return 0; }
78 
79 
80 } // namespace Ms
81 #endif
82 
Definition: segmentlist.h:26
Segment & operator*()
Definition: segmentlist.h:59
void push_front(Segment *)
Definition: segmentlist.cpp:178
Definition: segmentlist.h:53
void clear()
Definition: segmentlist.h:33
bool operator!=(const iterator &i) const
Definition: segmentlist.h:58
const_iterator(const Segment *s)
Definition: segmentlist.h:64
int _size
Number of items in segment list.
Definition: segmentlist.h:29
Segment * first() const
Definition: segmentlist.h:42
Segment * next() const
Definition: segment.h:85
const Segment * p
Definition: segmentlist.h:62
Segment * last() const
Definition: segmentlist.h:46
Segment * firstCRSegment() const
Definition: segmentlist.cpp:195
SegmentList clone() const
Definition: segmentlist.cpp:23
SegmentType
Definition: types.h:333
void push_back(Segment *)
Definition: segmentlist.cpp:161
ElementFlag
Definition: element.h:66
Definition: segment.h:50
SegmentList()
Definition: segmentlist.h:32
Segment * _last
Last item of segment list.
Definition: segmentlist.h:28
Definition: aeolus.cpp:26
Segment * _first
First item of segment list.
Definition: segmentlist.h:27
const_iterator operator++()
Definition: segmentlist.h:65
void insert(Segment *e, Segment *el)
Insert Segment e before Segment el.
Definition: segmentlist.cpp:103
Segment * p
Definition: segmentlist.h:54
iterator begin()
Definition: segmentlist.h:70
iterator operator++()
Definition: segmentlist.h:57
void check()
Definition: segmentlist.cpp:41
iterator end()
Definition: segmentlist.h:71
const Segment & operator*() const
Definition: segmentlist.h:67
int size() const
Definition: segmentlist.h:40
Definition: segmentlist.h:61
iterator(Segment *s)
Definition: segmentlist.h:56
const_iterator end() const
Definition: segmentlist.h:73
const_iterator begin() const
Definition: segmentlist.h:72