15.04.2014 - Version 0.3.8_beta, last version of 0.3.8 branch. Too much added and fixed...

This commit is contained in:
peri4
2014-04-15 13:19:07 +04:00
parent f50891b376
commit 77abb0bbea
46 changed files with 4538 additions and 2515 deletions

View File

@@ -27,8 +27,25 @@
#define PICONTAINERS_H
#include "pivector.h"
template<typename Type0, typename Type1>
class PIP_EXPORT PIPair {
public:
PIPair() {first = Type0(); second = Type1();}
PIPair(const Type0 & value0, const Type1 & value1) {first = value0; second = value1;}
Type0 first;
Type1 second;
};
template<typename Type0, typename Type1>
inline bool operator <(const PIPair<Type0, Type1> & value0, const PIPair<Type0, Type1> & value1) {return value0.first < value1.first;}
template<typename Type0, typename Type1>
inline std::ostream & operator <<(std::ostream & s, const PIPair<Type0, Type1> & v) {s << "(" << v.first << ", " << v.second << ")"; return s;}
template<typename Type0, typename Type1>
inline PICout operator <<(PICout s, const PIPair<Type0, Type1> & v) {s.space(); s.setControl(0, true); s << "(" << v.first << ", " << v.second << ")"; s.restoreControl(); return s;}
#include "pistack.h"
#include "piqueue.h"
#include "pimap.h"
#ifdef DOXYGEN
/*! \def piForeach(i,c)
@@ -295,73 +312,4 @@ public:
};
template<typename Type0, typename Type1>
class PIP_EXPORT PIPair {
public:
PIPair() {first = Type0(); second = Type1();}
PIPair(const Type0 & value0, const Type1 & value1) {first = value0; second = value1;}
Type0 first;
Type1 second;
};
template<typename Type0, typename Type1>
inline bool operator <(const PIPair<Type0, Type1> & value0, const PIPair<Type0, Type1> & value1) {return value0.first < value1.first;}
template<typename Type0, typename Type1>
inline std::ostream & operator <<(std::ostream & s, const PIPair<Type0, Type1> & v) {s << "(" << v.first << ", " << v.second << ")"; return s;}
template<typename Type0, typename Type1>
inline PICout operator <<(PICout s, const PIPair<Type0, Type1> & v) {s.space(); s.setControl(0, true); s << "(" << v.first << ", " << v.second << ")"; s.restoreControl(); return s;}
template<typename Key, typename Type>
class PIP_EXPORT PIMap: public map<Key, Type> {
typedef PIMap<Key, Type> _CMap;
typedef map<Key, Type> _stlc;
typedef std::pair<Key, Type> _stlpair;
public:
PIMap() {;}
PIMap(const Key & key_, const Type & value_) {insert(key_, value_);}
bool isEmpty() const {return _stlc::empty();}
bool contains(const Key & key_) const {return _stlc::count(key_) > 0;}
_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();}
Type & value(const Key & key_) {typename _stlc::iterator it = _stlc::find(key_); if (it == _stlc::end()) it->second = Type(); return it->second;}
Type & at(const Key & key_) {return value(key_);}
Type value(const Key & key_) const {return _stlc::find(key_)->second;}
};
template<typename Key, typename Type>
class PIP_EXPORT PIMultiMap: public multimap<Key, Type> {
typedef PIMultiMap<Key, Type> _CMultiMap;
typedef multimap<Key, Type> _stlc;
typedef std::pair<Key, Type> _stlpair;
public:
PIMultiMap() {;}
PIMultiMap(const Key & key_, const Type & value_) {insert(key_, value_);}
_CMultiMap & insert(const Key & key_, const Type & value_) {_stlc::insert(_stlpair(key_, value_)); return *this;}
_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();}
PIVector<Key> keys(Type value_) const {
PIVector<Key> ret;
for (typename _stlc::const_iterator i = _stlc::begin(); i != _stlc::end(); i++)
if (i->second == value_)
ret << i->first;
return ret;
}
Type & value(const Key & key_) {return _stlc::find(key_)->second;}
Type value(const Key & key_) const {return _stlc::find(key_)->second;}
PIVector<Type> values(const Key & key_) const {
std::pair<typename _stlc::const_iterator, typename _stlc::const_iterator> range = _stlc::equal_range(key_);
PIVector<Type> ret;
for (typename _stlc::const_iterator i = range.first; i != range.second; ++i)
ret << i->second;
return ret;
}
Type & operator [](const Key & key_) {if (!contains(key_)) return _stlc::insert(_stlpair(key_, Type()))->second; return _stlc::find(key_)->second;}
Type operator [](const Key & key_) const {return _stlc::find(key_)->second;}
};
#endif // PICONTAINERS_H