[Mockpp-commits] mockpp/3party/ministl .cvsignore,NONE,1.1 algo.h,NONE,1.1 algorithm,NONE,1.1 bool.h
Brought to you by:
ewald-arnold
From: Ewald A. <ewa...@us...> - 2005-11-27 17:35:18
|
Update of /cvsroot/mockpp/mockpp/3party/ministl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9405/3party/ministl Added Files: .cvsignore algo.h algorithm bool.h bstring.h defalloc.h function function.h list list.h map map.h ministl.h pair pair.h set set.h simplevec.h string vector vector.h Log Message: import from www.mico.org --- NEW FILE: pair.h --- /* * * Copyright (c) 1994 * Hewlett-Packard Company * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation. Hewlett-Packard Company makes no * representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. * */ #ifndef PAIR_H #define PAIR_H #ifndef __GNUG__ #include <ministl/bool.h> #endif template <class T1, class T2> struct pair { T1 first; T2 second; #if defined(_AIX) && !defined(__GNUG__) // if T? is const xlC goofes about first/second not beeing inited pair() : first (T1()), second (T2()) {} #else pair() {} #endif pair(const T1& a, const T2& b) : first(a), second(b) {} }; template <class T1, class T2> inline bool operator==(const pair<T1, T2>& x, const pair<T1, T2>& y) { return x.first == y.first && x.second == y.second; } template <class T1, class T2> inline bool operator<(const pair<T1, T2>& x, const pair<T1, T2>& y) { return x.first < y.first || (!(y.first < x.first) && x.second < y.second); } template <class T1, class T2> inline pair<T1, T2> make_pair(const T1& x, const T2& y) { return pair<T1, T2>(x, y); } #endif --- NEW FILE: vector.h --- // -*- c++ -*- /* * MICO --- a free CORBA implementation * Copyright (C) 1997-98 Kay Roemer & Arno Puder * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Send comments and/or bug reports to: * mi...@in... */ #ifndef __ministl_vector_h__ #define __ministl_vector_h__ #include <ministl/ministl.h> #ifndef __GNUG__ #include <ministl/bool.h> #endif #include <ministl/defalloc.h> namespace ministl { template<class T> class vector { public: typedef T* iterator; typedef const T* const_iterator; typedef unsigned long size_type; private: size_type _last, _size; T *_buf; public: const_iterator begin () const { return &_buf[0]; } iterator begin () { return &_buf[0]; } const_iterator end () const { return &_buf[_last]; } iterator end () { return &_buf[_last]; } size_type capacity () const { return _size; } size_type size () const { return _last; } private: static T *alloc (size_type n) { return (T *)::operator new ((size_t)(n * sizeof (T))); } static void dealloc (T *buf) { if (buf) ::operator delete (buf); } // overlapping move to the right static void copy_forward (T* d, const T* sstart, const T* send) { d += send - sstart; while (send != sstart) *--d = *--send; } // overlapping move to the left static void copy_backward (T* d, const T* sstart, const T* send) { for ( ; send != sstart; ++d, ++sstart) *d = *sstart; } static void construct (T *d, const T &t) { new (d) T(t); } static void construct (T *d, const T *sstart, const T *send) { for ( ; sstart != send; ++sstart, ++d) construct (d, *sstart); } static void fill (iterator d, size_type n, const T &t) { for (size_type i = 0; i < n; ++i, ++d) construct (d, t); } void reserve (iterator where, size_type n) { if (_last + n <= _size) { if (where+n < end()) { construct (end(), end()-n, end()); copy_forward (where+n, where, end()-n); destroy (where, where+n); } else { construct (where+n, where, end()); destroy (where, end()); } } else { long sz = _last+n; sz = (_size == 0) ? _max_(sz, 5) : _max_(sz, 2*_size); T *nbuf = alloc (sz); if (_buf) { construct (nbuf, begin(), where); construct (nbuf + (where-begin()) + n, where, end()); destroy (begin(), end()); dealloc (_buf); } _buf = nbuf; _size = sz; } } public: void reserve (size_type sz) { if (_size < sz) { sz = (_size == 0) ? _max_(sz, 5) : _max_(sz, 2*_size); T *nbuf = alloc (sz); if (_buf) { construct (nbuf, begin(), end()); destroy (begin(), end()); dealloc (_buf); } _buf = nbuf; _size = sz; } } vector () : _last (0), _size (0), _buf (0) {} vector (size_type n, const T& t = T()) : _last (0), _size (0), _buf (0) { insert (begin(), n, t); } vector (const_iterator first, const_iterator last) : _last (0), _size (0), _buf (0) { insert (begin(), first, last); } vector (const vector<T> &v) : _last (0), _size (0), _buf (0) { reserve (v._last); construct (begin(), v.begin(), v.end()); _last = v._last; } vector<T> &operator= (const vector<T> &v) { if (this != &v) { destroy (begin(), end()); _last = 0; reserve (v._last); construct (begin(), v.begin(), v.end()); _last = v._last; } return *this; } ~vector () { destroy (begin(), end()); dealloc (_buf); } const T &front () const { ministl_assert (size() > 0); return _buf[0]; } T &front () { ministl_assert (size() > 0); return _buf[0]; } const T &back () const { ministl_assert (size() > 0); return _buf[_last-1]; } T &back () { ministl_assert (size() > 0); return _buf[_last-1]; } bool empty () const { return _last == 0; } void clear () { destroy (begin(), end()); _last = 0; } void push_back (const T &t) { reserve (_last+1); construct (end(), t); ++_last; } void pop_back () { ministl_assert (size() > 0); --_last; destroy (end()); } const T &operator[] (size_type idx) const { ministl_assert (idx < size()); return _buf[idx]; } T &operator[] (size_type idx) { ministl_assert (idx < size()); return _buf[idx]; } iterator insert (iterator pos, const T &t) { ministl_assert (pos <= end()); long at = pos - begin(); reserve (pos, 1); pos = begin()+at; construct (pos, t); ++_last; return pos; } iterator insert (iterator pos, const_iterator first, const_iterator last) { ministl_assert (pos <= end()); long n = last - first; long at = pos - begin(); if (n > 0) { reserve (pos, n); pos = begin()+at; construct (pos, first, last); _last += n; } return pos; } iterator insert (iterator pos, size_type n, const T &t) { ministl_assert (pos <= end()); long at = pos - begin(); if (n > 0) { reserve (pos, n); pos = begin()+at; fill (pos, n, t); _last += n; } return pos; } void erase (iterator first, iterator last) { if (last != first) { copy_backward (first, last, end()); destroy (end() - (last-first), end()); _last -= last - first; } } void erase (iterator pos) { if (pos != end()) { copy_backward (pos, pos+1, end()); destroy (end()-1); --_last; } } }; template<class T> bool operator== (const vector<T> &v1, const vector<T> &v2) { if (v1.size() != v2.size()) return false; for (unsigned long i = 0; i < v1.size(); ++i) { if (!(v1[i] == v2[i])) return false; } return true; } template<class T> bool operator< (const vector<T> &v1, const vector<T> &v2) { unsigned long minlast = _min_ (v1.size(), v2.size()); for (unsigned long i = 0; i < minlast; ++i) { if (v1[i] < v2[i]) return true; if (v2[i] < v1[i]) return false; } return v1.size() < v2.size(); } } // namespace ministl #endif --- NEW FILE: set --- /* * MICO --- a free CORBA implementation * Copyright (C) 1997-98 Kay Roemer & Arno Puder * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Send comments and/or bug reports to: * mi...@in... */ #include <ministl/set.h> --- NEW FILE: string --- /* * MICO --- a free CORBA implementation * Copyright (C) 1997-98 Kay Roemer & Arno Puder * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Send comments and/or bug reports to: * mi...@in... */ #include <ministl/bstring.h> --- NEW FILE: algorithm --- /* * MICO --- a free CORBA implementation * Copyright (C) 1997-98 Kay Roemer & Arno Puder * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Send comments and/or bug reports to: * mi...@in... */ #include <ministl/algo.h> --- NEW FILE: set.h --- // -*- c++ -*- /* * MICO --- a free CORBA implementation * Copyright (C) 1997-98 Kay Roemer & Arno Puder * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Send comments and/or bug reports to: * mi...@in... */ #ifndef __ministl_set_h__ #define __ministl_set_h__ #include <ministl/ministl.h> #include <ministl/simplevec.h> #include <ministl/function> #include <ministl/pair> #ifndef __GNUG__ #include <ministl/bool.h> #endif template<class vT, class cT> class set; template<class vT, class cT> class setConstIterator; template<class vT, class cT> class setIterator { friend class set<vT,cT>; friend class setConstIterator<vT,cT>; typedef setIterator<vT,cT> my_type; typedef vT value_type; typedef simplevec<value_type *> rep_type; typedef typename rep_type::iterator repiterator; repiterator n; setIterator (repiterator _n) : n (_n) { } public: setIterator () : n (0) { } bool operator== (const my_type &it) const { return it.n == n; } bool operator!= (const my_type &it) const { return !(it.n == n); } my_type operator++ () { ++n; return *this; } my_type operator++ (int) { my_type tmp = *this; ++n; return tmp; } my_type operator-- () { --n; return *this; } my_type operator-- (int) { my_type tmp = *this; --n; return tmp; } value_type &operator* () { return **n; } }; template<class vT, class cT> class setConstIterator { friend class set<vT,cT>; typedef setConstIterator<vT,cT> my_type; typedef vT value_type; typedef simplevec<value_type *> rep_type; typedef typename rep_type::const_iterator repiterator; repiterator n; setConstIterator (repiterator _n) : n (_n) { } public: setConstIterator () : n (0) { } setConstIterator (const setIterator<vT,cT> &i) : n (i.n) { } bool operator== (const my_type &it) const { return it.n == n; } bool operator!= (const my_type &it) const { return !(it.n == n); } my_type operator++ () { ++n; return *this; } my_type operator++ (int) { my_type tmp = *this; ++n; return tmp; } my_type operator-- () { --n; return *this; } my_type operator-- (int) { my_type tmp = *this; --n; return tmp; } const value_type &operator* () const { return **n; } }; template<class valT, class cmpT> class set { public: typedef valT value_type; typedef unsigned long size_type; typedef simplevec<value_type *> rep_type; typedef setIterator<valT, cmpT> iterator; typedef setConstIterator<valT, cmpT> const_iterator; // XXX typedefs done to work around g++ bug typedef pair<iterator, bool> pair_iterator_bool; private: rep_type _ents; cmpT _comp; public: iterator begin () { return iterator (_ents.begin()); } const_iterator begin () const { return const_iterator (_ents.begin()); } iterator end () { return iterator (_ents.end()); } const_iterator end () const { return const_iterator (_ents.end()); } set (const cmpT &comp = cmpT()) : _comp (comp) { } set (const_iterator first, const_iterator last, const cmpT &comp = cmpT()) : _comp (comp) { insert (first, last); } set (const set<valT, cmpT> &m) : _comp (m._comp) { insert (m.begin(), m.end()); } set<valT, cmpT> &operator= (const set<valT, cmpT> &m) { if (this != &m) { _comp = m._comp; erase (begin(), end()); insert (m.begin(), m.end()); } return *this; } ~set () { erase (begin(), end()); } bool empty () const { return _ents.empty (); } size_type size () const { return _ents.size (); } private: // find the iterator position where k should be inserted ... bool lookup (const value_type &k, iterator &it); public: pair_iterator_bool insert (const value_type &v) { iterator i = end(); if (size() > 0 && lookup (v, i)) return pair_iterator_bool (i, false); i = iterator (_ents.insert (i.n, new value_type (v))); return pair_iterator_bool (i, true); } #if 0 iterator insert (iterator pos, const value_type &v) { } #endif void insert (const_iterator first, const_iterator last) { for ( ; first != last; ++first) insert (*first); } void insert (const value_type *first, const value_type *last) { for ( ; first != last; ++first) insert (*first); } void erase (iterator pos) { if (pos != end()) { delete *(pos.n); _ents.erase (pos.n); } } size_type erase (const value_type &k) { iterator i = find (k); if (i == end()) return 0; erase (i); return 1; } void erase (iterator first, iterator last) { for (iterator i = first; i != last; ++i) delete *(i.n); _ents.erase (first.n, last.n); } void clear () { erase (begin(), end()); } iterator find (const value_type &k) { if (size() > 0) { int l = 0; int r = size()-1; do { int m = (l+r) >> 1; if (_comp (*_ents[m], k)) { l = m+1; } else { // if (k == *_ents[m]) if (!_comp (k, *_ents[m])) return iterator (_ents.begin()+m); r = m-1; } } while (l <= r); } return end(); } const_iterator find (const value_type &k) const { if (size() > 0) { int l = 0; int r = size()-1; do { int m = (l+r) >> 1; if (_comp (*_ents[m], k)) { l = m+1; } else { // if (k == *_ents[m]) if (!_comp (k, *_ents[m])) return const_iterator (_ents.begin()+m); r = m-1; } } while (l <= r); } return end(); } size_type count (const value_type &k) const { return find (k) != end() ? 1 : 0; } }; template<class vT, class cT> inline bool set<vT, cT>::lookup (const vT &k, setIterator<vT,cT> &it) { int l = 0; int r = size(); while (l < r) { int m = (l+r) >> 1; ministl_assert (m < r); if (_comp (*_ents[m], k)) { l = m+1; } else { // if (k == *_ents[m]) { if (!_comp (k, *_ents[m])) { it = setIterator<vT,cT> (_ents.begin()+m); return true; } r = m; } } ministl_assert (l == r); it = setIterator<vT,cT> (_ents.begin()+l); return l < (int)size() && // k == *it !_comp (*it, k) && !_comp (k, *it); } template<class vT, class cT> bool operator== (const set<vT,cT> &v1, const set<vT,cT> &v2) { if (v1.size() != v2.size()) return false; typename set<vT,cT>::const_iterator i1 = v1.begin(); typename set<vT,cT>::const_iterator i2 = v2.begin(); for ( ;i1 != v1.end() && i2 != v2.end(); ++i1, ++i2) { if (!(*i1 == *i2)) return false; } return true; } template<class vT, class cT> bool operator< (const set<vT,cT> &v1, const set<vT,cT> &v2) { long minlast = _min_ (v1.size(), v2.size()); typename set<vT,cT>::const_iterator i1 = v1.begin(); typename set<vT,cT>::const_iterator i2 = v2.begin(); for ( ;i1 != v1.end() && i2 != v2.end(); ++i1, ++i2) { if (*i1 < *i2) return true; if (*i2 < *i1) return false; } return v1.size() < v2.size(); } #endif // __ministl_set_h__ --- NEW FILE: function --- /* * MICO --- a free CORBA implementation * Copyright (C) 1997-98 Kay Roemer & Arno Puder * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Send comments and/or bug reports to: * mi...@in... */ #include <ministl/function.h> --- NEW FILE: list --- /* * MICO --- a free CORBA implementation * Copyright (C) 1997-98 Kay Roemer & Arno Puder * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Send comments and/or bug reports to: * mi...@in... */ #include <ministl/list.h> --- NEW FILE: bstring.h --- /** ** Copyright (c) 1994-1995 Modena Software Inc., ** ** Permission to use, copy, modify, distribute and sell this software ** and its documentation for any purpose is hereby granted without fee, ** provided that the above copyright notice appear in all copies and ** that both that copyright notice and this permission notice appear ** in supporting documentation. Modena Software, Inc. makes no ** representations about the suitability of this software for any ** purpose. It is provided "as is" without express or implied warranty. ** **/ #ifndef __cplusplus #error Must use C++ for BSTRING.H #endif #ifndef __MBSTRING_H #define __MBSTRING_H [...2575 lines suppressed...] typedef basic_string<char> cstring; typedef basic_string<char> string; //typedef basic_string<wchar_t> wstring; /* The following is a workaround for a compiler bug in some versions of the Apogee compiler. This looks pretty weird, and it shouldn't work, but more obvious constructs cause other error messages.---DRM */ #if 0 inline void destroy(string* pointer) { pointer->~basic_string(); } #endif } // namespace ministl #endif --- NEW FILE: list.h --- // -*- c++ -*- /* * MICO --- a free CORBA implementation * Copyright (C) 1997-98 Kay Roemer & Arno Puder * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Send comments and/or bug reports to: * mi...@in... */ #ifndef __ministl_list_h__ #define __ministl_list_h__ #include <ministl/ministl.h> #ifndef __GNUG__ #include <ministl/bool.h> #endif template<class T> class listNode { listNode<T> *_prev, *_next; T _data; public: listNode (const T &data = T(), listNode<T> *next = 0, listNode<T> *prev = 0) : _prev (prev), _next (next), _data (data) { } ~listNode () { ministl_assert (!_next && !_prev); } void remove () { if (_prev) _prev->_next = _next; if (_next) _next->_prev = _prev; _next = _prev = 0; } void insert_after (listNode<T> *ln) { ministl_assert (ln); _next = _prev = 0; if (ln->_next) ln->_next->_prev = this; _next = ln->_next; ln->_next = this; _prev = ln; } void insert_before (listNode<T> *ln) { ministl_assert (ln); _next = _prev = 0; if (ln->_prev) ln->_prev->_next = this; _prev = ln->_prev; ln->_prev = this; _next = ln; } const T &data () const { return _data; } T &data () { return _data; } listNode<T> *next () { return _next; } listNode<T> *prev () { return _prev; } }; template<class T> class list; template<class T> class listConstIterator; template<class T> class listIterator { friend class list<T>; friend class listConstIterator<T>; typedef listNode<T> node; node *n; listIterator (node *_n) : n (_n) { } public: listIterator () : n (0) { } bool operator== (const listIterator<T> &it) const { return it.n == n; } bool operator!= (const listIterator<T> &it) const { return !(it.n == n); } listIterator<T> operator++ () { n = n->next(); ministl_assert (n); return *this; } listIterator<T> operator++ (int) { listIterator<T> tmp = *this; n = n->next(); ministl_assert (n); return tmp; } listIterator<T> operator-- () { n = n->prev(); ministl_assert (n); return *this; } listIterator<T> operator-- (int) { listIterator<T> tmp = *this; n = n->prev(); ministl_assert (n); return tmp; } T &operator* () { return n->data(); } }; template<class T> class listConstIterator { friend class list<T>; typedef listNode<T> node; node *n; listConstIterator (node *_n) : n (_n) { } public: listConstIterator () : n (0) { } listConstIterator (const listIterator<T> &i) : n (i.n) { } bool operator== (const listConstIterator<T> &it) const { return it.n == n; } bool operator!= (const listConstIterator<T> &it) const { return !(it.n == n); } listConstIterator<T> operator++ () { n = n->next(); ministl_assert (n); return *this; } listConstIterator<T> operator++ (int) { listConstIterator<T> tmp = *this; n = n->next(); ministl_assert (n); return tmp; } listConstIterator<T> operator-- () { n = n->prev(); ministl_assert (n); return *this; } listConstIterator<T> operator-- (int) { listConstIterator<T> tmp = *this; n = n->prev(); ministl_assert (n); return tmp; } const T &operator* () const { return n->data(); } }; template<class T> class list { typedef listNode<T> node; public: typedef unsigned long size_type; typedef listIterator<T> iterator; typedef listConstIterator<T> const_iterator; private: node *_begin; node *_end; size_type _length; public: #if 0 void __check () { node *n = _begin; while (n->next()) n = n->next(); assert (n == _end); } #endif iterator begin () { return iterator (_begin); } const_iterator begin () const { return const_iterator (_begin); } iterator end () { return iterator (_end); } const_iterator end () const { return const_iterator (_end); } list () : _length (0) { _begin = _end = new node (); } list (size_type n, const T &t = T()) : _length (0) { _begin = _end = new node (); insert (begin(), n, t); } list (const T *first, const T *last) : _length (0) { _begin = _end = new node (); insert (begin(), first, last); } list (const_iterator first, const_iterator last) : _length (0) { _begin = _end = new node (); insert (begin(), first, last); } typedef list<T> list_T; list (const list_T &list_) : _length (0) { _begin = _end = new node (); insert (begin(), list_.begin(), list_.end()); } list<T> &operator= (const list<T> &list_) { if (this != &list_) { erase (begin(), end()); insert (begin(), list_.begin(), list_.end()); } return *this; } ~list () { erase (begin(), end()); delete _end; } T &front () { return _begin->data(); } const T &front () const { return _begin->data(); } T &back () { ministl_assert (_end->prev()); return _end->prev()->data(); } const T &back () const { ministl_assert (_end->prev()); return _end->prev()->data(); } bool empty () const { return _length == 0; } void clear () { erase (begin(), end()); } size_type size () const { return _length; } void push_front (const T &t) { insert (begin(), t); } void pop_front () { ministl_assert (size() > 0); erase (begin()); } void push_back (const T &t) { insert (end(), t); } void pop_back () { ministl_assert (size() > 0); erase (--end()); } iterator insert (iterator pos, const T &t) { node *n = new node (t); n->insert_before (pos.n); if (pos.n == _begin) _begin = n; ++_length; return iterator (n); } void insert (iterator pos, size_type n, const T &t) { for (size_type i = 0; i < n; ++i) insert (pos, t); } void insert (iterator pos, const T *first, const T *last) { for ( ; first != last; ++first) insert (pos, *first); } void insert (iterator pos, const_iterator first, const_iterator last) { for ( ; first != last; ++first) insert (pos, *first); } void erase (iterator pos) { if (pos != end()) { ministl_assert (pos.n != _end); if (pos.n == _begin) _begin = _begin->next(); pos.n->remove (); delete pos.n; pos.n = 0; --_length; } } void erase (iterator first, iterator last) { iterator next; while (first != last) { next = first; ++next; // XXX first must be incremented before erasing! erase (first); first = next; } } }; template<class T> bool operator== (const list<T> &v1, const list<T> &v2) { if (v1.size() != v2.size()) return false; typename list<T>::const_iterator i1 = v1.begin(); typename list<T>::const_iterator i2 = v2.begin(); for ( ;i1 != v1.end() && i2 != v2.end(); ++i1, ++i2) { if (!(*i1 == *i2)) return false; } return true; } template<class T> bool operator< (const list<T> &v1, const list<T> &v2) { long minlast = _min_ (v1.size(), v2.size()); typename list<T>::const_iterator i1 = v1.begin(); typename list<T>::const_iterator i2 = v2.begin(); for ( ;i1 != v1.end() && i2 != v2.end(); ++i1, ++i2) { if (!(*i1 == *i2)) return *i1 < *i2; } return v1.size() < v2.size(); } #endif // __ministl_list_h__ --- NEW FILE: function.h --- /* * * Copyright (c) 1994 * Hewlett-Packard Company * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation. Hewlett-Packard Company makes no * representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. * */ #ifndef FUNCTION_H #define FUNCTION_H #ifndef __GNUG__ #include <ministl/bool.h> #endif #if 0 template <class T1, class T2> inline bool operator!=(const T1& x, const T2& y) { return !(x == y); } #endif template <class T1, class T2> inline bool operator>(const T1& x, const T2& y) { return y < x; } template <class T1, class T2> inline bool operator<=(const T1& x, const T2& y) { return !(y < x); } template <class T1, class T2> inline bool operator>=(const T1& x, const T2& y) { return !(x < y); } template <class Arg, class Result> struct unary_function { typedef Arg argument_type; typedef Result result_type; }; template <class Arg1, class Arg2, class Result> struct binary_function { typedef Arg1 first_argument_type; typedef Arg2 second_argument_type; typedef Result result_type; }; template <class T> struct plus : binary_function<T, T, T> { T operator()(const T& x, const T& y) const { return x + y; } }; template <class T> struct minus : binary_function<T, T, T> { T operator()(const T& x, const T& y) const { return x - y; } }; template <class T> struct multiplies : binary_function<T, T, T> { T operator()(const T& x, const T& y) const { return x * y; } }; template <class T> struct divides : binary_function<T, T, T> { T operator()(const T& x, const T& y) const { return x / y; } }; template <class T> #ifdef __GNU__ struct modulus { typedef T first_argument_type; typedef T second_argument_type; typedef T result_type; T operator()(const T& x, const T& y) const { return x % y; } }; #else struct modulus : binary_function<T, T, T> { T operator()(const T& x, const T& y) const { return x % y; } }; #endif template <class T> struct negate : unary_function<T, T> { T operator()(const T& x) const { return -x; } }; template <class T> struct equal_to : binary_function<T, T, bool> { bool operator()(const T& x, const T& y) const { return x == y; } }; template <class T> struct not_equal_to : binary_function<T, T, bool> { bool operator()(const T& x, const T& y) const { return x != y; } }; template <class T> struct greater : binary_function<T, T, bool> { bool operator()(const T& x, const T& y) const { return x > y; } }; template <class T> struct less : binary_function<T, T, bool> { bool operator()(const T& x, const T& y) const { return x < y; } }; template <class T> struct greater_equal : binary_function<T, T, bool> { bool operator()(const T& x, const T& y) const { return x >= y; } }; template <class T> struct less_equal : binary_function<T, T, bool> { bool operator()(const T& x, const T& y) const { return x <= y; } }; template <class T> struct logical_and : binary_function<T, T, bool> { bool operator()(const T& x, const T& y) const { return x && y; } }; template <class T> struct logical_or : binary_function<T, T, bool> { bool operator()(const T& x, const T& y) const { return x || y; } }; template <class T> struct logical_not : unary_function<T, bool> { bool operator()(const T& x) const { return !x; } }; template <class Predicate> class unary_negate : public unary_function<typename Predicate::argument_type, bool> { protected: Predicate pred; public: unary_negate(const Predicate& x) : pred(x) {} bool operator()(const typename Predicate::argument_type& x) const { return !pred(x); } }; template <class Predicate> unary_negate<Predicate> not1(const Predicate& pred) { return unary_negate<Predicate>(pred); } template <class Predicate> class binary_negate : public binary_function<typename Predicate::first_argument_type, typename Predicate::second_argument_type, bool> { protected: Predicate pred; public: binary_negate(const Predicate& x) : pred(x) {} bool operator()(const typename Predicate::first_argument_type& x, const typename Predicate::second_argument_type& y) const { return !pred(x, y); } }; template <class Predicate> binary_negate<Predicate> not2(const Predicate& pred) { return binary_negate<Predicate>(pred); } template <class Operation> class binder1st : public unary_function<typename Operation::second_argument_type, typename Operation::result_type> { protected: Operation op; typename Operation::first_argument_type value; public: binder1st(const Operation& x, const typename Operation::first_argument_type& y) : op(x), value(y) {} typename Operation::result_type operator()(const typename Operation::argument_type& x) const { return op(value, x); } }; template <class Operation, class T> binder1st<Operation> bind1st(const Operation& op, const T& x) { return binder1st<Operation>(op, Operation::first_argument_type(x)); } template <class Operation> class binder2nd : public unary_function<typename Operation::first_argument_type, typename Operation::result_type> { protected: Operation op; typename Operation::second_argument_type value; public: binder2nd(const Operation& x, const typename Operation::second_argument_type& y) : op(x), value(y) {} typename Operation::result_type operator()(const typename Operation::argument_type& x) const { return op(x, value); } }; template <class Operation, class T> binder2nd<Operation> bind2nd(const Operation& op, const T& x) { return binder2nd<Operation>(op, Operation::second_argument_type(x)); } template <class Operation1, class Operation2> class unary_compose : public unary_function<typename Operation2::argument_type, typename Operation1::result_type> { protected: Operation1 op1; Operation2 op2; public: unary_compose(const Operation1& x, const Operation2& y) : op1(x), op2(y) {} typename Operation1::result_type operator()(const typename Operation2::argument_type& x) const { return op1(op2(x)); } }; template <class Operation1, class Operation2> unary_compose<Operation1, Operation2> compose1(const Operation1& op1, const Operation2& op2) { return unary_compose<Operation1, Operation2>(op1, op2); } template <class Operation1, class Operation2, class Operation3> class binary_compose : public unary_function<typename Operation2::argument_type, typename Operation1::result_type> { protected: Operation1 op1; Operation2 op2; Operation3 op3; public: binary_compose(const Operation1& x, const Operation2& y, const Operation3& z) : op1(x), op2(y), op3(z) { } typename Operation1::result_type operator()(const typename Operation2::argument_type& x) const { return op1(op2(x), op3(x)); } }; template <class Operation1, class Operation2, class Operation3> binary_compose<Operation1, Operation2, Operation3> compose2(const Operation1& op1, const Operation2& op2, const Operation3& op3) { return binary_compose<Operation1, Operation2, Operation3>(op1, op2, op3); } template <class Arg, class Result> class pointer_to_unary_function : public unary_function<Arg, Result> { protected: Result (*ptr)(Arg); public: pointer_to_unary_function() {} pointer_to_unary_function(Result (*x)(Arg)) : ptr(x) {} Result operator()(Arg x) const { return ptr(x); } }; template <class Arg, class Result> pointer_to_unary_function<Arg, Result> ptr_fun(Result (*x)(Arg)) { return pointer_to_unary_function<Arg, Result>(x); } template <class Arg1, class Arg2, class Result> class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result> { protected: Result (*ptr)(Arg1, Arg2); public: pointer_to_binary_function() {} pointer_to_binary_function(Result (*x)(Arg1, Arg2)) : ptr(x) {} Result operator()(Arg1 x, Arg2 y) const { return ptr(x, y); } }; template <class Arg1, class Arg2, class Result> pointer_to_binary_function<Arg1, Arg2, Result> ptr_fun(Result (*x)(Arg1, Arg2)) { return pointer_to_binary_function<Arg1, Arg2, Result>(x); } #endif --- NEW FILE: bool.h --- // Defining TRUE and FALSE is usually a Bad Idea, // because you will probably be inconsistent with anyone // else who had the same clever idea. // Therefore: DON'T USE THIS FILE. #ifndef _bool_h #define _bool_h 1 // make sure a config.h has been included before #if defined(__GNUG__) || defined(HAVE_BOOL_TYPE) #undef TRUE #undef FALSE #define TRUE true #define FALSE false #else class bool { int rep; public: bool () : rep(0) {} bool (int i) : rep(!!i) {} bool (const bool &b) : rep(b.rep) {} bool &operator= (const bool b) { rep = b.rep; return *this; } bool &operator= (int i) { rep = !!i; return *this; } operator int () { return rep; } operator int() const { return rep; } }; #undef true #undef false #define true (bool(1)) #define false (bool(0)) #endif #endif --- NEW FILE: map --- /* * MICO --- a free CORBA implementation * Copyright (C) 1997-98 Kay Roemer & Arno Puder * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Send comments and/or bug reports to: * mi...@in... */ #include <ministl/map.h> --- NEW FILE: vector --- /* * MICO --- a free CORBA implementation * Copyright (C) 1997-98 Kay Roemer & Arno Puder * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Send comments and/or bug reports to: * mi...@in... */ #include <ministl/vector.h> --- NEW FILE: defalloc.h --- /* * * Copyright (c) 1994 * Hewlett-Packard Company * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation. Hewlett-Packard Company makes no * representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. * */ #ifndef MINISTL_DEFALLOC_H #define MINISTL_DEFALLOC_H template <class T> inline void destroy(T* pointer) { pointer->~T(); } template<> inline void destroy(char*) {} template<> inline void destroy(unsigned char*) {} template<> inline void destroy(short*) {} template<> inline void destroy(unsigned short*) {} template<> inline void destroy(int*) {} template<> inline void destroy(unsigned int*) {} template<> inline void destroy(long*) {} template<> inline void destroy(unsigned long*) {} template<> inline void destroy(float*) {} template<> inline void destroy(double*) {} template<> inline void destroy(char**) {} template<> inline void destroy(unsigned char**) {} template<> inline void destroy(short**) {} template<> inline void destroy(unsigned short**) {} template<> inline void destroy(int**) {} template<> inline void destroy(unsigned int**) {} template<> inline void destroy(long**) {} template<> inline void destroy(unsigned long**) {} template<> inline void destroy(float**) {} template<> inline void destroy(double**) {} template <class T> inline void destroy(T* beg, T* end) { for ( ; beg != end; ++beg) beg->~T(); } template<> inline void destroy(char*, char*) {} template<> inline void destroy(unsigned char*, unsigned char*) {} template<> inline void destroy(short*, short*) {} template<> inline void destroy(unsigned short*, unsigned short*) {} template<> inline void destroy(int*, int*) {} template<> inline void destroy(unsigned int*, unsigned int*) {} template<> inline void destroy(long*, long*) {} template<> inline void destroy(unsigned long*, unsigned long*) {} template<> inline void destroy(float*, float*) {} template<> inline void destroy(double*, double*) {} template<> inline void destroy(char**, char**) {} template<> inline void destroy(unsigned char**, unsigned char**) {} template<> inline void destroy(short**, short**) {} template<> inline void destroy(unsigned short**, unsigned short**) {} template<> inline void destroy(int**, int**) {} template<> inline void destroy(unsigned int**, unsigned int**) {} template<> inline void destroy(long**, long**) {} template<> inline void destroy(unsigned long**, unsigned long**) {} template<> inline void destroy(float**, float**) {} template<> inline void destroy(double**, double**) {} #if defined (__GNUG__) //inline void *operator new(size_t, void *place) { return place; } //inline void *operator new[](size_t, void *place) { return place; } #else #include <new.h> #endif #endif --- NEW FILE: map.h --- // -*- c++ -*- /* * MICO --- a free CORBA implementation * Copyright (C) 1997-98 Kay Roemer & Arno Puder * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Send comments and/or bug reports to: * mi...@in... */ #ifndef __ministl_map_h__ #define __ministl_map_h__ #include <ministl/ministl.h> #include <ministl/simplevec.h> #include <ministl/function> #include <ministl/pair> #ifndef __GNUG__ #include <ministl/bool.h> #endif template<class kT, class vT, class cT> class map; template<class kT, class vT, class cT> class mapConstIterator; template<class kT, class vT, class cT> class mapIterator { friend class map<kT,vT,cT>; friend class mapConstIterator<kT,vT,cT>; typedef mapIterator<kT,vT,cT> my_type; typedef pair<const kT, vT> value_type; typedef simplevec<value_type *> rep_type; typedef typename rep_type::iterator repiterator; repiterator n; mapIterator (repiterator _n) : n (_n) { } public: mapIterator () : n (0) { } bool operator== (const my_type &it) const { return it.n == n; } bool operator!= (const my_type &it) const { return !(it.n == n); } my_type operator++ () { ++n; return *this; } my_type operator++ (int) { my_type tmp = *this; ++n; return tmp; } my_type operator-- () { --n; return *this; } my_type operator-- (int) { my_type tmp = *this; --n; return tmp; } value_type &operator* () { return **n; } }; template<class kT, class vT, class cT> class mapConstIterator { friend class map<kT,vT,cT>; typedef mapConstIterator<kT,vT,cT> my_type; typedef pair<const kT, vT> value_type; typedef simplevec<value_type *> rep_type; typedef typename rep_type::const_iterator repiterator; repiterator n; mapConstIterator (repiterator _n) : n (_n) { } public: mapConstIterator () : n (0) { } mapConstIterator (const mapIterator<kT,vT,cT> &i) : n (i.n) { } bool operator== (const my_type &it) const { return it.n == n; } bool operator!= (const my_type &it) const { return !(it.n == n); } my_type operator++ () { ++n; return *this; } my_type operator++ (int) { my_type tmp = *this; ++n; return tmp; } my_type operator-- () { --n; return *this; } my_type operator-- (int) { my_type tmp = *this; --n; return tmp; } const value_type &operator* () const { return **n; } }; template<class keyT, class valT, class cmpT> class map { public: typedef keyT key_type; typedef pair<const keyT, valT> value_type; typedef unsigned long size_type; typedef simplevec<value_type *> rep_type; typedef mapIterator<keyT, valT, cmpT> iterator; typedef mapConstIterator<keyT, valT, cmpT> const_iterator; // XXX typedefs done to work around g++ bug typedef pair<iterator, bool> pair_iterator_bool; private: rep_type _ents; cmpT _comp; public: iterator begin () { return iterator (_ents.begin()); } const_iterator begin () const { return const_iterator (_ents.begin()); } iterator end () { return iterator (_ents.end()); } const_iterator end () const { return const_iterator (_ents.end()); } map (const cmpT &comp = cmpT()) : _comp (comp) { } map (const_iterator first, const_iterator last, const cmpT &comp = cmpT()) : _comp (comp) { insert (first, last); } map (const map<keyT, valT, cmpT> &m) : _comp (m._comp) { insert (m.begin(), m.end()); } map<keyT, valT, cmpT> &operator= (const map<keyT, valT, cmpT> &m) { if (this != &m) { _comp = m._comp; erase (begin(), end()); insert (m.begin(), m.end()); } return *this; } ~map () { erase (begin(), end()); } bool empty () const { return _ents.empty (); } size_type size () const { return _ents.size (); } private: // find the iterator position where k should be inserted ... bool lookup (const key_type &k, iterator &it); public: pair_iterator_bool insert (const value_type &v) { iterator i = end(); if (size() > 0 && lookup (v.first, i)) return pair_iterator_bool (i, false); i = iterator (_ents.insert (i.n, new value_type (v))); return pair_iterator_bool (i, true); } #if 0 iterator insert (iterator pos, const value_type &v) { } #endif void insert (const_iterator first, const_iterator last) { for ( ; first != last; ++first) insert (*first); } void insert (const value_type *first, const value_type *last) { for ( ; first != last; ++first) insert (*first); } void erase (iterator pos) { if (pos != end()) { delete *(pos.n); _ents.erase (pos.n); } } size_type erase (const key_type &k) { iterator i = find (k); if (i == end()) return 0; erase (i); return 1; } void erase (iterator first, iterator last) { for (iterator i = first; i != last; ++i) delete *(i.n); _ents.erase (first.n, last.n); } void clear () { erase (begin(), end()); } iterator find (const key_type &k) { if (size() > 0) { int l = 0; int r = size()-1; do { int m = (l+r) >> 1; if (_comp (_ents[m]->first, k)) { l = m+1; } else { // if (k == _ents[m]->first) if (!_comp (k, _ents[m]->first)) return iterator (_ents.begin()+m); r = m-1; } } while (l <= r); } return end(); } const_iterator find (const key_type &k) const { if (size() > 0) { int l = 0; int r = size()-1; do { int m = (l+r) >> 1; if (_comp (_ents[m]->first, k)) { l = m+1; } else { // if (k == _ents[m]->first) if (!_comp (k, _ents[m]->first)) return const_iterator (_ents.begin()+m); r = m-1; } } while (l <= r); } return end(); } size_type count (const key_type &k) const { return find (k) != end() ? 1 : 0; } valT &operator[] (const key_type &k) { iterator i = insert(value_type (k, valT())).first; return (*i).second; } }; template<class kT, class vT, class cT> inline bool map<kT,vT,cT>::lookup (const kT &k, mapIterator<kT,vT,cT> &it) { int l = 0; int r = size(); while (l < r) { int m = (l+r) >> 1; ministl_assert (m < r); if (_comp (_ents[m]->first, k)) { l = m+1; } else { // if (k == _ents[m]->first) { if (!_comp (k, _ents[m]->first)) { it = mapIterator<kT,vT,cT> (_ents.begin()+m); return true; } r = m; } } ministl_assert (l == r); it = mapIterator<kT,vT,cT> (_ents.begin()+l); return l < (int)size() && // (*it).first == k; !_comp ((*it).first, k) && !_comp (k, (*it).first); } template<class kT, class vT, class cT> bool operator== (const map<kT,vT,cT> &v1, const map<kT,vT,cT> &v2) { if (v1.size() != v2.size()) return false; typename map<kT,vT,cT>::const_iterator i1 = v1.begin(); typename map<kT,vT,cT>::const_iterator i2 = v2.begin(); for ( ;i1 != v1.end() && i2 != v2.end(); ++i1, ++i2) { if (!(*i1 == *i2)) return false; } return true; } template<class kT, class vT, class cT> bool operator< (const map<kT,vT,cT> &v1, const map<kT,vT,cT> &v2) { long minlast = _min_ (v1.size(), v2.size()); typename map<kT,vT,cT>::const_iterator i1 = v1.begin(); typename map<kT,vT,cT>::const_iterator i2 = v2.begin(); for ( ;i1 != v1.end() && i2 != v2.end(); ++i1, ++i2) { if (*i1 < *i2) return true; if (*i2 < *i1) return false; } return v1.size() < v2.size(); } #endif // __ministl_map_h__ --- NEW FILE: algo.h --- /* * * Copyright (c) 1994 * Hewlett-Packard Company * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation. Hewlett-Packard Company makes no * representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. * */ #ifndef ALGO_H #define ALGO_H #include <stdlib.h> #ifndef __GNUG__ #include <ministl/bool.h> #endif #include <ministl/pair> template <class InputIterator, class Function> Function for_each(InputIterator first, InputIterator last, Function f) { while (first != last) f(*first++); return f; } template <class InputIterator, class T> InputIterator find(InputIterator first, InputIterator last, const T& value) { while (first != last && *first != value) ++first; return first; } template <class InputIterator, class Predicate> InputIterator find_if(InputIterator first, InputIterator last, Predicate pred) { while (first != last && !pred(*first)) ++first; return first; } template <class ForwardIterator> ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last) { if (first == last) return last; ForwardIterator next = first; while(++next != last) { if (*first == *next) return first; first = next; } return last; } template <class ForwardIterator, class BinaryPredicate> ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate binary_pred) { if (first == last) return last; ForwardIterator next = first; while(++next != last) { if (binary_pred(*first, *next)) return first; first = next; } return last; } template <class InputIterator, class T, class Size> void count(InputIterator first, InputIterator last, const T& value, Size& n) { while (first != last) if (*first++ == value) ++n; } template <class InputIterator, class Predicate, class Size> void count_if(InputIterator first, InputIterator last, Predicate pred, Size& n) { while (first != last) if (pred(*first++)) ++n; } #endif --- NEW FILE: pair --- /* * MICO --- a free CORBA implementation * Copyright (C) 1997-98 Kay Roemer & Arno Puder * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Send comments and/or bug reports to: * mi...@in... */ #include <ministl/pair.h> --- NEW FILE: simplevec.h --- // -*- c++ -*- /* * MICO --- a free CORBA implementation * Copyright (C) 1997-98 Kay Roemer & Arno Puder * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Send comments and/or bug reports to: * mi...@in... */ #ifndef __ministl_simplevec_h__ #define __ministl_simplevec_h__ #include <ministl/ministl.h> #ifndef __GNUG__ #include <ministl/bool.h> #endif #include <ministl/defalloc.h> template<class T> class simplevec { public: typedef T* iterator; typedef const T* const_iterator; typedef unsigned long size_type; private: size_type _last, _size; T *_buf; public: const_iterator begin () const { return &_buf[0]; } iterator begin () { return &_buf[0]; } const_iterator end () const { return &_buf[_last]; } iterator end () { return &_buf[_last]; } size_type capacity () const { return _size; } size_type size () const { return _last; } private: static T *alloc (size_type n) { return (T *)::operator new ((size_t)(n * sizeof (T))); } static void dealloc (T *buf) { if (buf) ::operator delete (buf); } void reserve (iterator where, size_type n) { if (_last + n <= _size) { memmove (where+n, where, (end()-where)*sizeof(T)); } else { long sz = _last+n; sz = (_size == 0) ? _max_(sz, 5) : _max_(sz, 2*_size); T *nbuf = alloc (sz); if (_buf) { memcpy (nbuf, begin(), (where-begin())*sizeof(T)); memcpy (nbuf + (where-begin()) + n, where, (end()-where)*sizeof(T)); dealloc (_buf); } _buf = nbuf; _size = sz; } } public: void reserve (size_type sz) { if (_size < sz) { sz = (_size == 0) ? _max_(sz, 5)... [truncated message content] |