]> git.lyx.org Git - lyx.git/blobdiff - src/changes.h
Small formatting and comment cleanup.
[lyx.git] / src / changes.h
index 6e34a5ab57b441c171527e4520f4e1a043ca5e00..967a9a6c8d7bc6308827ba632a311068b3c778b4 100644 (file)
@@ -21,6 +21,9 @@
 #include <vector>
 
 
+namespace lyx {
+
+
 class Change {
 public:
        /// the type of change
@@ -30,14 +33,17 @@ public:
                DELETED // deleted text
        };
 
-       explicit Change(Type t, int a = 0, lyx::time_type ct = 0)
+       explicit Change(Type t, int a = 0, time_type ct = current_time())
                : type(t), author(a), changetime(ct) {}
 
+       /// is the change similar to the given change such that both can be merged?
+       bool isSimilarTo(Change const & change);
+
        Type type;
 
        int author;
 
-       lyx::time_type changetime;
+       time_type changetime;
 };
 
 bool operator==(Change const & l, Change const & r);
@@ -45,63 +51,59 @@ bool operator!=(Change const & l, Change const & r);
 
 class Changes {
 public:
-
-       Changes(Change::Type type);
-
-       ~Changes();
-
-       Changes(Changes const &);
-
-       /// reset "default" change type (for empty pars)
-       void reset(Change::Type type) {
-               empty_type_ = type;
-       }
-
        /// set the pos to the given change
-       void set(Change const & change, lyx::pos_type pos);
+       void set(Change const & change, pos_type pos);
+       /// set the range (excluding end) to the given change
+       void set(Change const & change, pos_type start, pos_type end);
 
-       /// set the range to the given change
-       void set(Change const & change, lyx::pos_type start, lyx::pos_type end);
+       /// erase the entry at pos and adjust all range bounds past it
+       /// (assumes that a character was deleted at pos)
+       void erase(lyx::pos_type pos);
 
-       /// mark the given change and adjust
-       void record(Change const & change, lyx::pos_type pos);
+       /// insert a new entry at pos and adjust all range bounds past it
+       /// (assumes that a character was inserted at pos)
+       void insert(Change const & change, lyx::pos_type pos);
 
-       /// return the change at the given position
-       Change const lookup(lyx::pos_type pos) const;
+       ///
 
-       /// return true if there is a change in the given range
-       bool isChange(lyx::pos_type start, lyx::pos_type end) const;
+       /// return the change at the given pos
+       Change const & lookup(pos_type pos) const;
 
-       /// remove the given entry. This implies that a character was
-       /// deleted at pos, and will adjust all range bounds past it
-       void erase(lyx::pos_type pos);
+       /// return true if there is a change in the given range (excluding end)
+       bool isChanged(pos_type start, pos_type end) const;
+
+       ///
 
-       /// output latex to mark a transition between two changetypes
+       /// output latex to mark a transition between two change types
        /// returns length of text outputted
-       static int latexMarkChange(lyx::odocstream & os, Change::Type old,
-               Change::Type change, bool const & output);
+       static int latexMarkChange(odocstream & os, Change::Type oldChangeType,
+               Change::Type changeType, bool const & output);
 
        /// output .lyx file format for transitions between changes
        static void lyxMarkChange(std::ostream & os, int & column,
-               lyx::time_type curtime, Change const & old, Change const & change);
+               Change const & old, Change const & change);
 
 private:
        class Range {
        public:
-               Range(lyx::pos_type s, lyx::pos_type e)
+               Range(pos_type s, pos_type e)
                        : start(s), end(e) {}
 
-               // does this range contain r ?
-               bool contains(Range const & r) const;
+               // does this range contain r ? (inlined as the result of profiling)
+               bool contains(Range const & r) const {
+                       return r.start >= start && r.end <= end;
+               }
 
-               // does this range contain pos ?
-               bool contains(lyx::pos_type pos) const;
+               // does this range contain pos ? (inlined as the result of profiling)
+               bool contains(pos_type pos) const {
+                       return pos >= start && pos < end;
+               }
 
                // do the ranges intersect ?
                bool intersects(Range const & r) const;
 
-               lyx::pos_type start;
-               lyx::pos_type end; // Caution: end is not in the range!
+               pos_type start;
+               pos_type end; // Caution: end is not in the range!
        };
 
        friend bool operator==(Range const & r1, Range const & r2);
@@ -109,29 +111,23 @@ private:
 
        class ChangeRange {
        public:
-               ChangeRange(lyx::pos_type s, lyx::pos_type e, Change const & c)
-                       : range(Range(s, e)), change(c) {}
-               Range range;
+               ChangeRange(Change const & c, Range const & r)
+                       : change(c), range(r) {}
+
                Change change;
+               Range range;
        };
 
+       /// merge equal changes with adjoining ranges
+       void merge();
+
        typedef std::vector<ChangeRange> ChangeTable;
 
-       /// our table of changes, every row a range and change descriptor
+       /// table of changes, every row a change and range descriptor
        ChangeTable table_;
+};
 
-       /// change type for an empty paragraph
-       Change::Type empty_type_;
-
-       /// handle a delete, either logical or physical (see erase)
-       void del(Change const & change, ChangeTable::size_type pos);
-
-       /// handle an add, adjusting range bounds past it
-       void add(Change const & change, ChangeTable::size_type pos);
 
-       /// merge neighbouring ranges, assuming that they are abutting
-       /// (as done by set())
-       void merge();
-};
+} // namespace lyx
 
 #endif // CHANGES_H