Formatting.
svn-id: r31852
This commit is contained in:
parent
06dea14540
commit
db04dd427d
7 changed files with 72 additions and 72 deletions
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
template <class T>
|
template<class T>
|
||||||
class Array {
|
class Array {
|
||||||
protected:
|
protected:
|
||||||
uint _capacity;
|
uint _capacity;
|
||||||
|
@ -45,7 +45,7 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Array() : _capacity(0), _size(0), _data(0) {}
|
Array() : _capacity(0), _size(0), _data(0) {}
|
||||||
Array(const Array<T>& array) : _capacity(0), _size(0), _data(0) {
|
Array(const Array<T> &array) : _capacity(0), _size(0), _data(0) {
|
||||||
_size = array._size;
|
_size = array._size;
|
||||||
_capacity = _size + 32;
|
_capacity = _size + 32;
|
||||||
_data = new T[_capacity];
|
_data = new T[_capacity];
|
||||||
|
@ -53,21 +53,21 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
~Array() {
|
~Array() {
|
||||||
delete [] _data;
|
delete[] _data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void push_back(const T& element) {
|
void push_back(const T &element) {
|
||||||
ensureCapacity(_size + 1);
|
ensureCapacity(_size + 1);
|
||||||
_data[_size++] = element;
|
_data[_size++] = element;
|
||||||
}
|
}
|
||||||
|
|
||||||
void push_back(const Array<T>& array) {
|
void push_back(const Array<T> &array) {
|
||||||
ensureCapacity(_size + array._size);
|
ensureCapacity(_size + array._size);
|
||||||
copy(array._data, array._data + array._size, _data + _size);
|
copy(array._data, array._data + array._size, _data + _size);
|
||||||
_size += array._size;
|
_size += array._size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void insert_at(int idx, const T& element) {
|
void insert_at(int idx, const T &element) {
|
||||||
assert(idx >= 0 && (uint)idx <= _size);
|
assert(idx >= 0 && (uint)idx <= _size);
|
||||||
ensureCapacity(_size + 1);
|
ensureCapacity(_size + 1);
|
||||||
copy_backward(_data + idx, _data + _size, _data + _size + 1);
|
copy_backward(_data + idx, _data + _size, _data + _size + 1);
|
||||||
|
@ -85,17 +85,17 @@ public:
|
||||||
|
|
||||||
// TODO: insert, remove, ...
|
// TODO: insert, remove, ...
|
||||||
|
|
||||||
T& operator [](int idx) {
|
T& operator[](int idx) {
|
||||||
assert(idx >= 0 && (uint)idx < _size);
|
assert(idx >= 0 && (uint)idx < _size);
|
||||||
return _data[idx];
|
return _data[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
const T& operator [](int idx) const {
|
const T& operator[](int idx) const {
|
||||||
assert(idx >= 0 && (uint)idx < _size);
|
assert(idx >= 0 && (uint)idx < _size);
|
||||||
return _data[idx];
|
return _data[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
Array<T>& operator =(const Array<T>& array) {
|
Array<T>& operator=(const Array<T> &array) {
|
||||||
if (this == &array)
|
if (this == &array)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
|
|
|
@ -279,13 +279,13 @@ private:
|
||||||
* Base template for hash functor objects, used by HashMap.
|
* Base template for hash functor objects, used by HashMap.
|
||||||
* This needs to be specialized for every type that you need to hash.
|
* This needs to be specialized for every type that you need to hash.
|
||||||
*/
|
*/
|
||||||
template <typename T> struct Hash;
|
template<typename T> struct Hash;
|
||||||
|
|
||||||
|
|
||||||
#define GENERATE_TRIVIAL_HASH_FUNCTOR(T) \
|
#define GENERATE_TRIVIAL_HASH_FUNCTOR(T) \
|
||||||
template <> struct Hash<T> : public UnaryFunction<T, uint> { \
|
template<> struct Hash<T> : public UnaryFunction<T, uint> { \
|
||||||
uint operator()(T val) const { return (uint)val; } \
|
uint operator()(T val) const { return (uint)val; } \
|
||||||
}
|
}
|
||||||
|
|
||||||
GENERATE_TRIVIAL_HASH_FUNCTOR(bool);
|
GENERATE_TRIVIAL_HASH_FUNCTOR(bool);
|
||||||
GENERATE_TRIVIAL_HASH_FUNCTOR(char);
|
GENERATE_TRIVIAL_HASH_FUNCTOR(char);
|
||||||
|
|
|
@ -94,7 +94,7 @@ uint nextTableSize(uint x);
|
||||||
* triggered instead. Hence if you are not sure whether a key is contained in
|
* triggered instead. Hence if you are not sure whether a key is contained in
|
||||||
* the map, use contains() first to check for its presence.
|
* the map, use contains() first to check for its presence.
|
||||||
*/
|
*/
|
||||||
template <class Key, class Val, class HashFunc = Hash<Key>, class EqualFunc = EqualTo<Key> >
|
template<class Key, class Val, class HashFunc = Hash<Key>, class EqualFunc = EqualTo<Key> >
|
||||||
class HashMap {
|
class HashMap {
|
||||||
private:
|
private:
|
||||||
#if defined (PALMOS_MODE)
|
#if defined (PALMOS_MODE)
|
||||||
|
@ -113,17 +113,17 @@ public:
|
||||||
#ifdef USE_HASHMAP_MEMORY_POOL
|
#ifdef USE_HASHMAP_MEMORY_POOL
|
||||||
MemoryPool _nodePool;
|
MemoryPool _nodePool;
|
||||||
|
|
||||||
Node *allocNode(const Key& key) {
|
Node *allocNode(const Key &key) {
|
||||||
void* mem = _nodePool.malloc();
|
void* mem = _nodePool.malloc();
|
||||||
return new (mem) Node(key);
|
return new (mem) Node(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void freeNode(Node* node) {
|
void freeNode(Node *node) {
|
||||||
node->~Node();
|
node->~Node();
|
||||||
_nodePool.free(node);
|
_nodePool.free(node);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
Node* allocNode(const Key& key) {
|
Node* allocNode(const Key &key) {
|
||||||
return new Node(key);
|
return new Node(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ public:
|
||||||
mutable int _collisions, _lookups;
|
mutable int _collisions, _lookups;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void assign(const HM_t& map);
|
void assign(const HM_t &map);
|
||||||
int lookup(const Key &key) const;
|
int lookup(const Key &key) const;
|
||||||
int lookupAndCreateIfMissing(const Key &key);
|
int lookupAndCreateIfMissing(const Key &key);
|
||||||
void expand_array(uint newsize);
|
void expand_array(uint newsize);
|
||||||
|
@ -181,13 +181,13 @@ public:
|
||||||
template<class T>
|
template<class T>
|
||||||
IteratorImpl(const IteratorImpl<T> &c) : _idx(c._idx), _hashmap(c._hashmap) {}
|
IteratorImpl(const IteratorImpl<T> &c) : _idx(c._idx), _hashmap(c._hashmap) {}
|
||||||
|
|
||||||
NodeType &operator *() const { return *deref(); }
|
NodeType &operator*() const { return *deref(); }
|
||||||
NodeType *operator->() const { return deref(); }
|
NodeType *operator->() const { return deref(); }
|
||||||
|
|
||||||
bool operator ==(const IteratorImpl &iter) const { return _idx == iter._idx && _hashmap == iter._hashmap; }
|
bool operator==(const IteratorImpl &iter) const { return _idx == iter._idx && _hashmap == iter._hashmap; }
|
||||||
bool operator !=(const IteratorImpl &iter) const { return !(*this == iter); }
|
bool operator!=(const IteratorImpl &iter) const { return !(*this == iter); }
|
||||||
|
|
||||||
IteratorImpl &operator ++() {
|
IteratorImpl &operator++() {
|
||||||
assert(_hashmap);
|
assert(_hashmap);
|
||||||
do {
|
do {
|
||||||
_idx++;
|
_idx++;
|
||||||
|
@ -198,7 +198,7 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IteratorImpl operator ++(int) {
|
IteratorImpl operator++(int) {
|
||||||
IteratorImpl old = *this;
|
IteratorImpl old = *this;
|
||||||
operator ++();
|
operator ++();
|
||||||
return old;
|
return old;
|
||||||
|
@ -210,10 +210,10 @@ public:
|
||||||
typedef IteratorImpl<const Node> const_iterator;
|
typedef IteratorImpl<const Node> const_iterator;
|
||||||
|
|
||||||
HashMap();
|
HashMap();
|
||||||
HashMap(const HM_t& map);
|
HashMap(const HM_t &map);
|
||||||
~HashMap();
|
~HashMap();
|
||||||
|
|
||||||
HM_t &operator =(const HM_t &map) {
|
HM_t &operator=(const HM_t &map) {
|
||||||
if (this == &map)
|
if (this == &map)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
|
@ -227,8 +227,8 @@ public:
|
||||||
|
|
||||||
bool contains(const Key &key) const;
|
bool contains(const Key &key) const;
|
||||||
|
|
||||||
Val &operator [](const Key &key);
|
Val &operator[](const Key &key);
|
||||||
const Val &operator [](const Key &key) const;
|
const Val &operator[](const Key &key) const;
|
||||||
|
|
||||||
Val &getVal(const Key &key);
|
Val &getVal(const Key &key);
|
||||||
const Val &getVal(const Key &key) const;
|
const Val &getVal(const Key &key) const;
|
||||||
|
@ -291,7 +291,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Base constructor, creates an empty hashmap.
|
* Base constructor, creates an empty hashmap.
|
||||||
*/
|
*/
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc>
|
template<class Key, class Val, class HashFunc, class EqualFunc>
|
||||||
HashMap<Key, Val, HashFunc, EqualFunc>::HashMap() :
|
HashMap<Key, Val, HashFunc, EqualFunc>::HashMap() :
|
||||||
#ifdef USE_HASHMAP_MEMORY_POOL
|
#ifdef USE_HASHMAP_MEMORY_POOL
|
||||||
_nodePool(sizeof(Node)),
|
_nodePool(sizeof(Node)),
|
||||||
|
@ -315,8 +315,8 @@ HashMap<Key, Val, HashFunc, EqualFunc>::HashMap() :
|
||||||
* We must provide a custom copy constructor as we use pointers
|
* We must provide a custom copy constructor as we use pointers
|
||||||
* to heap buffers for the internal storage.
|
* to heap buffers for the internal storage.
|
||||||
*/
|
*/
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc>
|
template<class Key, class Val, class HashFunc, class EqualFunc>
|
||||||
HashMap<Key, Val, HashFunc, EqualFunc>::HashMap(const HM_t& map) :
|
HashMap<Key, Val, HashFunc, EqualFunc>::HashMap(const HM_t &map) :
|
||||||
#ifdef USE_HASHMAP_MEMORY_POOL
|
#ifdef USE_HASHMAP_MEMORY_POOL
|
||||||
_nodePool(sizeof(Node)),
|
_nodePool(sizeof(Node)),
|
||||||
#endif
|
#endif
|
||||||
|
@ -327,7 +327,7 @@ HashMap<Key, Val, HashFunc, EqualFunc>::HashMap(const HM_t& map) :
|
||||||
/**
|
/**
|
||||||
* Destructor, frees all used memory.
|
* Destructor, frees all used memory.
|
||||||
*/
|
*/
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc>
|
template<class Key, class Val, class HashFunc, class EqualFunc>
|
||||||
HashMap<Key, Val, HashFunc, EqualFunc>::~HashMap() {
|
HashMap<Key, Val, HashFunc, EqualFunc>::~HashMap() {
|
||||||
for (uint ctr = 0; ctr < _arrsize; ++ctr)
|
for (uint ctr = 0; ctr < _arrsize; ++ctr)
|
||||||
if (_arr[ctr] != NULL)
|
if (_arr[ctr] != NULL)
|
||||||
|
@ -343,8 +343,8 @@ HashMap<Key, Val, HashFunc, EqualFunc>::~HashMap() {
|
||||||
* @note We do *not* deallocate the previous storage here -- the caller is
|
* @note We do *not* deallocate the previous storage here -- the caller is
|
||||||
* responsible for doing that!
|
* responsible for doing that!
|
||||||
*/
|
*/
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc>
|
template<class Key, class Val, class HashFunc, class EqualFunc>
|
||||||
void HashMap<Key, Val, HashFunc, EqualFunc>::assign(const HM_t& map) {
|
void HashMap<Key, Val, HashFunc, EqualFunc>::assign(const HM_t &map) {
|
||||||
_arrsize = map._arrsize;
|
_arrsize = map._arrsize;
|
||||||
_arr = new Node *[_arrsize];
|
_arr = new Node *[_arrsize];
|
||||||
assert(_arr != NULL);
|
assert(_arr != NULL);
|
||||||
|
@ -364,7 +364,7 @@ void HashMap<Key, Val, HashFunc, EqualFunc>::assign(const HM_t& map) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc>
|
template<class Key, class Val, class HashFunc, class EqualFunc>
|
||||||
void HashMap<Key, Val, HashFunc, EqualFunc>::clear(bool shrinkArray) {
|
void HashMap<Key, Val, HashFunc, EqualFunc>::clear(bool shrinkArray) {
|
||||||
for (uint ctr = 0; ctr < _arrsize; ++ctr) {
|
for (uint ctr = 0; ctr < _arrsize; ++ctr) {
|
||||||
if (_arr[ctr] != NULL) {
|
if (_arr[ctr] != NULL) {
|
||||||
|
@ -385,7 +385,7 @@ void HashMap<Key, Val, HashFunc, EqualFunc>::clear(bool shrinkArray) {
|
||||||
_nele = 0;
|
_nele = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc>
|
template<class Key, class Val, class HashFunc, class EqualFunc>
|
||||||
void HashMap<Key, Val, HashFunc, EqualFunc>::expand_array(uint newsize) {
|
void HashMap<Key, Val, HashFunc, EqualFunc>::expand_array(uint newsize) {
|
||||||
assert(newsize > _arrsize);
|
assert(newsize > _arrsize);
|
||||||
uint ctr, dex;
|
uint ctr, dex;
|
||||||
|
@ -428,7 +428,7 @@ void HashMap<Key, Val, HashFunc, EqualFunc>::expand_array(uint newsize) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc>
|
template<class Key, class Val, class HashFunc, class EqualFunc>
|
||||||
int HashMap<Key, Val, HashFunc, EqualFunc>::lookup(const Key &key) const {
|
int HashMap<Key, Val, HashFunc, EqualFunc>::lookup(const Key &key) const {
|
||||||
uint ctr = _hash(key) % _arrsize;
|
uint ctr = _hash(key) % _arrsize;
|
||||||
|
|
||||||
|
@ -450,7 +450,7 @@ int HashMap<Key, Val, HashFunc, EqualFunc>::lookup(const Key &key) const {
|
||||||
return ctr;
|
return ctr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc>
|
template<class Key, class Val, class HashFunc, class EqualFunc>
|
||||||
int HashMap<Key, Val, HashFunc, EqualFunc>::lookupAndCreateIfMissing(const Key &key) {
|
int HashMap<Key, Val, HashFunc, EqualFunc>::lookupAndCreateIfMissing(const Key &key) {
|
||||||
uint ctr = lookup(key);
|
uint ctr = lookup(key);
|
||||||
|
|
||||||
|
@ -469,30 +469,30 @@ int HashMap<Key, Val, HashFunc, EqualFunc>::lookupAndCreateIfMissing(const Key &
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc>
|
template<class Key, class Val, class HashFunc, class EqualFunc>
|
||||||
bool HashMap<Key, Val, HashFunc, EqualFunc>::contains(const Key &key) const {
|
bool HashMap<Key, Val, HashFunc, EqualFunc>::contains(const Key &key) const {
|
||||||
uint ctr = lookup(key);
|
uint ctr = lookup(key);
|
||||||
return (_arr[ctr] != NULL);
|
return (_arr[ctr] != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc>
|
template<class Key, class Val, class HashFunc, class EqualFunc>
|
||||||
Val &HashMap<Key, Val, HashFunc, EqualFunc>::operator [](const Key &key) {
|
Val &HashMap<Key, Val, HashFunc, EqualFunc>::operator[](const Key &key) {
|
||||||
return getVal(key);
|
return getVal(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc>
|
template<class Key, class Val, class HashFunc, class EqualFunc>
|
||||||
const Val &HashMap<Key, Val, HashFunc, EqualFunc>::operator [](const Key &key) const {
|
const Val &HashMap<Key, Val, HashFunc, EqualFunc>::operator[](const Key &key) const {
|
||||||
return getVal(key);
|
return getVal(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc>
|
template<class Key, class Val, class HashFunc, class EqualFunc>
|
||||||
Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) {
|
Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) {
|
||||||
uint ctr = lookupAndCreateIfMissing(key);
|
uint ctr = lookupAndCreateIfMissing(key);
|
||||||
assert(_arr[ctr] != NULL);
|
assert(_arr[ctr] != NULL);
|
||||||
return _arr[ctr]->_value;
|
return _arr[ctr]->_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc>
|
template<class Key, class Val, class HashFunc, class EqualFunc>
|
||||||
const Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) const {
|
const Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) const {
|
||||||
uint ctr = lookup(key);
|
uint ctr = lookup(key);
|
||||||
if (_arr[ctr] != NULL)
|
if (_arr[ctr] != NULL)
|
||||||
|
@ -501,14 +501,14 @@ const Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) const
|
||||||
return _defaultVal;
|
return _defaultVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc>
|
template<class Key, class Val, class HashFunc, class EqualFunc>
|
||||||
void HashMap<Key, Val, HashFunc, EqualFunc>::setVal(const Key &key, const Val &val) {
|
void HashMap<Key, Val, HashFunc, EqualFunc>::setVal(const Key &key, const Val &val) {
|
||||||
uint ctr = lookupAndCreateIfMissing(key);
|
uint ctr = lookupAndCreateIfMissing(key);
|
||||||
assert(_arr[ctr] != NULL);
|
assert(_arr[ctr] != NULL);
|
||||||
_arr[ctr]->_value = val;
|
_arr[ctr]->_value = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc>
|
template<class Key, class Val, class HashFunc, class EqualFunc>
|
||||||
void HashMap<Key, Val, HashFunc, EqualFunc>::erase(const Key &key) {
|
void HashMap<Key, Val, HashFunc, EqualFunc>::erase(const Key &key) {
|
||||||
// This is based on code in the Wikipedia article on Hash tables.
|
// This is based on code in the Wikipedia article on Hash tables.
|
||||||
uint i = lookup(key);
|
uint i = lookup(key);
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace Common {
|
||||||
* Simple double linked list, modeled after the list template of the standard
|
* Simple double linked list, modeled after the list template of the standard
|
||||||
* C++ library.
|
* C++ library.
|
||||||
*/
|
*/
|
||||||
template <class t_T>
|
template<class t_T>
|
||||||
class List {
|
class List {
|
||||||
protected:
|
protected:
|
||||||
#if defined (_WIN32_WCE) || defined (_MSC_VER)
|
#if defined (_WIN32_WCE) || defined (_MSC_VER)
|
||||||
|
@ -52,7 +52,7 @@ public:
|
||||||
Node(const t_T2 &x) : _data(x) {}
|
Node(const t_T2 &x) : _data(x) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class t_T2>
|
template<class t_T2>
|
||||||
class Iterator {
|
class Iterator {
|
||||||
template<class T> friend class Iterator;
|
template<class T> friend class Iterator;
|
||||||
friend class List<t_T>;
|
friend class List<t_T>;
|
||||||
|
@ -70,7 +70,7 @@ public:
|
||||||
Iterator(const Iterator<T> &c) : _node(c._node) {}
|
Iterator(const Iterator<T> &c) : _node(c._node) {}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Iterator<t_T2> &operator =(const Iterator<T> &c) {
|
Iterator<t_T2> &operator=(const Iterator<T> &c) {
|
||||||
_node = c._node;
|
_node = c._node;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ public:
|
||||||
#if (__GNUC__ == 2) && (__GNUC_MINOR__ >= 95)
|
#if (__GNUC__ == 2) && (__GNUC_MINOR__ >= 95)
|
||||||
return static_cast<List<t_T>::Node<t_T2> *>(_node)->_data;
|
return static_cast<List<t_T>::Node<t_T2> *>(_node)->_data;
|
||||||
#else
|
#else
|
||||||
return static_cast<Node<t_T2>*>(_node)->_data;
|
return static_cast<Node<t_T2> *>(_node)->_data;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
t_T2 *operator->() const {
|
t_T2 *operator->() const {
|
||||||
|
@ -135,7 +135,7 @@ public:
|
||||||
_anchor._prev = &_anchor;
|
_anchor._prev = &_anchor;
|
||||||
_anchor._next = &_anchor;
|
_anchor._next = &_anchor;
|
||||||
}
|
}
|
||||||
List(const List<t_T>& list) {
|
List(const List<t_T> &list) {
|
||||||
_anchor._prev = &_anchor;
|
_anchor._prev = &_anchor;
|
||||||
_anchor._next = &_anchor;
|
_anchor._next = &_anchor;
|
||||||
|
|
||||||
|
@ -146,15 +146,15 @@ public:
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void push_front(const t_T& element) {
|
void push_front(const t_T &element) {
|
||||||
insert(begin(), element);
|
insert(begin(), element);
|
||||||
}
|
}
|
||||||
|
|
||||||
void push_back(const t_T& element) {
|
void push_back(const t_T &element) {
|
||||||
insert(end(), element);
|
insert(end(), element);
|
||||||
}
|
}
|
||||||
|
|
||||||
void insert(iterator pos, const t_T& element) {
|
void insert(iterator pos, const t_T &element) {
|
||||||
NodeBase *newNode = new Node<t_T>(element);
|
NodeBase *newNode = new Node<t_T>(element);
|
||||||
|
|
||||||
newNode->_next = pos._node;
|
newNode->_next = pos._node;
|
||||||
|
@ -163,7 +163,7 @@ public:
|
||||||
newNode->_next->_prev = newNode;
|
newNode->_next->_prev = newNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename iterator2>
|
template<typename iterator2>
|
||||||
void insert(iterator pos, iterator2 first, iterator2 last) {
|
void insert(iterator pos, iterator2 first, iterator2 last) {
|
||||||
for (; first != last; ++first)
|
for (; first != last; ++first)
|
||||||
insert(pos, *first);
|
insert(pos, *first);
|
||||||
|
@ -210,7 +210,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
List<t_T>& operator =(const List<t_T>& list) {
|
List<t_T> &operator=(const List<t_T> &list) {
|
||||||
if (this != &list) {
|
if (this != &list) {
|
||||||
iterator i;
|
iterator i;
|
||||||
const_iterator j;
|
const_iterator j;
|
||||||
|
|
|
@ -38,7 +38,7 @@ public:
|
||||||
private:
|
private:
|
||||||
// Prevent copying instances by accident
|
// Prevent copying instances by accident
|
||||||
NonCopyable(const NonCopyable&);
|
NonCopyable(const NonCopyable&);
|
||||||
NonCopyable& operator= (const NonCopyable&);
|
NonCopyable& operator=(const NonCopyable&);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End of namespace Common
|
} // End of namespace Common
|
||||||
|
|
|
@ -33,13 +33,13 @@ namespace Common {
|
||||||
/**
|
/**
|
||||||
* Generic template base class for implementing the singleton design pattern.
|
* Generic template base class for implementing the singleton design pattern.
|
||||||
*/
|
*/
|
||||||
template <class T>
|
template<class T>
|
||||||
class Singleton : NonCopyable {
|
class Singleton : NonCopyable {
|
||||||
private:
|
private:
|
||||||
Singleton<T>(const Singleton<T>&);
|
Singleton<T>(const Singleton<T> &);
|
||||||
Singleton<T>& operator= (const Singleton<T>&);
|
Singleton<T> &operator=(const Singleton<T> &);
|
||||||
|
|
||||||
static T* _singleton;
|
static T *_singleton;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default object factory used by the template class Singleton.
|
* The default object factory used by the template class Singleton.
|
||||||
|
@ -53,7 +53,7 @@ private:
|
||||||
//FIXME evc4 and msvc7 doesn't like it as private member
|
//FIXME evc4 and msvc7 doesn't like it as private member
|
||||||
public:
|
public:
|
||||||
#endif
|
#endif
|
||||||
static T* makeInstance() {
|
static T *makeInstance() {
|
||||||
return new T();
|
return new T();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ protected:
|
||||||
typedef T SingletonBaseType;
|
typedef T SingletonBaseType;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DECLARE_SINGLETON(T) template<> T* Common::Singleton<T>::_singleton=0
|
#define DECLARE_SINGLETON(T) template<> T *Common::Singleton<T>::_singleton = 0
|
||||||
|
|
||||||
} // End of namespace Common
|
} // End of namespace Common
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace Common {
|
||||||
/**
|
/**
|
||||||
* Extremly simple fixed size stack class.
|
* Extremly simple fixed size stack class.
|
||||||
*/
|
*/
|
||||||
template <class T, int MAX_SIZE = 10>
|
template<class T, int MAX_SIZE = 10>
|
||||||
class FixedStack {
|
class FixedStack {
|
||||||
protected:
|
protected:
|
||||||
T _stack[MAX_SIZE];
|
T _stack[MAX_SIZE];
|
||||||
|
@ -47,15 +47,15 @@ public:
|
||||||
void clear() {
|
void clear() {
|
||||||
_size = 0;
|
_size = 0;
|
||||||
}
|
}
|
||||||
void push(const T& x) {
|
void push(const T &x) {
|
||||||
assert(_size < MAX_SIZE);
|
assert(_size < MAX_SIZE);
|
||||||
_stack[_size++] = x;
|
_stack[_size++] = x;
|
||||||
}
|
}
|
||||||
const T& top() const {
|
const T &top() const {
|
||||||
assert(_size > 0);
|
assert(_size > 0);
|
||||||
return _stack[_size - 1];
|
return _stack[_size - 1];
|
||||||
}
|
}
|
||||||
T& top() {
|
T &top() {
|
||||||
assert(_size > 0);
|
assert(_size > 0);
|
||||||
return _stack[_size - 1];
|
return _stack[_size - 1];
|
||||||
}
|
}
|
||||||
|
@ -67,11 +67,11 @@ public:
|
||||||
int size() const {
|
int size() const {
|
||||||
return _size;
|
return _size;
|
||||||
}
|
}
|
||||||
T& operator [](int i) {
|
T &operator[](int i) {
|
||||||
assert(0 <= i && i < MAX_SIZE);
|
assert(0 <= i && i < MAX_SIZE);
|
||||||
return _stack[i];
|
return _stack[i];
|
||||||
}
|
}
|
||||||
const T& operator [](int i) const {
|
const T &operator[](int i) const {
|
||||||
assert(0 <= i && i < MAX_SIZE);
|
assert(0 <= i && i < MAX_SIZE);
|
||||||
return _stack[i];
|
return _stack[i];
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Variable size stack class, implemented using our Array class.
|
* Variable size stack class, implemented using our Array class.
|
||||||
*/
|
*/
|
||||||
template <class T>
|
template<class T>
|
||||||
class Stack {
|
class Stack {
|
||||||
protected:
|
protected:
|
||||||
Array<T> _stack;
|
Array<T> _stack;
|
||||||
|
@ -95,7 +95,7 @@ public:
|
||||||
void clear() {
|
void clear() {
|
||||||
_stack.clear();
|
_stack.clear();
|
||||||
}
|
}
|
||||||
void push(const T& x) {
|
void push(const T &x) {
|
||||||
_stack.push_back(x);
|
_stack.push_back(x);
|
||||||
}
|
}
|
||||||
T top() const {
|
T top() const {
|
||||||
|
@ -110,7 +110,7 @@ public:
|
||||||
int size() const {
|
int size() const {
|
||||||
return _stack.size();
|
return _stack.size();
|
||||||
}
|
}
|
||||||
T operator [](int i) {
|
T operator[](int i) {
|
||||||
return _stack[i];
|
return _stack[i];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue