1
//---------------------------------------------------------------------------------------
2
// This file is part of the Lomse library.
3
// Copyright (c) 2010 Lomse project
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.
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.
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/>.
16
// For any comment, suggestion or feature request, please contact the manager of
17
// the project at cecilios@users.sourceforge.net
19
//---------------------------------------------------------------------------------------
21
#include "lomse_document_iterator.h"
23
#include "lomse_document.h"
24
#include "lomse_internal_model.h"
31
//---------------------------------------------------------------------------------------
32
// ElementIterator implementation
33
//---------------------------------------------------------------------------------------
34
ElementIterator::ElementIterator(ImoObj* pObj)
37
m_pCurItem = NULL; //m_pTree->begin();
40
//---------------------------------------------------------------------------------------
41
ElementIterator::~ElementIterator()
45
////---------------------------------------------------------------------------------------
46
//void ElementIterator::to_begin()
49
// m_pCurItem = m_pTree->begin();
52
////---------------------------------------------------------------------------------------
53
//void ElementIterator::clear_stack()
55
// while (!m_stack.empty())
59
////---------------------------------------------------------------------------------------
60
//bool ElementIterator::is_pointing_to(long objType)
62
// return *m_pCurItem != NULL && (*m_pCurItem)->get_type() == objType;
65
////---------------------------------------------------------------------------------------
66
//void ElementIterator::point_to(int objType)
68
// while (*m_pCurItem != NULL && !is_pointing_to(objType))
72
//---------------------------------------------------------------------------------------
73
void ElementIterator::point_to(ImoObj* pObj)
78
////---------------------------------------------------------------------------------------
79
//void ElementIterator::enter_element()
81
// if (*m_pCurItem != NULL)
83
// m_stack.push(m_pCurItem);
88
////---------------------------------------------------------------------------------------
89
//void ElementIterator::exit_element()
91
// if (!m_stack.empty())
93
// m_pCurItem = m_stack.top();
100
////---------------------------------------------------------------------------------------
101
//void ElementIterator::exit_all_to(ImoObj* pImo)
104
// //exit elements until the received one
106
// while (*m_pCurItem != pImo && !m_stack.empty())
108
// m_pCurItem = m_stack.top();
109
// if (*m_pCurItem == pImo)
115
////---------------------------------------------------------------------------------------
116
////void ElementIterator::start_of(long objType, int num)
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
122
//// enter_element();
123
//// point_to(k_content);
124
//// enter_element();
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)
137
m_numContentItems = m_pDoc->get_num_content_items();
142
//---------------------------------------------------------------------------------------
143
DocIterator::~DocIterator()
145
// if (m_pScoreElmIterator)
146
// delete m_pScoreElmIterator;
149
//---------------------------------------------------------------------------------------
150
void DocIterator::next()
156
//---------------------------------------------------------------------------------------
157
void DocIterator::prev()
163
//---------------------------------------------------------------------------------------
164
void DocIterator::point_to_current()
166
if (m_curItemIndex >=0 && m_curItemIndex < m_numContentItems)
167
m_pCurItem = m_pDoc->get_content_item(m_curItemIndex);
172
////---------------------------------------------------------------------------------------
173
//void DocIterator::enter_element()
176
// //if new elements added, create specific cursor to delegate to it.
178
// if (m_pCurItem->is_score())
180
// if (m_pScoreElmIterator)
181
// delete m_pScoreElmIterator;
182
// m_pScoreElmIterator = new ScoreElmIterator(this, dynamic_cast<ImScore*>(m_pCurItem) );
186
//---------------------------------------------------------------------------------------
187
void DocIterator::start_of_content()
189
//to first item in 'content' element
193
// point_to(k_content);
199
//---------------------------------------------------------------------------------------
200
void DocIterator::last_of_content()
204
// point_to(k_content);
205
// m_pCurItem = (*m_pCurItem)->get_last_child();
206
m_curItemIndex = m_numContentItems - 2;
212
////---------------------------------------------------------------------------------------
213
//// ScoreElmIterator implementation
214
////---------------------------------------------------------------------------------------
215
//ScoreElmIterator::ScoreElmIterator(ElementIterator* pParent, ImScore* pScore)
216
// : m_pParent(pParent)
217
// , m_pScore(pScore)
221
////---------------------------------------------------------------------------------------
222
//ScoreElmIterator::~ScoreElmIterator()
226
////---------------------------------------------------------------------------------------
227
//void ScoreElmIterator::start()
229
// m_pParent->exit_all_to(m_pScore);
230
// m_pParent->enter_element();
233
////---------------------------------------------------------------------------------------
234
//void ScoreElmIterator::start_of_instrument(int instr)
236
// //to first staff obj of instr (0..n-1)
238
// find_instrument(instr);
239
// m_pParent->enter_element();
240
// m_pParent->point_to(k_musicData);
241
// m_pParent->enter_element();
244
////---------------------------------------------------------------------------------------
245
//void ScoreElmIterator::find_instrument(int instr)
250
// m_pParent->point_to(k_instrument);
251
// for (int i=0; i != instr && !m_pParent->is_out_of_range(); i++)
254
// m_pParent->point_to(k_instrument);