add PISet::const_iterator, now can iterate ranged-for PISet by T, not by PIPair<T, bool>
This commit is contained in:
@@ -610,7 +610,7 @@ public:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
struct MapIndex {
|
struct MapIndex {
|
||||||
MapIndex(const Key & k = Key(), size_t i = 0): key(k), index(i) {}
|
MapIndex(const Key & k = Key(), size_t i = 0): key(k), index(i) {}
|
||||||
MapIndex(Key && k, size_t i = 0): key(std::move(k)), index(i) {}
|
MapIndex(Key && k, size_t i = 0): key(std::move(k)), index(i) {}
|
||||||
@@ -627,6 +627,10 @@ private:
|
|||||||
template<typename P, typename Key1, typename T1>
|
template<typename P, typename Key1, typename T1>
|
||||||
friend PIBinaryStream<P> & operator<<(PIBinaryStream<P> & s, const PIDeque<typename PIMap<Key1, T1>::MapIndex> & v);
|
friend PIBinaryStream<P> & operator<<(PIBinaryStream<P> & s, const PIDeque<typename PIMap<Key1, T1>::MapIndex> & v);
|
||||||
|
|
||||||
|
PIVector<T> pim_content;
|
||||||
|
PIDeque<MapIndex> pim_index;
|
||||||
|
|
||||||
|
private:
|
||||||
inline ssize_t _binarySearch(ssize_t first, ssize_t last, const Key & key, bool & found) const {
|
inline ssize_t _binarySearch(ssize_t first, ssize_t last, const Key & key, bool & found) const {
|
||||||
ssize_t mid = 0;
|
ssize_t mid = 0;
|
||||||
while (first <= last) {
|
while (first <= last) {
|
||||||
@@ -678,10 +682,6 @@ private:
|
|||||||
inline T & _value(ssize_t index) { return pim_content[pim_index[index].index]; }
|
inline T & _value(ssize_t index) { return pim_content[pim_index[index].index]; }
|
||||||
|
|
||||||
inline const T & _value(ssize_t index) const { return pim_content[pim_index[index].index]; }
|
inline const T & _value(ssize_t index) const { return pim_content[pim_index[index].index]; }
|
||||||
|
|
||||||
|
|
||||||
PIVector<T> pim_content;
|
|
||||||
PIDeque<MapIndex> pim_index;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,90 @@ public:
|
|||||||
_CSet::insert(v3, 0);
|
_CSet::insert(v3, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class const_iterator {
|
||||||
|
friend class PISet<T>;
|
||||||
|
|
||||||
|
private:
|
||||||
|
inline const_iterator(const PISet<T> * v, ssize_t p): parent(v), pos(p) {}
|
||||||
|
const PISet<T> * parent;
|
||||||
|
ssize_t pos;
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef T value_type;
|
||||||
|
typedef T * pointer;
|
||||||
|
typedef T & reference;
|
||||||
|
typedef std::ptrdiff_t difference_type;
|
||||||
|
typedef std::random_access_iterator_tag iterator_category;
|
||||||
|
|
||||||
|
inline const_iterator(): parent(0), pos(0) {}
|
||||||
|
|
||||||
|
inline const T & operator*() const { return parent->pim_index[pos].key; }
|
||||||
|
inline const T & operator->() const { return parent->pim_index[pos].key; }
|
||||||
|
|
||||||
|
inline const_iterator & operator++() {
|
||||||
|
++pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline const_iterator operator++(int) {
|
||||||
|
const auto tmp = *this;
|
||||||
|
++*this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
inline const_iterator & operator--() {
|
||||||
|
--pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline const_iterator operator--(int) {
|
||||||
|
const auto tmp = *this;
|
||||||
|
--*this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const_iterator & operator+=(const const_iterator & it) {
|
||||||
|
pos += it.pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline const_iterator & operator+=(size_t p) {
|
||||||
|
pos += p;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline const_iterator & operator-=(const const_iterator & it) {
|
||||||
|
pos -= it.pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline const_iterator & operator-=(size_t p) {
|
||||||
|
pos -= p;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend inline const_iterator operator-(size_t p, const const_iterator & it) { return it - p; }
|
||||||
|
friend inline const_iterator operator-(const const_iterator & it, size_t p) {
|
||||||
|
auto tmp = it;
|
||||||
|
tmp -= p;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
friend inline std::ptrdiff_t operator-(const const_iterator & it1, const const_iterator & it2) { return it1.pos - it2.pos; }
|
||||||
|
|
||||||
|
friend inline const_iterator operator+(size_t p, const const_iterator & it) { return it + p; }
|
||||||
|
friend inline const_iterator operator+(const const_iterator & it, size_t p) {
|
||||||
|
auto tmp = it;
|
||||||
|
tmp += p;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator==(const const_iterator & it) const { return (pos == it.pos); }
|
||||||
|
inline bool operator!=(const const_iterator & it) const { return (pos != it.pos); }
|
||||||
|
friend inline bool operator<(const const_iterator & it1, const const_iterator & it2) { return it1.pos < it2.pos; }
|
||||||
|
friend inline bool operator<=(const const_iterator & it1, const const_iterator & it2) { return it1.pos <= it2.pos; }
|
||||||
|
friend inline bool operator>(const const_iterator & it1, const const_iterator & it2) { return it1.pos > it2.pos; }
|
||||||
|
friend inline bool operator>=(const const_iterator & it1, const const_iterator & it2) { return it1.pos >= it2.pos; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inline const_iterator begin() const { return const_iterator(this, 0); }
|
||||||
|
inline const_iterator end() const { return const_iterator(this, _CSet::size()); }
|
||||||
|
|
||||||
//! Contructs set from vector of elements
|
//! Contructs set from vector of elements
|
||||||
explicit PISet(const PIVector<T> & values) {
|
explicit PISet(const PIVector<T> & values) {
|
||||||
if (values.isEmpty()) return;
|
if (values.isEmpty()) return;
|
||||||
@@ -199,10 +283,10 @@ inline PICout operator<<(PICout s, const PISet<Type> & v) {
|
|||||||
s.saveAndSetControls(0);
|
s.saveAndSetControls(0);
|
||||||
s << "{";
|
s << "{";
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (typename PIMap<Type, uchar>::const_iterator i = v.begin(); i != v.end(); ++i) {
|
for (const auto & i: v) {
|
||||||
if (!first) s << ", ";
|
if (!first) s << ", ";
|
||||||
first = false;
|
first = false;
|
||||||
s << i.key();
|
s << i;
|
||||||
}
|
}
|
||||||
s << "}";
|
s << "}";
|
||||||
s.restoreControls();
|
s.restoreControls();
|
||||||
|
|||||||
@@ -285,10 +285,10 @@ int main(int argc, char * argv[]) {
|
|||||||
ts << "<context>\n";
|
ts << "<context>\n";
|
||||||
ts << " <name>" << context << "</name>\n";
|
ts << " <name>" << context << "</name>\n";
|
||||||
for (const auto & s: strings) {
|
for (const auto & s: strings) {
|
||||||
TSMessage m = old.value(s.first);
|
TSMessage m = old.value(s);
|
||||||
m.filename = locations.value(s.first.hash());
|
m.filename = locations.value(s.hash());
|
||||||
writeTSMessage(s.first, m);
|
writeTSMessage(s, m);
|
||||||
old.remove(s.first);
|
old.remove(s);
|
||||||
}
|
}
|
||||||
if (!cli.hasArgument("no-obsolete")) {
|
if (!cli.hasArgument("no-obsolete")) {
|
||||||
for (const auto & i: old) {
|
for (const auto & i: old) {
|
||||||
|
|||||||
Reference in New Issue
Block a user