X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FTexRow.h;h=e40867d7b1416f113ca41d448655729bc1ced685;hb=3209e6604ef132c8488ad14719b29406899d8b00;hp=7697761987d48387df871913eefa3eee3e31a979;hpb=2e45bade7abea57625319068f559a6b57150ffb5;p=lyx.git diff --git a/src/TexRow.h b/src/TexRow.h index 7697761987..e40867d7b1 100644 --- a/src/TexRow.h +++ b/src/TexRow.h @@ -28,7 +28,7 @@ #ifndef TEXROW_H #define TEXROW_H -#include "support/debug.h" +#include "support/docstring.h" #include "support/types.h" #include @@ -42,31 +42,56 @@ class DocIterator; class docstring_list; class FuncRequest; -/// types for cells and math insets -typedef void const * uid_type; -typedef size_t idx_type; +/// Represents the correspondence between paragraphs and the generated +/// LaTeX file + +class TexRow { +public: + /// We begin with defining the types of row information we are tracking + /// + + /// type of row entries + enum RowType { + text_entry, + math_entry, + begin_document + }; -/// an individual par id/pos <=> row mapping -struct TextEntry { int id; pos_type pos; }; + /// an individual par id/pos <=> row mapping + struct TextEntry { int id; pos_type pos; }; -/// an individual math id/cell <=> row mapping -struct MathEntry { uid_type id; idx_type cell; }; + /// an individual math id/cell <=> row mapping + struct MathEntry { uid_type id; idx_type cell; }; -/// a container for passing entries around -struct RowEntry { - bool is_math;// true iff the union is a math - union { - struct TextEntry text; - struct MathEntry math; + /// a container for passing entries around + struct RowEntry { + RowType type; + union { + struct TextEntry text;// iff the type is text_entry + struct MathEntry math;// iff the type is row_entry + struct {} begindocument;// iff the type is begin_document + }; }; -}; + /// Encapsulates the paragraph and position for later use + static RowEntry textEntry(int id, pos_type pos); + /// Encapsulates a cell and position for later use + static RowEntry mathEntry(uid_type id, idx_type cell); + /// Denotes the beginning of the document + static RowEntry beginDocument(); -/// Represents the correspondence between paragraphs and the generated -/// LaTeX file + /// Converts a CursorSlice into a RowEntry + static RowEntry rowEntryFromCursorSlice(CursorSlice const & slice); -class TexRow { + static const TextEntry text_none; + static const RowEntry row_none; + /// Returns true if RowEntry is devoid of information + static bool isNone(RowEntry entry); + /// Returns true if TextEntry is devoid of information + static bool isNone(TextEntry entry); + +private: /// id/pos correspondence for a single row class RowEntryList; @@ -89,7 +114,6 @@ public: /// TexRow(); -#if !(defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 6)) /// Copy can be expensive and is not usually useful for TexRow. /// Force explicit copy, prefer move instead. This also prevents /// move()s from being converted into copy silently. @@ -97,28 +121,10 @@ public: TexRow(TexRow && other) = default; TexRow & operator=(TexRow const & other) = default; TexRow & operator=(TexRow && other) = default; -# else - //for gcc 4.6, nothing to do: it's enough to disable implicit copy during - // dev with more recent versions of gcc. -#endif /// Clears structure. void reset(); - static const TextEntry text_none; - static const RowEntry row_none; - /// Returns true if RowEntry is devoid of information - static bool isNone(RowEntry entry); - /// Returns true if TextEntry is devoid of information - static bool isNone(TextEntry entry); - - /// Converts a CursorSlice into a RowEntry - static RowEntry rowEntryFromCursorSlice(CursorSlice const & slice); - /// Encapsulates the paragraph and position for later use - static RowEntry textEntry(int id, pos_type pos); - /// Encapsulates a cell and position for later use - static RowEntry mathEntry(uid_type id, idx_type cell); - /// for debugging purposes static docstring asString(RowEntry entry); @@ -145,6 +151,7 @@ public: /** * getEntriesFromRow - find pids and position for a given row + * This is the main algorithm behind reverse-search. * @param row number to find * @return a pair of TextEntry denoting the start and end of the position. * The TextEntry values can be isNone(). If no row is found then the first @@ -183,6 +190,7 @@ public: /// Finds the best pair of rows for dit /// returns (-1,-1) if not found. + /// This is the main algorithm behind forward-search. std::pair rowFromDocIterator(DocIterator const & dit) const; /// Finds the best pair of rows for cursor, taking the selection into @@ -203,7 +211,7 @@ public: void prepend(docstring_list &) const; private: - /// true iff same paragraph or math inset + /// true iff same paragraph or math inset or begin_document static bool sameParOrInsetMath(RowEntry entry1, RowEntry entry2); /// computes the distance in pos or cell index /// assumes it is the sameParOrInsetMath @@ -223,7 +231,6 @@ struct TexString { docstring str; /// TexRow texrow; -#if !(defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 6)) /// Copy can be expensive and is not usually useful for TexString. /// Force explicit copy, prefer move instead. This also prevents /// move()s from being converted into copy silently. @@ -231,10 +238,6 @@ struct TexString { TexString(TexString && other) = default; TexString & operator=(TexString const & other) = default; TexString & operator=(TexString && other) = default; -# else - //for gcc 4.6, nothing to do: it's enough to disable implicit copy during - // dev with more recent versions of gcc. -#endif /// Empty TexString TexString() = default; /// Texstring containing str and TexRow with enough lines which are empty @@ -286,7 +289,7 @@ public: }; -bool operator==(RowEntry entry1, RowEntry entry2); +bool operator==(TexRow::RowEntry entry1, TexRow::RowEntry entry2); } // namespace lyx