]> git.lyx.org Git - lyx.git/blobdiff - src/TexRow.h
Account for old versions of Pygments
[lyx.git] / src / TexRow.h
index 80b39b765e12bb9d93859f7dbac1c07854df9b05..e85b141aeff70bc546b902190dc340da12e4a360 100644 (file)
@@ -29,6 +29,7 @@
 #define TEXROW_H
 
 #include "support/debug.h"
+#include "support/docstring.h"
 #include "support/types.h"
 
 #include <vector>
@@ -47,26 +48,55 @@ typedef void const * uid_type;
 typedef size_t idx_type;
 
 
-/// an individual par id/pos <=> row mapping
-struct TextEntry { int id; pos_type pos; };
+/// Represents the correspondence between paragraphs and the generated
+/// LaTeX file
 
-/// an individual math id/cell <=> row mapping
-struct MathEntry { uid_type id; idx_type cell; };
+class TexRow {
+public:
+       /// We begin with defining the types of row information we are tracking
+       ///
 
-/// 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;
+       /// 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; };
 
-/// Represents the correspondence between paragraphs and the generated
-/// LaTeX file
+       /// an individual math id/cell <=> row mapping
+       struct MathEntry { uid_type id; idx_type cell; };
 
-class TexRow {
+       /// 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();
+
+       /// Converts a CursorSlice into a RowEntry
+       static RowEntry rowEntryFromCursorSlice(CursorSlice const & slice);
+
+       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;
 
@@ -105,20 +135,6 @@ public:
        /// 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 +161,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
@@ -168,7 +185,8 @@ public:
 
        // A FuncRequest to select from start to end
        static FuncRequest goToFunc(TextEntry start, TextEntry end);
-       static FuncRequest goToFunc(std::pair<TextEntry,TextEntry> entries);
+       // A FuncRequest to select a row
+       FuncRequest goToFuncFromRow(int const row) const;
 
        /**
         * getDocIteratorFromRow - find pids and positions for a given row
@@ -182,6 +200,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<int,int> rowFromDocIterator(DocIterator const & dit) const;
 
        /// Finds the best pair of rows for cursor, taking the selection into
@@ -202,7 +221,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
@@ -285,7 +304,7 @@ public:
 };
 
 
-bool operator==(RowEntry entry1, RowEntry entry2);
+bool operator==(TexRow::RowEntry entry1, TexRow::RowEntry entry2);
 
 
 } // namespace lyx