X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsupport%2FRandomAccessList.h;h=2565d62513158ecc57e0f306ef471c9b477ab264;hb=037b1e14789223c89e88e8bd74baffa4d0956571;hp=2e419bd7001491cdf87cf52fdd3069dc1a6d3200;hpb=9d6cad3fe60696d795280a886623fdc9a89f9de6;p=lyx.git diff --git a/src/support/RandomAccessList.h b/src/support/RandomAccessList.h index 2e419bd700..2565d62513 100644 --- a/src/support/RandomAccessList.h +++ b/src/support/RandomAccessList.h @@ -13,13 +13,11 @@ #ifndef RANDOM_ACESS_LIST_H #define RANDOM_ACESS_LIST_H -//#include "debug.h" - -#include - #include #include -#include + + +namespace lyx { #define USE_OLD_ITERATOR 1 @@ -31,7 +29,7 @@ keeps the std::list::iterator interface. A typical use would be: typedef RandomAccessList MyContainer; -Then you can use MyContainer as if it was a standard +Then you can use MyContainer as if it was a standard std::vector for operator[] access and as if it was a standard std::list for iterator access. The main difference with std::vector is that insertion of elements is much less costly. Compared @@ -248,6 +246,21 @@ public: return it; } + void swap(size_t i, size_t j) + { + size_t const p = std::max(i, j); + size_t const q = std::min(i, j); + container_.splice(iterCont_[p], container_, iterCont_[q]); + container_.splice(iterCont_[q], container_, iterCont_[p]); + recreateVector(); + } + + void splice(iterator where, iterator first, iterator last) + { + container_.splice(where, container_, first, last); + recreateVector(); + } + void swap(RandomAccessList & x) { std::swap(container_, x.container_); @@ -260,6 +273,32 @@ public: iterCont_.clear(); } + size_t position(iterator it) const + { + size_t const s = iterCont_.size(); + for (size_t i = 0; it != s; ++i) { + if (iterCont_[i] == it) + return i; + } + return s; + } + + size_t position(const_iterator it) const + { + size_t const s = iterCont_.size(); + for (size_t i = 0; i != s; ++i) { + if (iterCont_[i] == it) + return i; + } + return s; + } + + + const_iterator constIterator(size_t i) const + { + return iterCont_[i]; + } + private: void recreateVector() { @@ -276,4 +315,7 @@ private: IterCont iterCont_; }; + +} // namespace lyx + #endif