~s-cecilio/lomse/master

« back to all changes in this revision

Viewing changes to src/document/lomse_document_iterator.cpp

  • Committer: cecilios
  • Date: 2010-11-14 17:47:31 UTC
  • Revision ID: git-v1:1fa3764c8c4d338b95b1a537b1e78271170c0025
latest new code. demo_1 tested on linux and win32

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//---------------------------------------------------------------------------------------
 
2
//  This file is part of the Lomse library.
 
3
//  Copyright (c) 2010 Lomse project
 
4
//
 
5
//  Lomse is free software; you can redistribute it and/or modify it under the
 
6
//  terms of the GNU General Public License as published by the Free Software Foundation,
 
7
//  either version 3 of the License, or (at your option) any later version.
 
8
//
 
9
//  Lomse is distributed in the hope that it will be useful, but WITHOUT ANY
 
10
//  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 
11
//  PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 
12
//
 
13
//  You should have received a copy of the GNU General Public License along
 
14
//  with Lomse; if not, see <http://www.gnu.org/licenses/>.
 
15
//  
 
16
//  For any comment, suggestion or feature request, please contact the manager of
 
17
//  the project at cecilios@users.sourceforge.net
 
18
//
 
19
//---------------------------------------------------------------------------------------
 
20
 
 
21
#include "lomse_document_iterator.h"
 
22
 
 
23
#include "lomse_document.h"
 
24
#include "lomse_internal_model.h"
 
25
 
 
26
using namespace std;
 
27
 
 
28
namespace lomse
 
29
{
 
30
 
 
31
//---------------------------------------------------------------------------------------
 
32
// ElementIterator implementation
 
33
//---------------------------------------------------------------------------------------
 
34
ElementIterator::ElementIterator(ImoObj* pObj)
 
35
    : m_pObj(pObj)
 
36
{
 
37
    m_pCurItem = NULL;    //m_pTree->begin();
 
38
}
 
39
 
 
40
//---------------------------------------------------------------------------------------
 
41
ElementIterator::~ElementIterator()
 
42
{
 
43
}
 
44
 
 
45
////---------------------------------------------------------------------------------------
 
46
//void ElementIterator::to_begin()
 
47
//{
 
48
//    clear_stack();
 
49
//    m_pCurItem = m_pTree->begin();
 
50
//}
 
51
//
 
52
////---------------------------------------------------------------------------------------
 
53
//void ElementIterator::clear_stack()
 
54
//{
 
55
//    while (!m_stack.empty())
 
56
//        m_stack.pop();
 
57
//}
 
58
//
 
59
////---------------------------------------------------------------------------------------
 
60
//bool ElementIterator::is_pointing_to(long objType)
 
61
//{
 
62
//    return *m_pCurItem != NULL && (*m_pCurItem)->get_type() == objType;
 
63
//}
 
64
//
 
65
////---------------------------------------------------------------------------------------
 
66
//void ElementIterator::point_to(int objType)
 
67
//{
 
68
//    while (*m_pCurItem != NULL && !is_pointing_to(objType))
 
69
//        next();
 
70
//}
 
71
//
 
72
//---------------------------------------------------------------------------------------
 
73
void ElementIterator::point_to(ImoObj* pObj)
 
74
{
 
75
    m_pCurItem = pObj;
 
76
}
 
77
 
 
78
////---------------------------------------------------------------------------------------
 
79
//void ElementIterator::enter_element()
 
80
//{
 
81
//    if (*m_pCurItem != NULL)
 
82
//    {
 
83
//        m_stack.push(m_pCurItem);
 
84
//        ++m_pCurItem;
 
85
//    }
 
86
//}
 
87
//
 
88
////---------------------------------------------------------------------------------------
 
89
//void ElementIterator::exit_element()
 
90
//{
 
91
//    if (!m_stack.empty())
 
92
//    {
 
93
//        m_pCurItem = m_stack.top();
 
94
//        m_stack.pop();
 
95
//    }
 
96
//    else
 
97
//        m_pCurItem = NULL;
 
98
//}
 
99
//
 
100
////---------------------------------------------------------------------------------------
 
101
//void ElementIterator::exit_all_to(ImoObj* pImo)
 
102
//
 
103
//{
 
104
//     //exit elements until the received one
 
105
//
 
106
//    while (*m_pCurItem != pImo && !m_stack.empty())
 
107
//    {
 
108
//        m_pCurItem = m_stack.top();
 
109
//        if (*m_pCurItem == pImo)
 
110
//            break;
 
111
//        m_stack.pop();
 
112
//    }
 
113
//}
 
114
//
 
115
////---------------------------------------------------------------------------------------
 
116
////void ElementIterator::start_of(long objType, int num)
 
117
////{
 
118
////    //within the limits of current element finds the element #num [0..n-1]
 
119
////    //of type 'objType' and points to its first sub-element
 
120
////
 
121
////    to_begin();
 
122
////    enter_element();
 
123
////    point_to(k_content);
 
124
////    enter_element();
 
125
////}
 
126
 
 
127
 
 
128
 
 
129
//---------------------------------------------------------------------------------------
 
130
// DocIterator implementation
 
131
//---------------------------------------------------------------------------------------
 
132
DocIterator::DocIterator(Document* pDoc)
 
133
    : ElementIterator(pDoc->get_imodoc())
 
134
    , m_pDoc(pDoc->get_imodoc())
 
135
    //, m_pScoreElmIterator(NULL)
 
136
{
 
137
    m_numContentItems = m_pDoc->get_num_content_items();
 
138
    m_curItemIndex = -1;
 
139
    next();
 
140
}
 
141
 
 
142
//---------------------------------------------------------------------------------------
 
143
DocIterator::~DocIterator()
 
144
{
 
145
//    if (m_pScoreElmIterator)
 
146
//        delete m_pScoreElmIterator;
 
147
}
 
148
 
 
149
//---------------------------------------------------------------------------------------
 
150
void DocIterator::next()
 
151
{
 
152
    ++m_curItemIndex;
 
153
    point_to_current();
 
154
}
 
155
 
 
156
//---------------------------------------------------------------------------------------
 
157
void DocIterator::prev()
 
158
{
 
159
    --m_curItemIndex;
 
160
    point_to_current();
 
161
}
 
162
 
 
163
//---------------------------------------------------------------------------------------
 
164
void DocIterator::point_to_current()
 
165
{
 
166
    if (m_curItemIndex >=0 && m_curItemIndex < m_numContentItems)
 
167
        m_pCurItem = m_pDoc->get_content_item(m_curItemIndex);
 
168
    else
 
169
        m_pCurItem = NULL;
 
170
}
 
171
 
 
172
////---------------------------------------------------------------------------------------
 
173
//void DocIterator::enter_element()
 
174
//{
 
175
//    //Factory method 
 
176
//    //if new elements added, create specific cursor to delegate to it.
 
177
//
 
178
//    if (m_pCurItem->is_score())
 
179
//    {
 
180
//        if (m_pScoreElmIterator)
 
181
//            delete m_pScoreElmIterator;
 
182
//        m_pScoreElmIterator = new ScoreElmIterator(this, dynamic_cast<ImScore*>(m_pCurItem) );
 
183
//    }
 
184
//}
 
185
 
 
186
//---------------------------------------------------------------------------------------
 
187
void DocIterator::start_of_content()
 
188
{
 
189
    //to first item in 'content' element
 
190
 
 
191
//    to_begin();
 
192
//    enter_element();
 
193
//    point_to(k_content);
 
194
//    enter_element();
 
195
    m_curItemIndex = -1;
 
196
    next();
 
197
}
 
198
 
 
199
//---------------------------------------------------------------------------------------
 
200
void DocIterator::last_of_content()
 
201
{
 
202
//    to_begin();
 
203
//    enter_element();
 
204
//    point_to(k_content);
 
205
//    m_pCurItem = (*m_pCurItem)->get_last_child();
 
206
    m_curItemIndex = m_numContentItems - 2;
 
207
    next();
 
208
}
 
209
 
 
210
 
 
211
 
 
212
////---------------------------------------------------------------------------------------
 
213
//// ScoreElmIterator implementation
 
214
////---------------------------------------------------------------------------------------
 
215
//ScoreElmIterator::ScoreElmIterator(ElementIterator* pParent, ImScore* pScore)
 
216
//    : m_pParent(pParent)
 
217
//    , m_pScore(pScore)
 
218
//{
 
219
//}
 
220
//
 
221
////---------------------------------------------------------------------------------------
 
222
//ScoreElmIterator::~ScoreElmIterator()
 
223
//{
 
224
//}
 
225
 
 
226
////---------------------------------------------------------------------------------------
 
227
//void ScoreElmIterator::start()
 
228
//{
 
229
//    m_pParent->exit_all_to(m_pScore);
 
230
//    m_pParent->enter_element();
 
231
//}
 
232
//
 
233
////---------------------------------------------------------------------------------------
 
234
//void ScoreElmIterator::start_of_instrument(int instr)
 
235
//{
 
236
//    //to first staff obj of instr (0..n-1)
 
237
//
 
238
//    find_instrument(instr);
 
239
//    m_pParent->enter_element();
 
240
//    m_pParent->point_to(k_musicData);
 
241
//    m_pParent->enter_element();
 
242
//}
 
243
//
 
244
////---------------------------------------------------------------------------------------
 
245
//void ScoreElmIterator::find_instrument(int instr)
 
246
//{
 
247
//    //instr = 0..n
 
248
//
 
249
//    start();
 
250
//    m_pParent->point_to(k_instrument);
 
251
//    for (int i=0; i != instr && !m_pParent->is_out_of_range(); i++)
 
252
//    {
 
253
//        ++(*m_pParent);
 
254
//        m_pParent->point_to(k_instrument);
 
255
//    }
 
256
//}
 
257
 
 
258
 
 
259
}  //namespace lomse