23.06.2014 - PICodeParser, PICodeInfo, PIConnection, new binary "pip_cmg"

This commit is contained in:
peri4
2014-06-23 21:08:27 +04:00
parent 2e5e75c4c4
commit 15a20d40ac
56 changed files with 10315 additions and 760 deletions

103
pimap.h
View File

@@ -26,9 +26,10 @@
#define PIMAP_H
#include "pivector.h"
#include "pideque.h"
#if 0 // !defined(PIP_CONTAINERS_STL) || defined(DOXYGEN)
#if !defined(PIP_CONTAINERS_STL) || defined(DOXYGEN)
template<class T>
void piQuickSort(T * a, ssize_t N) {
@@ -54,7 +55,7 @@ template <typename Key, typename T>
class PIMap {
public:
PIMap() {;}
PIMap(const PIMap<Key, T> & other) {;}
PIMap(const PIMap<Key, T> & other) {*this = other;}
~PIMap() {;}
PIMap<Key, T> & operator =(const PIMap<Key, T> & other) {
@@ -69,6 +70,42 @@ public:
typedef Key key_type;
typedef PIPair<Key, T> value_type;
class iterator {
friend class PIMap<Key, T>;
private:
iterator(const PIMap<Key, T> * v, ssize_t p): parent(v), pos(p) {}
const PIMap<Key, T> * parent;
ssize_t pos;
public:
iterator(): parent(0) {}
const Key & key() const {return const_cast<PIMap<Key, T> * >(parent)->_key(pos);}
T & value() const {return const_cast<PIMap<Key, T> * >(parent)->_value(pos);}
void operator ++() {++pos;}
void operator ++(int) {++pos;}
void operator --() {--pos;}
void operator --(int) {--pos;}
bool operator ==(const iterator & it) const {return (pos == it.pos);}
bool operator !=(const iterator & it) const {return (pos != it.pos);}
};
class reverse_iterator {
friend class PIMap<Key, T>;
private:
reverse_iterator(const PIMap<Key, T> * v, ssize_t p): parent(v), pos(p) {}
const PIMap<Key, T> * parent;
ssize_t pos;
public:
reverse_iterator(): parent(0) {}
const Key & key() const {return const_cast<PIMap<Key, T> * >(parent)->_key(pos);}
T & value() const {return const_cast<PIMap<Key, T> * >(parent)->_value(pos);}
void operator ++() {--pos;}
void operator ++(int) {--pos;}
void operator --() {++pos;}
void operator --(int) {++pos;}
bool operator ==(const reverse_iterator & it) const {return (pos == it.pos);}
bool operator !=(const reverse_iterator & it) const {return (pos != it.pos);}
};
class const_iterator {
friend class PIMap<Key, T>;
private:
@@ -78,12 +115,14 @@ public:
public:
const_iterator(): parent(0) {}
const PIMap<Key, T>::value_type operator *() const {return parent->_pair(pos);}
const PIMap<Key, T>::value_type* operator ->() const {cval = parent->_pair(pos); return &cval;}
void operator ++() {++pos;}
void operator ++(int) {++pos;}
void operator --() {--pos;}
void operator --(int) {--pos;}
bool operator ==(const const_iterator & it) const {return (pos == it.pos);}
bool operator !=(const const_iterator & it) const {return (pos != it.pos);}
mutable value_type cval;
};
class const_reverse_iterator {
@@ -95,20 +134,22 @@ public:
public:
const_reverse_iterator(): parent(0) {}
const PIMap<Key, T>::value_type operator *() const {return parent->_pair(pos);}
const PIMap<Key, T>::value_type* operator ->() const {cval = parent->_pair(pos); return &cval;}
void operator ++() {--pos;}
void operator ++(int) {--pos;}
void operator --() {++pos;}
void operator --(int) {++pos;}
bool operator ==(const const_reverse_iterator & it) const {return (pos == it.pos);}
bool operator !=(const const_reverse_iterator & it) const {return (pos != it.pos);}
mutable value_type cval;
};
// iterator begin() {return iterator(this, 0);}
// iterator end() {return iterator(this, size());}
iterator begin() {return iterator(this, 0);}
iterator end() {return iterator(this, size());}
const_iterator begin() const {return const_iterator(this, 0);}
const_iterator end() const {return const_iterator(this, size());}
// reverse_iterator rbegin() {return reverse_iterator(this, size() - 1);}
// reverse_iterator rend() {return reverse_iterator(this, -1);}
reverse_iterator rbegin() {return reverse_iterator(this, size() - 1);}
reverse_iterator rend() {return reverse_iterator(this, -1);}
const_reverse_iterator rbegin() const {return const_reverse_iterator(this, size() - 1);}
const_reverse_iterator rend() const {return const_reverse_iterator(this, -1);}
@@ -126,6 +167,20 @@ public:
return pim_content.back();
}
const T operator [](const Key & key) const {bool f(false); ssize_t i = _find(key, f); if (f) return pim_content[pim_index[i].index]; return T();}
T & at(const Key & key) {return (*this)[key];}
const T at(const Key & key) const {return (*this)[key];}
PIMap<Key, T> & operator <<(const PIMap<Key, T> & other) {
if (other.isEmpty()) return *this;
if (other.size() == 1) {insert(other.pim_index[0].key, other.pim_content[0]); return *this;}
if (other.size() == 2) {insert(other.pim_index[0].key, other.pim_content[0]); insert(other.pim_index[1].key, other.pim_content[1]); return *this;}
pim_content << other.pim_content;
size_t si = pim_index.size();
for (int i = 0; i < other.pim_content.size_s(); ++i)
pim_index << MapIndex(other.pim_index[i].key, other.pim_index[i].index + si);
_sort();
return *this;
}
bool operator ==(const PIMap<Key, T> & t) const {return (pim_content == t.pim_content && pim_index == t.pim_index);}
bool operator !=(const PIMap<Key, T> & t) const {return (pim_content != t.pim_content || pim_index != t.pim_index);}
@@ -136,6 +191,8 @@ public:
//PIMap<Key, T> & removeAll(const T & v) {for (llong i = 0; i < pim_size; ++i) if (pim_data[i] == v) {remove(i); --i;} return *this;}
PIMap<Key, T> & removeOne(const Key & key) {bool f(false); ssize_t i = _find(key, f); if (f) _remove(i); return *this;}
PIMap<Key, T> & remove(const Key & key) {return removeOne(key);}
PIMap<Key, T> & erase(const Key & key) {return removeOne(key);}
PIMap<Key, T> & clear() {pim_content.clear(); pim_index.clear(); return *this;}
void swap(PIMap<Key, T> & other) {
@@ -159,6 +216,13 @@ public:
}
//const T value(const Key & key, const T & default_ = T()) const {MapIndex * i = _find(key); if (i == 0) return default_; return pim_content[i->index];}
const T value(const Key & key, const T & default_ = T()) const {bool f(false); ssize_t i = _find(key, f); if (!f) return default_; return pim_content[pim_index[i].index];}
Key key(const T & value_, const Key & default_ = Key()) const {for (int i = 0; i < pim_index.size_s(); ++i) if (pim_content[pim_index[i].index] == value_) return pim_index[i].key; return default_;}
PIVector<Key> keys() const {
PIVector<Key> ret;
for (int i = 0; i < pim_index.size_s(); ++i)
ret << pim_index[i].key;
return ret;
}
void dump() {
piCout << "PIMap" << size() << "entries" << NewLine << "content:";
@@ -174,8 +238,10 @@ private:
MapIndex(Key k = Key(), size_t i = 0): key(k), index(i) {;}
Key key;
size_t index;
//bool operator <(const MapIndex & s) const {return key < s.key;}
//bool operator >(const MapIndex & s) const {return key > s.key;}
bool operator ==(const MapIndex & s) const {return key == s.key;}
bool operator !=(const MapIndex & s) const {return key != s.key;}
bool operator <(const MapIndex & s) const {return key < s.key;}
bool operator >(const MapIndex & s) const {return key > s.key;}
};
ssize_t binarySearch(ssize_t first, ssize_t last, const Key & key, bool & found) const {
@@ -184,10 +250,7 @@ private:
mid = (first + last) / 2;
if (key > pim_index[mid].key) first = mid + 1;
else if (key < pim_index[mid].key) last = mid - 1;
else {
found = true;
return mid;
}
else {found = true; return mid;}
}
found = false;
return first;
@@ -225,16 +288,18 @@ private:
//piCout << "_pair" << index << pim_index[index].index;
return value_type(pim_index[index].key, pim_content[pim_index[index].index]);
}
Key & _key(ssize_t index) {return pim_index[index].key;}
T & _value(ssize_t index) {return pim_content[pim_index[index].index];}
PIVector<T> pim_content;
PIVector<MapIndex> pim_index;
PIDeque<MapIndex> pim_index;
};
//template <typename Key, typename T> bool operator <(const typename PIMap<Key, T>::MapIndex & f, const typename PIMap<Key, T>::MapIndex & s) {return f.key < s.key;}
//template <typename Key, typename T> bool operator >(const typename PIMap<Key, T>::MapIndex & f, const typename PIMap<Key, T>::MapIndex & s) {return f.key > s.key;}
#define __PIMAP_SIMPLE_FUNCTIONS__(T)
/* template<> inline PIMap<Key, T>::~PIMap() {dealloc(); _reset();} \
/*#define __PIMAP_SIMPLE_FUNCTIONS__(T)
template<> inline PIMap<Key, T>::~PIMap() {dealloc(); _reset();} \
template<> inline PIMap<Key, T> & PIMap<Key, T>::push_back(const T & v) {alloc(pim_size + 1); pim_data[pim_size - 1] = v; return *this;} \
template<> inline PIMap<Key, T> & PIMap<Key, T>::fill(const T & f) { \
for (size_t i = 0; i < pim_size; ++i) \
@@ -269,7 +334,7 @@ private:
memmove(&(pim_data[index]), &(pim_data[index + count]), os * sizeof(T)); \
pim_size -= count; \
return *this; \
}*/
}
__PIMAP_SIMPLE_FUNCTIONS__(char)
__PIMAP_SIMPLE_FUNCTIONS__(uchar)
@@ -283,7 +348,7 @@ __PIMAP_SIMPLE_FUNCTIONS__(llong)
__PIMAP_SIMPLE_FUNCTIONS__(ullong)
__PIMAP_SIMPLE_FUNCTIONS__(float)
__PIMAP_SIMPLE_FUNCTIONS__(double)
__PIMAP_SIMPLE_FUNCTIONS__(ldouble)
__PIMAP_SIMPLE_FUNCTIONS__(ldouble)*/
#else
@@ -301,7 +366,7 @@ public:
int size_s() const {return static_cast<int>(_stlc::size());}
_CMap & insert(const Key & key_, const Type & value_) {_stlc::insert(_stlpair(key_, value_)); return *this;}
_CMap & insert(PIPair<Key, Type> entry_) {_stlc::insert(_stlpair(entry_.first, entry_.second)); return *this;}
Key key(Type value_) const {for (typename _stlc::const_iterator i = _stlc::begin(); i != _stlc::end(); i++) if (i->second == value_) return i->first; return Key();}
Key key(Type value_, const Key & default_ = Key()) const {for (typename _stlc::const_iterator i = _stlc::begin(); i != _stlc::end(); i++) if (i->second == value_) return i->first; return default_;}
PIVector<Key> keys() const {
PIVector<Key> ret;
for (typename _stlc::const_iterator i = _stlc::begin(); i != _stlc::end(); i++)
@@ -325,7 +390,7 @@ public:
_CMultiMap & insert(PIPair<Key, Type> entry_) {_stlc::insert(_stlpair(entry_.first, entry_.second)); return *this;}
bool isEmpty() const {return _stlc::empty();}
bool contains(const Key & key_) const {return _stlc::count(key_) > 0;}
Key key(Type value_) const {for (typename _stlc::const_iterator i = _stlc::begin(); i != _stlc::end(); i++) if (i->second == value_) return i->first; return Key();}
Key key(Type value_, const Key & default_ = Key()) const {for (typename _stlc::const_iterator i = _stlc::begin(); i != _stlc::end(); i++) if (i->second == value_) return i->first; return default_;}
PIVector<Key> keys(Type value_) const {
PIVector<Key> ret;
for (typename _stlc::const_iterator i = _stlc::begin(); i != _stlc::end(); i++)