1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
2002-05-30 03:37:24 +00:00
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file TexRow.h
|
2003-08-23 00:17:00 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2002-05-30 03:37:24 +00:00
|
|
|
* \author Matthias Ettrich
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author John Levon
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-05-30 03:37:24 +00:00
|
|
|
*/
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
#ifndef TEXROW_H
|
|
|
|
#define TEXROW_H
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2015-09-15 04:56:01 +00:00
|
|
|
#include "support/debug.h"
|
2000-03-28 02:18:55 +00:00
|
|
|
|
2015-09-15 04:56:01 +00:00
|
|
|
#include <vector>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2015-09-15 04:56:01 +00:00
|
|
|
class LyXErr;
|
|
|
|
class DocIterator;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2007-08-12 14:54:54 +00:00
|
|
|
/// Represents the correspondence between paragraphs and the generated
|
2008-10-31 14:13:44 +00:00
|
|
|
/// LaTeX file
|
2007-08-12 14:54:54 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
class TexRow {
|
|
|
|
public:
|
|
|
|
///
|
2015-09-15 04:56:01 +00:00
|
|
|
TexRow(bool enable = true)
|
|
|
|
: lastid(-1), lastpos(-1), started(false), enabled_(enable) {}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/// Clears structure
|
2015-09-15 04:56:01 +00:00
|
|
|
/// TexRow is often computed to be immediately discarded. Set enable to
|
|
|
|
/// false if texrow is not needed
|
|
|
|
void reset(bool enable = true);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/// Define what paragraph and position the next row will represent
|
2003-05-07 21:27:29 +00:00
|
|
|
void start(int id, int pos);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/// Insert node when line is completed
|
|
|
|
void newline();
|
|
|
|
|
2010-02-08 17:39:55 +00:00
|
|
|
/// Insert multiple nodes when zero or more lines are completed
|
|
|
|
void newlines(int num_lines);
|
|
|
|
|
2015-09-15 04:56:01 +00:00
|
|
|
/// Call when code generation is complete
|
|
|
|
void finalize();
|
|
|
|
|
2002-05-30 03:37:24 +00:00
|
|
|
/**
|
|
|
|
* getIdFromRow - find pid and position for a given row
|
|
|
|
* @param row row number to find
|
|
|
|
* @param id set to id if found
|
|
|
|
* @param pos set to paragraph position if found
|
|
|
|
* @return true if found, false otherwise
|
|
|
|
*
|
|
|
|
* If the row could not be found, pos is set to zero and
|
|
|
|
* id is set to -1
|
|
|
|
*/
|
2000-08-05 05:17:18 +00:00
|
|
|
bool getIdFromRow(int row, int & id, int & pos) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2015-09-15 04:56:01 +00:00
|
|
|
/// Finds the best pair of rows for dit
|
|
|
|
/// returns (-1,-1) if not found.
|
|
|
|
std::pair<int,int> rowFromDocIterator(DocIterator const & dit) const;
|
2007-08-13 14:04:35 +00:00
|
|
|
|
2002-05-30 03:37:24 +00:00
|
|
|
/// Returns the number of rows contained
|
2007-08-13 14:04:35 +00:00
|
|
|
int rows() const { return rowlist.size(); }
|
2000-05-04 08:14:34 +00:00
|
|
|
|
2002-05-30 03:37:24 +00:00
|
|
|
/// an individual id/pos <=> row mapping
|
2000-06-08 23:16:16 +00:00
|
|
|
class RowItem {
|
|
|
|
public:
|
2007-08-13 14:04:35 +00:00
|
|
|
RowItem(int id, int pos)
|
|
|
|
: id_(id), pos_(pos)
|
2002-05-30 03:37:24 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
/// paragraph id
|
2007-08-12 14:54:54 +00:00
|
|
|
int id() const { return id_; }
|
2002-05-30 03:37:24 +00:00
|
|
|
/// set paragraph position
|
2007-08-12 14:54:54 +00:00
|
|
|
void pos(int p) { pos_ = p; }
|
2002-05-30 03:37:24 +00:00
|
|
|
/// paragraph position
|
2007-08-12 14:54:54 +00:00
|
|
|
int pos() const { return pos_; }
|
2000-06-08 23:16:16 +00:00
|
|
|
private:
|
2006-12-30 21:05:44 +00:00
|
|
|
RowItem();
|
2000-06-08 23:16:16 +00:00
|
|
|
int id_;
|
|
|
|
int pos_;
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
///
|
2007-08-13 14:04:35 +00:00
|
|
|
typedef std::vector<RowItem> RowList;
|
2000-08-05 05:17:18 +00:00
|
|
|
private:
|
2002-05-30 03:37:24 +00:00
|
|
|
/// container of id/pos <=> row mapping
|
|
|
|
RowList rowlist;
|
1999-09-27 18:44:28 +00:00
|
|
|
/// Last paragraph
|
2003-05-07 21:27:29 +00:00
|
|
|
int lastid;
|
1999-09-27 18:44:28 +00:00
|
|
|
/// Last position
|
|
|
|
int lastpos;
|
2011-03-10 04:05:49 +00:00
|
|
|
/// Is id/pos already registered for current row?
|
|
|
|
bool started;
|
2015-09-15 04:56:01 +00:00
|
|
|
///
|
|
|
|
bool enabled_;
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2015-09-15 04:56:01 +00:00
|
|
|
LyXErr & operator<<(LyXErr &, TexRow &);
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
2002-05-30 03:37:24 +00:00
|
|
|
#endif // TEXROW_H
|