[Mockpp-commits] mockpp/3party/ministl Makefile.am,NONE,1.1 basic_string.h,NONE,1.1 functional,NONE,
                
                Brought to you by:
                
                    ewald-arnold
                    
                
            
            
        
        
        
    | 
      
      
      From: Ewald A. <ewa...@us...> - 2005-11-29 23:18:15
      
     | 
| Update of /cvsroot/mockpp/mockpp/3party/ministl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24832/3party/ministl Modified Files: algo.h algorithm bool.h defalloc.h function.h list list.h map map.h ministl.h pair pair.h set set.h simplevec.h string vector vector.h Added Files: Makefile.am basic_string.h functional Removed Files: bstring.h function Log Message: adopted to mockpp Index: function.h =================================================================== RCS file: /cvsroot/mockpp/mockpp/3party/ministl/function.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- function.h 27 Nov 2005 17:35:11 -0000 1.1 +++ function.h 29 Nov 2005 23:18:05 -0000 1.2 @@ -1,285 +1,25 @@ /* + * MICO --- a free CORBA implementation + * Copyright (C) 1997-98 Kay Roemer & Arno Puder * - * Copyright (c) 1994 - * Hewlett-Packard Company + * Copyright (C) 2005 Ewald Arnold mockpp at ewald-arnold dot de * - * 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. + * 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 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 +#include <ministl/function.h> --- function DELETED --- Index: set =================================================================== RCS file: /cvsroot/mockpp/mockpp/3party/ministl/set,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- set 27 Nov 2005 17:35:11 -0000 1.1 +++ set 29 Nov 2005 23:18:05 -0000 1.2 @@ -1,7 +1,10 @@ +// -*- c++ -*- /* * MICO --- a free CORBA implementation * Copyright (C) 1997-98 Kay Roemer & Arno Puder * + * Copyright (C) 2005 Ewald Arnold mockpp at ewald-arnold dot de + * * 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 @@ -20,4 +23,374 @@ * mi...@in... */ -#include <ministl/set.h> +#ifndef __ministl_set_h__ +#define __ministl_set_h__ + +#include <ministl/ministl.h> +#include <ministl/simplevec.h> +#include <ministl/functional> +#include <ministl/pair> +#ifndef __GNUG__ +#include <ministl/bool.h> +#endif + +namespace ministl +{ + + +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(); + } + + +} // namespace ministl + + +#endif // __ministl_set_h__ --- NEW FILE: functional --- /* * Copyright (C) 2005 Ewald Arnold mockpp at ewald-arnold dot de * * 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_FUNCTIONAL_H #define MINISTL_FUNCTIONAL_H //#include <ministl/bool.h> namespace ministl { #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); } } // namespace ministl #endif --- NEW FILE: basic_string.h --- /* * MICO --- a free CORBA implementation * Copyright (C) 1997-98 Kay Roemer & Arno Puder * * Copyright (C) 2005 Ewald Arnold mockpp at ewald-arnold dot de * * 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/string> using ministl::string; using ministl::cstring; using ministl::wstring; Index: simplevec.h =================================================================== RCS file: /cvsroot/mockpp/mockpp/3party/ministl/simplevec.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- simplevec.h 27 Nov 2005 17:35:11 -0000 1.1 +++ simplevec.h 29 Nov 2005 23:18:05 -0000 1.2 @@ -3,6 +3,8 @@ * MICO --- a free CORBA implementation * Copyright (C) 1997-98 Kay Roemer & Arno Puder * + * Copyright (C) 2005 Ewald Arnold mockpp at ewald-arnold dot de + * * 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 @@ -25,246 +27,266 @@ #define __ministl_simplevec_h__ #include <ministl/ministl.h> -#ifndef __GNUG__ -#include <ministl/bool.h> -#endif + +//#include <ministl/bool.h> + #include <ministl/defalloc.h> +namespace ministl +{ + + template<class T> -class simplevec { -public: +class simplevec +{ + public: typedef T* iterator; typedef const T* const_iterator; typedef unsigned long size_type; -private: + private: size_type _last, _size; T *_buf; -public: + public: const_iterator begin () const { - return &_buf[0]; + return &_buf[0]; } iterator begin () { - return &_buf[0]; + return &_buf[0]; } const_iterator end () const { - return &_buf[_last]; + return &_buf[_last]; } iterator end () { - return &_buf[_last]; + return &_buf[_last]; } size_type capacity () const { - return _size; + return _size; } size_type size () const { - return _last; + return _last; } -private: + private: static T *alloc (size_type n) { - return (T *)::operator new ((size_t)(n * sizeof (T))); + return (T *)::operator new ((size_t)(n * sizeof (T))); } static void dealloc (T *buf) { - if (buf) - ::operator delete (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; - } + 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: + 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) { - memcpy (nbuf, begin(), size()*sizeof(T)); - dealloc (_buf); - } - _buf = nbuf; - _size = sz; - } + if (_size < sz) + { + sz = (_size == 0) ? _max_(sz, 5) : _max_(sz, 2*_size); + T *nbuf = alloc (sz); + if (_buf) + { + memcpy (nbuf, begin(), size()*sizeof(T)); + dealloc (_buf); + } + _buf = nbuf; + _size = sz; + } } simplevec () - : _last (0), _size (0), _buf (0) - { - } + : _last (0), _size (0), _buf (0) + {} simplevec (size_type n, const T& t = T()) - : _last (0), _size (0), _buf (0) + : _last (0), _size (0), _buf (0) { - insert (begin(), n, t); + insert (begin(), n, t); } simplevec (const_iterator first, const_iterator last) - : _last (0), _size (0), _buf (0) + : _last (0), _size (0), _buf (0) { - insert (begin(), first, last); + insert (begin(), first, last); } simplevec (const simplevec<T> &v) - : _last (0), _size (0), _buf (0) + : _last (0), _size (0), _buf (0) { - reserve (v._last); - memcpy (_buf, v.begin(), v.size()*sizeof(T)); - _last = v._last; + reserve (v._last); + memcpy (_buf, v.begin(), v.size()*sizeof(T)); + _last = v._last; } simplevec<T> &operator= (const simplevec<T> &v) { - if (this != &v) { - _last = 0; - reserve (v._last); - memcpy (_buf, v.begin(), v.size()*sizeof(T)); - _last = v._last; - } - return *this; + if (this != &v) + { + _last = 0; + reserve (v._last); + memcpy (_buf, v.begin(), v.size()*sizeof(T)); + _last = v._last; + } + return *this; } ~simplevec () { - dealloc (_buf); + dealloc (_buf); } const T &front () const { - //ministl_assert (size() > 0); - return _buf[0]; + //ministl_assert (size() > 0); + return _buf[0]; } T &front () { - //ministl_assert (size() > 0); - return _buf[0]; + //ministl_assert (size() > 0); + return _buf[0]; } const T &back () const { - //ministl_assert (size() > 0); - return _buf[_last-1]; + //ministl_assert (size() > 0); + return _buf[_last-1]; } T &back () { - //ministl_assert (size() > 0); - return _buf[_last-1]; + //ministl_assert (size() > 0); + return _buf[_last-1]; } bool empty () const { - return _last == 0; + return _last == 0; } void clear () { - _last = 0; + _last = 0; } void push_back (const T &t) { - reserve (_last+1); - *end() = t; - ++_last; + reserve (_last+1); + *end() = t; + ++_last; } void pop_back () { - //ministl_assert (size() > 0); - --_last; + //ministl_assert (size() > 0); + --_last; } const T &operator[] (size_type idx) const { - //ministl_assert (idx < size()); - return _buf[idx]; + //ministl_assert (idx < size()); + return _buf[idx]; } T &operator[] (size_type idx) { - //ministl_assert (idx < size()); - return _buf[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; - *pos = t; - ++_last; - return pos; + //ministl_assert (pos <= end()); + long at = pos - begin(); + reserve (pos, 1); + pos = begin()+at; + *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; - memcpy (pos, first, (last-first)*sizeof(T)); - _last += n; - } - return pos; + //ministl_assert (pos <= end()); + long n = last - first; + long at = pos - begin(); + if (n > 0) + { + reserve (pos, n); + pos = begin()+at; + memcpy (pos, first, (last-first)*sizeof(T)); + _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; - for (int i = 0; i < n; ++i) - pos[i] = t; - _last += n; - } - return pos; + //ministl_assert (pos <= end()); + long at = pos - begin(); + if (n > 0) + { + reserve (pos, n); + pos = begin()+at; + for (int i = 0; i < n; ++i) + pos[i] = t; + _last += n; + } + return pos; } void erase (iterator first, iterator last) { - if (last != first) { - memmove (first, last, (end()-last)*sizeof(T)); - _last -= last - first; - } + if (last != first) + { + memmove (first, last, (end()-last)*sizeof(T)); + _last -= last - first; + } } void erase (iterator pos) { - if (pos != end()) { - memmove (pos, pos+1, (end()-(pos+1))*sizeof(T)); - --_last; - } + if (pos != end()) + { + memmove (pos, pos+1, (end()-(pos+1))*sizeof(T)); + --_last; + } } }; template<class T> bool operator== (const simplevec<T> &v1, const simplevec<T> &v2) { - if (v1.size() != v2.size()) - return false; - return !v1.size() || !memcmp (&v1[0], &v2[0], v1.size()*sizeof(T)); + if (v1.size() != v2.size()) + return false; + return !v1.size() || !memcmp (&v1[0], &v2[0], v1.size()*sizeof(T)); } template<class T> bool operator< (const simplevec<T> &v1, const simplevec<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(); + 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 Index: algo.h =================================================================== RCS file: /cvsroot/mockpp/mockpp/3party/ministl/algo.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- algo.h 27 Nov 2005 17:35:11 -0000 1.1 +++ algo.h 29 Nov 2005 23:18:05 -0000 1.2 @@ -1,82 +1,26 @@ /* + * MICO --- a free CORBA implementation + * Copyright (C) 1997-98 Kay Roemer & Arno Puder * - * Copyright (c) 1994 - * Hewlett-Packard Company + * Copyright (C) 2005 Ewald Arnold mockpp at ewald-arnold dot de * - * 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. + * 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 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 - +#include <ministl/algo> +using namespace ministl; --- NEW FILE: Makefile.am --- SUBDIRS = tests CLEANFILES = *.~* *.~~* *~ # EXTRA_DIST = Index: ministl.h =================================================================== RCS file: /cvsroot/mockpp/mockpp/3party/ministl/ministl.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ministl.h 27 Nov 2005 17:35:11 -0000 1.1 +++ ministl.h 29 Nov 2005 23:18:05 -0000 1.2 @@ -3,6 +3,8 @@ * MICO --- a free CORBA implementation * Copyright (C) 1997-98 Kay Roemer & Arno Puder * + * Copyright (C) 2005 Ewald Arnold mockpp at ewald-arnold dot de + * * 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 @@ -35,14 +37,23 @@ #define ministl_assert(exp) assert(exp) #endif + +namespace ministl +{ + + static inline long _min_ (long x, long y) { - return x < y ? x : y; + return x < y ? x : y; } static inline long _max_ (long x, long y) { - return x > y ? x : y; + return x > y ? x : y; } + +} // namespace ministl + + #endif // __ministl_ministl_h__ --- bstring.h DELETED --- Index: list.h =================================================================== RCS file: /cvsroot/mockpp/mockpp/3party/ministl/list.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- list.h 27 Nov 2005 17:35:11 -0000 1.1 +++ list.h 29 Nov 2005 23:18:05 -0000 1.2 @@ -1,8 +1,9 @@ -// -*- c++ -*- /* * MICO --- a free CORBA implementation * Copyright (C) 1997-98 Kay Roemer & Arno Puder * + * Copyright (C) 2005 Ewald Arnold mockpp at ewald-arnold dot de + * * 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 @@ -21,392 +22,5 @@ * 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__ +#include <ministl/list> +using ministl::list; Index: vector.h =================================================================== RCS file: /cvsroot/mockpp/mockpp/3party/ministl/vector.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- vector.h 27 Nov 2005 17:35:11 -0000 1.1 +++ vector.h 29 Nov 2005 23:18:05 -0000 1.2 @@ -1,8 +1,9 @@ -// -*- c++ -*- /* * MICO --- a free CORBA implementation * Copyright (C) 1997-98 Kay Roemer & Arno Puder * + * Copyright (C) 2005 Ewald Arnold mockpp at ewald-arnold dot de + * * 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 @@ -21,324 +22,5 @@ * 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 - +#include <ministl/vector> +using ministl::vector; Index: defalloc.h =================================================================== RCS file: /cvsroot/mockpp/mockpp/3party/ministl/defalloc.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- defalloc.h 27 Nov 2005 17:35:11 -0000 1.1 +++ defalloc.h 29 Nov 2005 23:18:05 -0000 1.2 @@ -1,5 +1,5 @@ /* - * +* Copyright (C) 2005 Ewald Arnold mockpp at ewald-arnold dot de * * Copyright (c) 1994 * Hewlett-Packard Company * @@ -16,11 +16,16 @@ #ifndef MINISTL_DEFALLOC_H #define MINISTL_DEFALLOC_H +#include <new> + +namespace ministl +{ + template <class T> inline void destroy(T* pointer) { - pointer->~T(); + pointer->~T(); } template<> inline void destroy(char*) {} @@ -48,8 +53,8 @@ template <c... [truncated message content] |