diff --git a/dlls/aghl/multi_gamerules.h b/dlls/aghl/multi_gamerules.h new file mode 100644 index 00000000..d3544b14 --- /dev/null +++ b/dlls/aghl/multi_gamerules.h @@ -0,0 +1,142 @@ +/*** +* +* Copyright (c) 1999, 2000 Valve LLC. All rights reserved. +* +* This product contains software technology licensed from Id +* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. +* All Rights Reserved. +* +* Use, distribution, and modification of this source code and/or resulting +* object code is restricted to non-commercial enhancements to products from +* Valve LLC. All other use, distribution, or modification is prohibited +* without written permission from Valve LLC. +* +****/ +// +// multi_gamerules.h +// + +//========================================================= +// CHalfLifeMultiplay - rules for the basic half life multiplayer +// competition +//========================================================= +//++ BulliT +#if !defined(_MULTIPLAY_H_) +#define _MULTIPLAY_H_ +#include "aggamerules.h" +//-- Martin Webrant + + +//========================================================= +// CHalfLifeMultiplay - rules for the basic half life multiplayer +// competition +//========================================================= +//++ BulliT +class CHalfLifeMultiplay : public AgGameRules +//class CHalfLifeMultiplay : public CGameRules +//-- Martin Webrant +{ +public: + CHalfLifeMultiplay(); + +// GR_Think + virtual void Think( void ); + virtual void RefreshSkillData( void ); + virtual BOOL IsAllowedToSpawn( CBaseEntity *pEntity ); + virtual BOOL FAllowFlashlight( void ); + + virtual BOOL FShouldSwitchWeapon( CBasePlayer *pPlayer, CBasePlayerItem *pWeapon ); + virtual BOOL GetNextBestWeapon( CBasePlayer *pPlayer, CBasePlayerItem *pCurrentWeapon ); + +// Functions to verify the single/multiplayer status of a game + virtual BOOL IsMultiplayer( void ); + virtual BOOL IsDeathmatch( void ); + virtual BOOL IsCoOp( void ); + +// Client connection/disconnection + // If ClientConnected returns FALSE, the connection is rejected and the user is provided the reason specified in + // svRejectReason + // Only the client's name and remote address are provided to the dll for verification. + virtual BOOL ClientConnected( edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ] ); + virtual void InitHUD( CBasePlayer *pl ); // the client dll is ready for updating + virtual void ClientDisconnected( edict_t *pClient ); + virtual void UpdateGameMode( CBasePlayer *pPlayer ); // the client needs to be informed of the current game mode + +// Client damage rules + virtual float FlPlayerFallDamage( CBasePlayer *pPlayer ); + virtual BOOL FPlayerCanTakeDamage( CBasePlayer *pPlayer, CBaseEntity *pAttacker ); + +// Client spawn/respawn control + virtual void PlayerSpawn( CBasePlayer *pPlayer ); + virtual void PlayerThink( CBasePlayer *pPlayer ); + virtual BOOL FPlayerCanRespawn( CBasePlayer *pPlayer ); + virtual float FlPlayerSpawnTime( CBasePlayer *pPlayer ); + virtual edict_t *GetPlayerSpawnSpot( CBasePlayer *pPlayer ); + + virtual BOOL AllowAutoTargetCrosshair( void ); + virtual BOOL ClientCommand( CBasePlayer *pPlayer, const char *pcmd ); + +// Client kills/scoring + virtual int IPointsForKill( CBasePlayer *pAttacker, CBasePlayer *pKilled ); + virtual void PlayerKilled( CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor ); + virtual void DeathNotice( CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor ); + +// Weapon retrieval + virtual void PlayerGotWeapon( CBasePlayer *pPlayer, CBasePlayerItem *pWeapon ); + virtual BOOL CanHavePlayerItem( CBasePlayer *pPlayer, CBasePlayerItem *pWeapon );// The player is touching an CBasePlayerItem, do I give it to him? + +// Weapon spawn/respawn control + virtual int WeaponShouldRespawn( CBasePlayerItem *pWeapon ); + virtual float FlWeaponRespawnTime( CBasePlayerItem *pWeapon ); + virtual float FlWeaponTryRespawn( CBasePlayerItem *pWeapon ); + virtual Vector VecWeaponRespawnSpot( CBasePlayerItem *pWeapon ); + +// Item retrieval + virtual BOOL CanHaveItem( CBasePlayer *pPlayer, CItem *pItem ); + virtual void PlayerGotItem( CBasePlayer *pPlayer, CItem *pItem ); + +// Item spawn/respawn control + virtual int ItemShouldRespawn( CItem *pItem ); + virtual float FlItemRespawnTime( CItem *pItem ); + virtual Vector VecItemRespawnSpot( CItem *pItem ); + +// Ammo retrieval + virtual void PlayerGotAmmo( CBasePlayer *pPlayer, char *szName, int iCount ); + +// Ammo spawn/respawn control + virtual int AmmoShouldRespawn( CBasePlayerAmmo *pAmmo ); + virtual float FlAmmoRespawnTime( CBasePlayerAmmo *pAmmo ); + virtual Vector VecAmmoRespawnSpot( CBasePlayerAmmo *pAmmo ); + +// Healthcharger respawn control + virtual float FlHealthChargerRechargeTime( void ); + virtual float FlHEVChargerRechargeTime( void ); + +// What happens to a dead player's weapons + virtual int DeadPlayerWeapons( CBasePlayer *pPlayer ); + +// What happens to a dead player's ammo + virtual int DeadPlayerAmmo( CBasePlayer *pPlayer ); + +// Teamplay stuff + virtual const char *GetTeamID( CBaseEntity *pEntity ) {return "";} + virtual int PlayerRelationship( CBaseEntity *pPlayer, CBaseEntity *pTarget ); + + virtual BOOL PlayTextureSounds( void ) { return FALSE; } + virtual BOOL PlayFootstepSounds( CBasePlayer *pl, float fvol ); + +// Monsters + virtual BOOL FAllowMonsters( void ); + + // Immediately end a multiplayer game + virtual void EndMultiplayerGame( void ) { GoToIntermission(); } + +protected: + virtual void ChangeLevel( void ); + virtual void GoToIntermission( void ); + float m_flIntermissionEndTime; + BOOL m_iEndIntermissionButtonHit; + void SendMOTDToClient( edict_t *client ); +}; + +#endif //_MULTIPLAY_H_ diff --git a/ministl/algo.h b/ministl/algo.h new file mode 100644 index 00000000..23c7b42d --- /dev/null +++ b/ministl/algo.h @@ -0,0 +1,95 @@ +/* + * + * 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 +#ifndef __GNUG__ +#include +#endif +#include + +template +Function for_each(InputIterator first, InputIterator last, Function f) { + while (first != last) f(*first++); + return f; +} + +template +InputIterator find(InputIterator first, InputIterator last, const T& value) { + while (first != last && *first != value) ++first; + return first; +} + +template +InputIterator find_if(InputIterator first, InputIterator last, + Predicate pred) { + while (first != last && !pred(*first)) ++first; + return first; +} + +template +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 +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 +void count(InputIterator first, InputIterator last, const T& value, + Size& n) { + while (first != last) + if (*first++ == value) ++n; +} + +template +void count_if(InputIterator first, InputIterator last, Predicate pred, + Size& n) { + while (first != last) + if (pred(*first++)) ++n; +} + +template inline + _OI transform(_II _F, _II _L, _OI _X, _Uop _U) +{for (; _F != _L; ++_F, ++_X) +*_X = _U(*_F); +return (_X); } +// TEMPLATE FUNCTION transform WITH BINARY OP +template inline + _OI transform(_II1 _F1, _II1 _L1, _II2 _F2, _OI _X, _Bop _B) +{for (; _F1 != _L1; ++_F1, ++_F2, ++_X) +*_X = _B(*_F1, *_F2); +return (_X); } +// TEMPLATE FUNCTION replace + +#endif + diff --git a/ministl/algorithm b/ministl/algorithm new file mode 100644 index 00000000..ab993114 --- /dev/null +++ b/ministl/algorithm @@ -0,0 +1,23 @@ +/* + * 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: + * mico@informatik.uni-frankfurt.de + */ + +#include diff --git a/ministl/bool.h b/ministl/bool.h new file mode 100644 index 00000000..9ec59190 --- /dev/null +++ b/ministl/bool.h @@ -0,0 +1,51 @@ +// 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 diff --git a/ministl/bstring.h b/ministl/bstring.h new file mode 100644 index 00000000..f1f4251f --- /dev/null +++ b/ministl/bstring.h @@ -0,0 +1,2611 @@ +/** + ** 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 + +extern "C" { +#include +#include +#include +#include +} + +//#include + +// bool.h + +#ifndef __GNUG__ +#include +#endif + +// a typedef is less sweeping than a #define for "bool" +#ifndef __BOOL_DEFINED +//typedef int bool; +#endif + +// bc4const + +#ifdef __BC4_STL +#define __BC401_STL +#endif + +#ifdef __BC401_STL +#define __BC401_const +#else +#define __BC401_const const +#endif + +// bndchk.h +#ifdef BOUNDS_CHECK +void check_bounds + ( int index, + int container_size, + int lineno, + char *filename ); +#endif + +// mexcept.h + +#define _THROW_NONE +#define _THROW_DOMAIN +#define _THROW_INVALIDARG +#define _THROW_LENGTH +#define _THROW_OUTRANGE +#define _THROW_RANGE +#define _THROW_OVERFLOW +#define _THROW_ALLOC +#define _THROW_CAST +#define _THROW_TYPEID +#define _THROW_ALLOC_LENGTH +#define _THROW_ALLOC_OUTRANGE +#define _THROW_LENGTH_OUTRANGE +#define _THROW_ALLOC_LENGTH_OUTRANGE + +#include + +#ifdef __MMULTITHREAD +#include "mutex.h" +#endif + +const size_t NPOS = (size_t)(-1); + +enum capacity { default_size, reserve }; + +template +struct string_char_baggage { + + typedef charT char_type; + + // + // for users to acquire the basic character type + // + // constraints functions + // + static void + assign (char_type& c1, const char_type& c2) _THROW_NONE + { + c1 = c2; + } + static bool + eq (const char_type& c1, const char_type& c2) _THROW_NONE + { + return (c1 == c2); + } + static bool + ne (const char_type& c1, const char_type& c2) _THROW_NONE + { + return !(c1 == c2); + } + static bool + lt (const char_type& c1, const char_type& c2) _THROW_NONE + { + return (c1 < c2); + } + static char_type + eos () _THROW_NONE + { + return char_type(); // the null character + } + /* + static istream& + char_in (istream& is, char_type& c) _THROW_NONE + { + return is >> c; // extractor for a char_type object + } + static ostream& + char_out (ostream& os, char_type c) _THROW_NONE + { + return os << c; // inserter for a char_type object + } + static bool + is_del (char_type c) _THROW_NONE + { + // characteristic function for delimiters of char_type + return isspace(c); + } + */ + + // + // speed-up functions + // + static int + compare (const char_type* s1, const char_type* s2, size_t n) _THROW_NONE + { + for (size_t i = 0; i < n; ++i, ++s1, ++s2) + if (ne(*s1, *s2)) + { + return lt(*s1, *s2) ? -1 : 1; + } + return 0; + } + + static size_t + length (const char_type* s) _THROW_NONE + { + size_t l = 0; + while (ne(*s++, eos())) + ++l; + return l; + } + static char_type* + copy (char_type* s1, const char_type* s2, size_t n) _THROW_NONE + { + char_type* s = s1; + for (size_t i = 0; i < n; ++i) + assign(*s1++, *s2++); + return s; + } +}; + +template<> struct string_char_baggage { + + typedef char char_type; + + // + // constraint member functions + // + static void + assign (char_type& c1, const char_type& c2) _THROW_NONE + { + c1 = c2; + } + static bool + eq (const char_type& c1, const char_type& c2) _THROW_NONE + { + return (c1 == c2); + } + static bool + ne (const char_type& c1, const char_type& c2) _THROW_NONE + { + return (c1 != c2); + } + static bool + lt (const char_type& c1, const char_type& c2) _THROW_NONE + { + return (c1 < c2); + } + static char_type + eos () _THROW_NONE + { + return 0; // the null character + } + /* + static istream& + char_in (istream& is, char_type& c) _THROW_NONE + { + // extractor for a char_type object + // return is >> c; // this does not work + is.get(c); + return is; + } + static ostream& + char_out (ostream& os, char_type c) _THROW_NONE + { + return os << c; // inserter for a char_type object + } + static bool + is_del (char_type c) _THROW_NONE + { + // characteristic function for delimiters of char_type + return isspace(c); + } + */ + + // + // speed-up functions + // + static int + compare (const char_type* s1, const char_type* s2, size_t n) _THROW_NONE + { + return memcmp(s1, s2, n); + } + static size_t + length (const char_type* s) _THROW_NONE + { + return strlen(s); + } + static char_type* + copy (char_type* s1, const char_type* s2, size_t n) _THROW_NONE + { + // type cast required as memcpy returns void* + return (char_type*)memcpy(s1, s2, n); + } +}; + +#if 0 +struct string_char_baggage { + + typedef wchar_t char_type; + + static void + assign (char_type& c1, const char_type& c2) _THROW_NONE + { + c1 = c2; + } + static bool + eq (const char_type& c1, const char_type& c2) _THROW_NONE + { + return (c1 == c2); + } + static bool + ne (const char_type& c1, const char_type& c2) _THROW_NONE + { + return (c1 != c2); + } + static bool + lt (const char_type& c1, const char_type& c2) _THROW_NONE + { + return (c1 < c2); + } + static char_type + eos () _THROW_NONE + { + return 0; // the null character + } + /* + static istream& + char_in (istream& is, char_type& c) _THROW_NONE + { + return is >> c; // extractor for a char_type object + } + static ostream& + char_out (ostream& os, char_type c) _THROW_NONE + { + return os << c; // inserter for a char_type object + } + static bool + is_del (char_type c) _THROW_NONE + { + // characteristic function for delimiters of char_type + // using templatized locale::isspace function + return isspace(c); + } + */ + + // + // speed-up functions + // + static int + compare (const char_type* s1, const char_type* s2, size_t n) _THROW_NONE + { + return wmemcmp(s1, s2, n); + } + static size_t + length (const char_type* s) _THROW_NONE + { + return wcslen(s); + // May use Koshida's overloaded MSE function strlen(s) + } + static char_type* + copy (char_type* s1, const char_type* s2, size_t n) _THROW_NONE + { + return (char_type*)wmemcpy(s1, s2, n); + } +}; +#endif + +template +class basic_string; + +template +class basic_string_ref { + +// +// friend class declaration +// +friend class basic_string; + +// +// typedef declarations +// +typedef string_char_baggage baggage_type; + +// +// private data members +// + charT* ptr; + size_t len; + size_t res; + +#ifdef __MMULTITHREAD + mutex_arith count; // reference count +#else + size_t count; // reference count +#endif + +// +// private constructors and destructors +// + basic_string_ref () _THROW_NONE ; + + basic_string_ref (size_t size, capacity cap) _THROW_ALLOC_LENGTH ; + + basic_string_ref (const basic_string& str, size_t pos , size_t rlen) + _THROW_ALLOC ; + + basic_string_ref (const charT* s, size_t rlen, size_t rres) _THROW_ALLOC ; + + basic_string_ref (const charT* s, size_t n) _THROW_ALLOC_LENGTH ; + + basic_string_ref (const charT* s) _THROW_ALLOC ; + + basic_string_ref (charT c, size_t rep) _THROW_ALLOC_LENGTH ; + + basic_string_ref (const vector& vec) _THROW_ALLOC_LENGTH ; + + ~basic_string_ref () _THROW_NONE ; + + inline void + delete_ptr () _THROW_NONE ; + + static charT + eos () _THROW_NONE ; + + inline static + void + throwlength () _THROW_LENGTH; + + inline static + void + throwrange () _THROW_OUTRANGE; + +}; + +template +class basic_string { + +private: + +// +// typedef declaration +// + typedef basic_string_ref reference_class; + typedef basic_string_ref* reference_pointer; + +// +// data member +// + charT* c_str_ptr; + reference_pointer reference; +#if 1 + charT empty_string; +#endif + +// +// private member functions +// + inline charT* + point () _THROW_NONE ; + + inline size_t& + len () _THROW_NONE ; + + inline size_t + ref_count () const _THROW_NONE ; + + static charT + eos () _THROW_NONE ; + + void + assign_str (const charT* s, size_t slen) _THROW_ALLOC_LENGTH ; + + void + append_str (const charT* s, size_t slen) _THROW_ALLOC_LENGTH ; + + void + insert_str (size_t pos, const charT* s, size_t slen) + _THROW_ALLOC_LENGTH_OUTRANGE ; + + void + replace_str (size_t xlen, size_t pos, const charT* s, size_t slen) + _THROW_ALLOC_LENGTH_OUTRANGE ; + + int + compare_str (size_t pos, const charT* str, size_t slen, size_t strlen) + const _THROW_OUTRANGE ; + + size_t + find_str (const charT* s, size_t pos, size_t len) const _THROW_NONE ; + + size_t + rfind_str (const charT* s, size_t pos, size_t len) const _THROW_NONE ; + + size_t + find_first_of_str (const charT* s, size_t pos, size_t len) const + _THROW_NONE ; + + size_t + find_last_of_str (const charT* s, size_t pos, size_t len) const + _THROW_NONE ; + + size_t + find_first_not_of_str (const charT* s, size_t pos, size_t len) const + _THROW_NONE ; + + size_t + find_last_not_of_str (const charT* s, size_t pos, size_t len) const + _THROW_NONE ; + + +protected: + + basic_string (const charT* s, size_t rlen, size_t xlen) _THROW_ALLOC_LENGTH; + + inline void + delete_ref () _THROW_NONE ; + +public: +#if 1 + typedef unsigned long size_type; +#endif + typedef charT char_type; + typedef string_char_baggage baggage_type; + + basic_string () _THROW_ALLOC ; + + basic_string (size_t size, capacity cap) _THROW_ALLOC_LENGTH ; + + basic_string (const basic_string& str, size_t pos = 0, size_t n = NPOS) + _THROW_ALLOC_OUTRANGE ; + + basic_string (const charT* s, size_t n) _THROW_ALLOC_LENGTH ; + + basic_string (const charT* s) _THROW_ALLOC ; + + basic_string (charT c, size_t rep = 1) _THROW_ALLOC_LENGTH ; + + basic_string (const vector& vec) _THROW_ALLOC_LENGTH ; + + ~basic_string () _THROW_NONE ; + + basic_string& + operator= (const basic_string& str) _THROW_ALLOC ; + + basic_string& + operator= (const charT* s) _THROW_ALLOC ; + + basic_string& + operator= (charT c) _THROW_ALLOC ; + + basic_string& + operator+= (const basic_string& rhs) _THROW_ALLOC_LENGTH ; + + basic_string& + operator+= (const charT* s) _THROW_ALLOC_LENGTH ; + + basic_string& + operator+= (charT c) _THROW_ALLOC_LENGTH ; + + operator vector () const _THROW_ALLOC { + return vector (data(), data()+length()); + } + + basic_string& + append (const basic_string& str, size_t pos = 0, size_t n = NPOS) + _THROW_ALLOC_LENGTH_OUTRANGE ; + + basic_string& + append (const charT* s, size_t n) _THROW_ALLOC_LENGTH ; + + basic_string& + append (const charT* s) _THROW_ALLOC_LENGTH ; + + basic_string& + append (charT c, size_t rep = 1) _THROW_ALLOC_LENGTH ; + + basic_string& + assign (const basic_string& str, size_t pos = 0, size_t n = NPOS) + _THROW_ALLOC_LENGTH_OUTRANGE ; + + basic_string& + assign (const charT* s, size_t n) _THROW_ALLOC_LENGTH ; + + basic_string& + assign (const charT* s) _THROW_ALLOC_LENGTH ; + + basic_string& + assign (charT c, size_t rep = 1) _THROW_ALLOC_LENGTH ; + + basic_string& + insert (size_t pos1, const basic_string& str, size_t pos2 = 0, + size_t n = NPOS) _THROW_ALLOC_LENGTH_OUTRANGE ; + + basic_string& + insert (size_t pos, const charT* s, size_t n) _THROW_ALLOC_LENGTH_OUTRANGE ; + + basic_string& + insert (size_t pos, const charT* s) _THROW_ALLOC_LENGTH_OUTRANGE ; + + basic_string& + insert (size_t pos, charT c, size_t rep = 1) _THROW_ALLOC_LENGTH_OUTRANGE ; + + basic_string& + remove (size_t pos = 0, size_t n = NPOS) _THROW_ALLOC_OUTRANGE ; + + basic_string& + replace (size_t pos1, size_t n1, const basic_string& str, size_t pos2 = 0, + size_t n2 = NPOS) _THROW_ALLOC_LENGTH_OUTRANGE ; + + basic_string& + replace (size_t pos, size_t n1, const charT* s, size_t n2) + _THROW_ALLOC_LENGTH_OUTRANGE ; + + basic_string& + replace (size_t pos, size_t n1, const charT* s) + _THROW_ALLOC_LENGTH_OUTRANGE ; + + basic_string& + replace (size_t pos, size_t n, charT c, size_t rep = 1) + _THROW_ALLOC_LENGTH_OUTRANGE ; + + inline charT + get_at (size_t pos) const _THROW_OUTRANGE ; + + void + put_at (size_t pos, charT c) _THROW_ALLOC_OUTRANGE ; + + inline charT + operator[] (size_t pos) const _THROW_NONE ; + + charT& + operator[] (size_t pos) _THROW_ALLOC_OUTRANGE ; + + const charT* + c_str () const _THROW_ALLOC ; + + inline const charT* + data () const _THROW_NONE ; + + inline size_t + length () const _THROW_NONE ; + size_t size () const _THROW_NONE { return length(); } + + void + resize (size_t n, charT c) _THROW_ALLOC_LENGTH ; + + void + resize (size_t n) _THROW_ALLOC_LENGTH ; + + inline size_t + reserve () const _THROW_NONE ; + + void + reserve (size_t res_arg) _THROW_ALLOC_LENGTH ; + + size_t + copy (charT* s, size_t n, size_t pos = 0) const _THROW_OUTRANGE ; + + size_t + find (const basic_string& str, size_t pos = 0) const _THROW_NONE ; + + size_t + find (const charT* s, size_t pos, size_t n) const _THROW_NONE ; + + size_t + find (const charT* s, size_t pos = 0) const _THROW_NONE ; + + size_t + find (charT c, size_t pos = 0) const _THROW_NONE ; + + size_t + rfind (const basic_string& str, size_t pos = NPOS) const _THROW_NONE ; + + size_t + rfind (const charT* s, size_t pos, size_t n) const _THROW_NONE ; + + size_t + rfind (const charT* s, size_t pos = NPOS) const _THROW_NONE ; + + size_t + rfind (charT c, size_t pos = NPOS) const _THROW_NONE ; + + size_t + find_first_of (const basic_string& str, size_t pos = 0) const _THROW_NONE ; + + size_t + find_first_of (const charT* s, size_t pos, size_t n) const _THROW_NONE ; + + size_t + find_first_of (const charT* s, size_t pos = 0) const _THROW_NONE ; + + size_t + find_first_of (charT c, size_t pos = 0) const _THROW_NONE ; + + + size_t + find_last_of (const basic_string& str, size_t pos = NPOS) const + _THROW_NONE ; + + size_t + find_last_of (const charT* s, size_t pos, size_t n) const _THROW_NONE ; + + size_t + find_last_of (const charT* s, size_t pos = NPOS) const _THROW_NONE ; + + size_t + find_last_of (charT c, size_t pos = NPOS) const _THROW_NONE ; + + size_t + find_first_not_of (const basic_string& str, size_t pos = 0) const + _THROW_NONE ; + + size_t + find_first_not_of (const charT* s, size_t pos, size_t n) const _THROW_NONE ; + + size_t + find_first_not_of (const charT* s, size_t pos = 0) const _THROW_NONE ; + + size_t + find_first_not_of (charT c, size_t pos = 0) const _THROW_NONE ; + + size_t + find_last_not_of (const basic_string& str, size_t pos = NPOS) const + _THROW_NONE ; + + size_t + find_last_not_of (const charT* s, size_t pos, size_t n) const _THROW_NONE ; + + size_t + find_last_not_of (const charT* s, size_t pos = NPOS) const _THROW_NONE ; + + size_t + find_last_not_of (charT c, size_t pos = NPOS) const _THROW_NONE ; + + basic_string + substr (size_t pos = 0, size_t n = NPOS) const _THROW_ALLOC_OUTRANGE ; + + int + compare (const basic_string& str, size_t pos = 0, size_t n = NPOS) const + _THROW_OUTRANGE ; + + int + compare (const charT* s, size_t pos, size_t n) const + _THROW_LENGTH_OUTRANGE ; + + int + compare (const charT* s, size_t pos = 0) const _THROW_OUTRANGE ; + + int + compare (charT c, size_t pos = 0, size_t rep = 1) const + _THROW_LENGTH_OUTRANGE ; + + /* + static ostream& + op_lshift (ostream& o, const basic_string& s) _THROW_NONE ; + + static istream& + op_rshift (istream& i, basic_string& s) _THROW_ALLOC_LENGTH ; + */ + + static basic_string + op_plus (const basic_string& lhs, const basic_string& rhs) + _THROW_ALLOC_LENGTH ; + + static basic_string + op_plus (const charT* lhs, const basic_string& rhs) + _THROW_ALLOC_LENGTH ; + + static basic_string + op_plus (charT lhs, const basic_string& rhs) _THROW_ALLOC_LENGTH ; + + static basic_string + op_plus (const basic_string& lhs, const charT* rhs) + _THROW_ALLOC_LENGTH ; + + static basic_string + op_plus (const basic_string& lhs, charT rhs) _THROW_ALLOC_LENGTH ; +}; + +template +inline void +basic_string_ref::delete_ptr () _THROW_NONE +{ + if (res) + { + delete[] ptr; + res = 0; + ptr = 0; + } +} + +template +inline void +basic_string_ref::throwlength () _THROW_LENGTH +{ +#ifdef __MEXCEPT + throw length_error("Length exception occurred"); +#else + //cout << "Length exception occurred" << endl; + exit(1); +#endif +} + +template +inline void +basic_string_ref::throwrange () _THROW_OUTRANGE +{ +#ifdef __MEXCEPT + throw out_of_range("Out of range exception occurred"); +#else + //cout << "Out of range exception occurred" << endl; + exit(1); +#endif +} + +template +inline void +basic_string::delete_ref () _THROW_NONE +{ + --(reference->count); + if (!(reference->count)) + delete reference; +} + +template +inline size_t +basic_string::ref_count () const _THROW_NONE +{ + return reference->count; +} + +template +inline const charT* +basic_string::data () const _THROW_NONE +{ + if (length()) + return reference->ptr; + else + return 0; +} + +template +inline charT* +basic_string::point () _THROW_NONE +{ + return reference->ptr; +} + +template +inline size_t& +basic_string::len () _THROW_NONE +{ + return reference->len; +} + +template +inline size_t +basic_string::length () const _THROW_NONE +{ + return reference->len; +} + +template +inline size_t +basic_string::reserve () const _THROW_NONE +{ + return reference->res; +} + +template +inline charT +basic_string::get_at (size_t pos) const _THROW_OUTRANGE +{ + if (pos >= length()) + { + reference_class::throwrange(); + } + return *(data()+pos); +} + +template +inline charT +basic_string::operator[] (size_t pos) const _THROW_NONE +{ + if (pos < length()) + return *(data()+pos); + else + return 0; +} + +template +inline bool +operator== (const basic_string& lhs, const basic_string& rhs) + _THROW_NONE +{ + return 0 == lhs.compare(rhs); +} + +template +inline bool +operator== (const charT* lhs, const basic_string& rhs) _THROW_NONE +{ + return 0 == rhs.compare(lhs); +} + +template +inline bool +operator== (charT lhs, const basic_string& rhs) _THROW_NONE +{ + return 0 == rhs.compare(lhs); +} + +template +inline bool +operator== (const basic_string& lhs, const charT* rhs) _THROW_NONE +{ + return 0 == lhs.compare(rhs); +} + +template +inline bool +operator== (const basic_string& lhs, charT rhs) _THROW_NONE +{ + return 0 == lhs.compare(rhs); +} + +template +inline bool +operator!= (const basic_string& lhs, const basic_string& rhs) + _THROW_NONE +{ + return 0 != lhs.compare(rhs); +} + +template +inline bool +operator!= (const charT* lhs, const basic_string& rhs) _THROW_NONE +{ + return 0 != rhs.compare(lhs); +} + +template +inline bool +operator!= (charT lhs, const basic_string& rhs) _THROW_NONE +{ + return 0 != rhs.compare(lhs); +} + +template +inline bool +operator!= (const basic_string& lhs, const charT* rhs) _THROW_NONE +{ + return 0 != lhs.compare(rhs); +} + +template +inline bool +operator!= (const basic_string& lhs, charT rhs) _THROW_NONE +{ + return 0 != lhs.compare(rhs); +} + +template +inline bool +operator< (const basic_string& lhs, const basic_string& rhs) + _THROW_NONE +{ + if (lhs.compare(rhs) < 0) + return true; + else + return false; +} + +template +inline bool +operator< (const charT* lhs, const basic_string& rhs) _THROW_NONE +{ + if (rhs.compare(lhs) > 0) + return true; + else + return false; +} + +template +inline bool +operator< (charT lhs, const basic_string& rhs) _THROW_NONE +{ + if (rhs.compare(lhs) > 0) + return true; + else + return false; +} + +template +inline bool +operator< (const basic_string& lhs, const charT* rhs) _THROW_NONE +{ + if (lhs.compare(rhs) < 0) + return true; + else + return false; +} + +template +inline bool +operator< (const basic_string& lhs, charT rhs) _THROW_NONE +{ + if (lhs.compare(rhs) < 0) + return true; + else + return false; +} + +#ifdef __MNONDEF +template +inline bool +operator> (const basic_string& lhs, const basic_string& rhs) + _THROW_NONE +{ + return (rhs < lhs); +} +#endif + +template +inline bool +operator> (const charT* lhs, const basic_string& rhs) _THROW_NONE +{ + return (rhs < lhs); +} + +template +inline bool +operator> (charT lhs, const basic_string& rhs) _THROW_NONE +{ + return (rhs < lhs); +} + +template +inline bool +operator> (const basic_string& lhs, const charT* rhs) _THROW_NONE +{ + return (rhs < lhs); +} + +template +inline bool +operator> (const basic_string& lhs, charT rhs) _THROW_NONE +{ + return (rhs < lhs); +} + +#ifdef __MNONDEF +template +inline bool +operator>= (const basic_string& lhs, const basic_string& rhs) + _THROW_NONE +{ + return !(lhs < rhs); +} +#endif + +template +inline bool +operator>= (const charT* lhs, const basic_string& rhs) _THROW_NONE +{ + return !(lhs < rhs); +} + +template +inline bool +operator>= (charT lhs, const basic_string& rhs) _THROW_NONE +{ + return !(lhs < rhs); +} + +template +inline bool +operator>= (const basic_string& lhs, const charT* rhs) _THROW_NONE +{ + return !(lhs < rhs); +} + +template +inline bool +operator>= (const basic_string& lhs, charT rhs) _THROW_NONE +{ + return !(lhs < rhs); +} + +#ifdef __MNONDEF +template +inline bool +operator<= (const basic_string& lhs, const basic_string& rhs) + _THROW_NONE +{ + return !(rhs < lhs); +} +#endif + +template +inline bool +operator<= (const charT* lhs, const basic_string& rhs) _THROW_NONE +{ + return !(rhs < lhs); +} + +template +inline bool +operator<= (charT lhs, const basic_string& rhs) _THROW_NONE +{ + return !(rhs < lhs); +} + +template +inline bool +operator<= (const basic_string& lhs, const charT* rhs) _THROW_NONE +{ + return !(rhs < lhs); +} + +template +inline bool +operator<= (const basic_string& lhs, charT rhs) _THROW_NONE +{ + return !(rhs < lhs); +} + +// definitions : can be in a .c file +// + +template +charT +basic_string_ref::eos () _THROW_NONE +{ + return baggage_type::eos(); +} + +template +basic_string_ref::basic_string_ref () _THROW_NONE +{ + res = len = 0; + ptr = 0; + count = 1; +} + +template +basic_string_ref::basic_string_ref (size_t size, capacity cap) + _THROW_ALLOC_LENGTH +{ + if (cap == ::reserve) + { + len = 0; + res = size; +#if 0 + ptr = new charT [res]; +#else + ptr = new charT [res+1]; +#endif + } + else if ((cap == ::default_size) && (size != NPOS)) + { + res = len = size; + if (res) + { +#if 0 + ptr = new charT [res]; +#else + ptr = new charT [res+1]; +#endif + for (size_t position = 0; position < len; ++position) + baggage_type::assign (*(ptr+position), eos()); + } + else + ptr = 0; + } + else + { + throwlength(); + } + count = 1; +} + +template +basic_string_ref::basic_string_ref (const basic_string& str, + size_t pos, size_t rlen) _THROW_ALLOC +{ + res = len = rlen; + if (res) + { +#if 0 + ptr = new charT [res]; +#else + ptr = new charT [res+1]; +#endif + baggage_type::copy (ptr, str.data()+pos, len); + } + else + ptr = 0; + count = 1; +} + +template +basic_string_ref::basic_string_ref (const charT* s, size_t rlen, + size_t rres) _THROW_ALLOC +{ + res = rres; + len = rlen; + if (res) + { +#if 0 + ptr = new charT [res]; +#else + ptr = new charT [res+1]; +#endif + if (len) + baggage_type::copy (ptr, s, len); + } + else + ptr = 0; + count = 1; +} + +template +basic_string_ref::basic_string_ref (const charT* s, size_t n) + _THROW_ALLOC_LENGTH +{ + if (n == NPOS) + { + throwlength(); + } + res = len = n; + if (res) + { +#if 0 + ptr = new charT [res]; +#else + ptr = new charT [res+1]; +#endif + baggage_type::copy (ptr, s, len); + } + else + ptr = 0; + count = 1; +} + +template +basic_string_ref::basic_string_ref (const charT* s) _THROW_ALLOC +{ + res = len = baggage_type::length(s); + if (res) + { +#if 0 + ptr = new charT [res]; +#else + ptr = new charT [res+1]; +#endif + baggage_type::copy (ptr, s, len); + } + else + ptr = 0; + count = 1; +} + +template +basic_string_ref::basic_string_ref (charT c, size_t rep) + _THROW_ALLOC_LENGTH +{ + if (rep == NPOS) + { + throwlength(); + } + res = len = rep; + if (res) + { +#if 0 + ptr = new charT [res]; +#else + ptr = new charT [res+1]; +#endif + for (size_t position = 0; position < len; ++position) + baggage_type::assign (*(ptr+position), c); + } + else + ptr = 0; + count = 1; +} + +template +basic_string_ref::basic_string_ref (const vector& vec) + _THROW_ALLOC_LENGTH +{ + size_t n = vec.size(); + if (n == NPOS) + { + throwlength(); + } + res = len = n; + if (res) + { +#if 0 + ptr = new charT [res]; +#else + ptr = new charT [res+1]; +#endif + baggage_type::copy (ptr, vec.begin(), len); + } + else + ptr = 0; + count = 1; +} + +template +basic_string_ref::~basic_string_ref () _THROW_NONE +{ + delete_ptr(); +} + +template +charT +basic_string::eos () _THROW_NONE +{ + return baggage_type::eos(); +} + +template +void +basic_string::assign_str (const charT* s, size_t slen) + _THROW_ALLOC_LENGTH +{ + if (slen == NPOS) + { + reference_class::throwlength(); + } + if ((ref_count() > 1) || (slen && (reserve() < slen))) + { + reference_pointer tmp; + tmp = new basic_string_ref (s, slen); + delete_ref(); + reference = tmp; + } + else if (slen) + { + baggage_type::copy (point(), s, slen); + } + reference->len = slen; +} + +template +void +basic_string::append_str (const charT* s, size_t slen) + _THROW_ALLOC_LENGTH +{ + if (length() >= (NPOS-slen)) + { + reference_class::throwlength(); + } + if ((ref_count() > 1) || (slen > (reserve()-length()))) + { + reference_pointer tmp; + tmp = new basic_string_ref (data(), length(), length()+slen); + delete_ref(); + reference = tmp; + } + if (slen) + baggage_type::copy (point()+length(), s, slen); + reference->len += slen; +} + +template +void +basic_string::insert_str (size_t pos, const charT* s, size_t slen) + _THROW_ALLOC_LENGTH_OUTRANGE +{ + if (pos > length()) + { + reference_class::throwrange(); + } + if (length() >= (NPOS-slen)) + { + reference_class::throwlength(); + } + if ((ref_count() > 1) || (slen > (reserve()-length()))) + { + reference_pointer tmp; + tmp = new basic_string_ref (data(), pos, length()+slen); + baggage_type::copy (tmp->ptr+pos+slen, data()+pos, length()-pos); + tmp->len = length(); + delete_ref(); + reference = tmp; + } + else + { + for (size_t count = length()-pos; count > 0; --count) + baggage_type::assign (*(point()+pos+slen+count-1), + *(data()+pos+count-1)); + } + if (slen) + baggage_type::copy (point()+pos, s, slen); + reference->len += slen; +} + +template +void +basic_string::replace_str (size_t xlen, size_t pos, const charT* s, + size_t slen) _THROW_ALLOC_LENGTH_OUTRANGE +{ + if (pos > length()) + { + reference_class::throwrange(); + } + if ((length()-xlen) >= (NPOS-slen)) + { + reference_class::throwlength(); + } + if ((ref_count() > 1) || (reserve() < (length()+slen-xlen))) + { + reference_pointer tmp; + tmp = new basic_string_ref (data(), pos, length()+slen-xlen); + baggage_type::copy (tmp->ptr+pos+slen, data()+pos+xlen, + length()-pos-xlen); + tmp->len = length(); + delete_ref(); + reference = tmp; + } + else + { + if (slen < xlen) + baggage_type::copy (point()+pos+slen, data()+pos+xlen, + length()-pos-xlen); + else + { + for (size_t count = length()-pos-xlen; count > 0; --count) + baggage_type::assign (*(point()+pos+slen+count-1), + *(data()+pos+xlen+count-1)); + } + } + if (slen) + baggage_type::copy (point()+pos, s, slen); + reference->len += (slen-xlen); +} + +template +int +basic_string::compare_str (size_t pos, const charT* str, size_t slen, + size_t strlen) const _THROW_OUTRANGE +{ + if (pos > length()) + { + reference_class::throwrange(); + } + size_t rlen = (slen > strlen ) ? strlen : slen; + int result; + if (!length()) + return str ? (eos()- *str) : eos(); + result = baggage_type::compare (data()+pos, str, rlen); + return result ? result : (length()-pos-strlen); +} + +template +size_t +basic_string::find_str (const charT* s, size_t pos, size_t len) + const _THROW_NONE +{ + size_t count = pos; + size_t shift; + size_t place; + if ((length() == 0) || (len == 0)) + return NPOS; + while (len <= (length()-count)) + { + for (place = 0; place < len; ++place) + { + if (baggage_type::ne(*(s+len-1-place), *(data()+count+(len-1-place)))) + break; + } + if (place == len) + return count; + shift = find(*(s+len-1-place), count+(len-place)); + if (shift == NPOS) + return NPOS; + count = shift-(len-place-1); + } + return NPOS; +} + +template +size_t +basic_string::rfind_str (const charT* s, size_t pos, size_t len) + const _THROW_NONE +{ + size_t count = (pos < (length()-len)) ? (pos+1) : (length()-len); + size_t shift; + size_t place; + if ((length() < len) || (len == 0)) + return NPOS; + while (count > 0) + { + for (place = 0; place < len; ++place) + { + if (baggage_type::ne(*(s+len-1-place), *(data()+count+(len-place)-2))) + break; + } + if (place == len) + return count-1; + shift = rfind(*(s+len-1-place), count+(len-place)-3); + if (shift == NPOS) + return NPOS; + count = shift+place-len+2; + } + return NPOS; + +} + +template +size_t +basic_string::find_first_of_str (const charT* s, size_t pos, size_t len) + const _THROW_NONE +{ + size_t temp; + size_t count = pos; + size_t result = NPOS; + while (count < length()) + { + temp = 0; + while ((temp < len) && baggage_type::ne(*(data()+count), *(s+temp))) + ++temp; + if (temp != len) + break; + ++count; + } + temp = (count >= length()) ? NPOS : count; + return ((result > temp) ? temp : result); +} + +template +size_t +basic_string::find_last_of_str (const charT* s, size_t pos, size_t len) + const _THROW_NONE +{ + size_t temp = 0; + size_t count = (pos < length()) ? (pos+1) : length(); + if (length()) + { + while (count > 0) + { + temp = 0; + --count; + while ((temp != len) && baggage_type::ne(*(data()+count), *(s+temp))) + ++temp; + if (temp != len) + break; + } + } + return ((temp != len) && length()) ? count : NPOS; +} + +template +size_t +basic_string::find_first_not_of_str (const charT* s, size_t pos, + size_t len) const _THROW_NONE +{ + size_t count = pos; + while (count < length()) + { + size_t temp = 0; + while (temp < len) + { + if (baggage_type::eq(*(data()+count), *(s+temp))) + break; + ++temp; + } + if (temp == len) + break; + ++count; + } + return ((count >= length()) ? NPOS : count); +} + +template +size_t +basic_string::find_last_not_of_str (const charT* s, size_t pos, + size_t len) const _THROW_NONE +{ + size_t temp = 0; + size_t count = (pos < length()) ? (pos+1) : length(); + + if (length()) + { + while (count > 0) + { + temp = 0; + while (temp != len) + { + if (baggage_type::eq(*(data()+count-1), *(s+temp))) + break; + ++temp; + } + if (temp == len) + break; + --count; + } + } + return ((temp == len) && length()) ? count-1 : NPOS; +} + +template +basic_string::basic_string () _THROW_ALLOC +{ + reference = new basic_string_ref (); + c_str_ptr = 0; +} + +template +basic_string::basic_string (size_t size, capacity cap) + _THROW_ALLOC_LENGTH +{ + reference = new basic_string_ref (size, cap); + c_str_ptr = 0; +} + +template +basic_string::basic_string (const basic_string& str, + size_t pos, size_t n) _THROW_ALLOC_OUTRANGE +{ + if (pos > str.length()) + { + reference_class::throwrange(); + } + size_t rlen = (n > (str.length() - pos)) ? str.length() - pos : n; + if ((rlen == str.length()) && (str.ref_count() != NPOS)) + (reference = str.reference)->count++; + else + reference = new basic_string_ref (str, pos, rlen); + c_str_ptr = 0; +} + +template +basic_string::basic_string (const charT* s, size_t rlen, size_t xlen) + _THROW_ALLOC_LENGTH +{ + if (rlen >= (NPOS - xlen)) + { + reference_class::throwlength(); + } + reference = new basic_string_ref (s, rlen, rlen+xlen); + c_str_ptr = 0; +} + +template +basic_string::basic_string (const charT* s, size_t n) _THROW_ALLOC_LENGTH +{ + reference = new basic_string_ref (s, n); + c_str_ptr = 0; +} + +template +basic_string::basic_string (const charT* s) _THROW_ALLOC +{ + reference = new basic_string_ref (s); + c_str_ptr = 0; +} + +template +basic_string::basic_string (charT c, size_t rep) _THROW_ALLOC_LENGTH +{ + reference = new basic_string_ref (c, rep); + c_str_ptr = 0; +} + +template +basic_string::basic_string (const vector& vec) _THROW_ALLOC_LENGTH +{ + reference = new basic_string_ref (vec); + c_str_ptr = 0; +} + +template +basic_string::~basic_string () _THROW_NONE +{ + delete_ref(); + if (c_str_ptr) + delete[] c_str_ptr; +} + +template +basic_string& +basic_string::operator= (const basic_string& str) _THROW_ALLOC +{ + if (this != &str) + { + delete_ref(); + if (str.ref_count() != NPOS) + (reference = str.reference)->count++; + else + reference = new basic_string_ref (str, 0, str.length()); + } + return *this; +} + +template +basic_string& +basic_string::operator= (const charT* s) _THROW_ALLOC +{ + assign_str (s, baggage_type::length(s)); + return *this; +} + +template +basic_string& +basic_string::operator= (charT c) _THROW_ALLOC +{ + if ((ref_count() == 1) && (reserve() >= 1)) + { + baggage_type::assign (*(point()), c); + reference->len = 1; + } + else + { + delete_ref(); + reference = new basic_string_ref (c, 1); + } + return *this; +} + +template +basic_string& +basic_string::operator+= (const basic_string& rhs) _THROW_ALLOC_LENGTH +{ + append_str (rhs.data(), rhs.length()); + return *this; +} + +template +basic_string& +basic_string::operator+= (const charT* s) _THROW_ALLOC_LENGTH +{ + append_str (s, baggage_type::length(s)); + return *this; +} + +template +basic_string& +basic_string::operator+= (charT c) _THROW_ALLOC_LENGTH +{ + if (length() >= (NPOS-1)) + { + reference_class::throwlength(); + } + if (!((ref_count() == 1) && (reserve() > length()))) + { + reference_pointer tmp; + tmp = new basic_string_ref (data(), length(), length()+1); + delete_ref(); + reference = tmp; + } + baggage_type::assign (*(point()+length()), c); + reference->len++; + return *this; +} + + +template +basic_string& +basic_string::append (const basic_string& str, size_t pos, size_t n) + _THROW_ALLOC_LENGTH_OUTRANGE +{ + if (pos > str.length()) + { + reference_class::throwrange(); + } + append_str (str.data() + pos, (n>(str.length()-pos))?(str.length()-pos):n); + return *this; +} + +template +basic_string& +basic_string::append (const charT* s, size_t n) _THROW_ALLOC_LENGTH +{ + append_str (s, n); + return *this; +} + +template +basic_string& +basic_string::append (const charT* s) _THROW_ALLOC_LENGTH +{ + append_str (s, baggage_type::length(s)); + return *this; +} + +template +basic_string& +basic_string::append (charT c, size_t rep) _THROW_ALLOC_LENGTH +{ + if (length() >= (NPOS-rep)) + { + reference_class::throwlength(); + } + if (rep) + { + if ((ref_count() > 1) || (reserve() < (length() + rep))) + { + reference_pointer tmp; + tmp = new basic_string_ref (data(), length(), length()+rep); + delete_ref(); + reference = tmp; + } + for (size_t count = 0; count < rep; ++count) + baggage_type::assign (*(point()+length()+count), c); + reference->len += rep; + } + return *this; +} + +template +basic_string& +basic_string::assign (const basic_string& str, size_t pos, size_t n) + _THROW_ALLOC_LENGTH_OUTRANGE +{ + if (pos > str.length()) + { + reference_class::throwrange(); + } + size_t rlen = (n > (str.length() - pos)) ? str.length() - pos : n; + if ((rlen == str.length()) && (str.ref_count() != NPOS)) + { + delete_ref(); + (reference = str.reference)->count++; + } + else + assign_str (str.data()+pos, rlen); + return *this; +} + +template +basic_string& +basic_string::assign (const charT* s, size_t n) _THROW_ALLOC_LENGTH +{ + assign_str (s, n); + return *this; +} + +template +basic_string& +basic_string::assign (const charT* s) _THROW_ALLOC_LENGTH +{ + assign_str (s, baggage_type::length(s)); + return *this; +} + +template +basic_string& +basic_string::assign (charT c, size_t rep) _THROW_ALLOC_LENGTH +{ + if (rep == NPOS) + { + reference_class::throwlength(); + } + if ((ref_count() > 1) || (rep && (reserve() < rep))) + { + reference_pointer tmp; + tmp = new basic_string_ref (c, rep); + delete_ref(); + reference = tmp; + } + else + { + for (size_t count = 0; count < rep; ++count) + baggage_type::assign (*(point()+count), c); + reference->len = rep; + } + return *this; +} + +template +basic_string& +basic_string::insert (size_t pos1, const basic_string& str, + size_t pos2, size_t n) _THROW_ALLOC_LENGTH_OUTRANGE +{ + if (pos2 > str.length()) + { + reference_class::throwrange(); + } + size_t rlen = (n > (str.length() - pos2)) ? str.length() - pos2 : n; + insert_str (pos1, str.data()+pos2, rlen); + return *this; +} + +template +basic_string& +basic_string::insert (size_t pos, const charT* s, size_t n) + _THROW_ALLOC_LENGTH_OUTRANGE +{ + insert_str(pos, s, n); + return *this; +} + +template +basic_string& +basic_string::insert (size_t pos, const charT* s) + _THROW_ALLOC_LENGTH_OUTRANGE +{ + insert_str(pos, s, baggage_type::length(s)); + return *this; +} + +template +basic_string& +basic_string::insert (size_t pos, charT c, size_t rep) + _THROW_ALLOC_LENGTH_OUTRANGE +{ + if (pos > length()) + { + reference_class::throwrange(); + } + if ((rep == NPOS) || (length() >= (NPOS - rep))) + { + reference_class::throwlength(); + } + if (rep) + { + size_t count; + if ((ref_count() > 1) || (reserve() < (length()+rep))) + { + reference_pointer tmp; + tmp = new basic_string_ref (data(), pos, length()+rep); + if (length()) + for (count = length()-pos; count > 0; --count) + baggage_type::assign (*(tmp->ptr+pos+rep+count-1), + *(data()+pos+count-1)); + tmp->len = length(); + delete_ref(); + reference = tmp; + } + else + { + for (count = length()-pos; count > 0; --count) + baggage_type::assign (*(point()+pos+rep+count-1), + *(data()+pos+count-1)); + } + for (count = 0; count < rep; ++count) + baggage_type::assign (*(point()+pos+count), c); + reference->len += rep; + } + return *this; +} + +template +basic_string& +basic_string::remove (size_t pos, size_t n) _THROW_ALLOC_OUTRANGE +{ + if (pos > length()) + { + reference_class::throwrange(); + } + size_t xlen = (n > (length()-pos)) ? (length()-pos) : n; + if (ref_count() > 1) + { + reference_pointer tmp; + tmp = new basic_string_ref (data(), pos, length()); + baggage_type::copy (tmp->ptr+pos, data()+pos+xlen, length()-xlen-pos); + tmp->len = length()-xlen; + delete_ref(); + reference = tmp; + } + else if (xlen == length()) + reference->len = 0; + else if (xlen) + { + baggage_type::copy (point()+pos, data()+pos+xlen, length()-xlen-pos); + reference->len -= xlen; + } + return *this; +} + +template +basic_string& +basic_string::replace (size_t pos1, size_t n1, const basic_string& str, + size_t pos2, size_t n2) _THROW_ALLOC_LENGTH_OUTRANGE +{ + if (pos2 > str.length()) + { + reference_class::throwrange(); + } + size_t xlen = (n1 > (length()-pos1)) ? (length()-pos1) : n1; + size_t rlen = (n2 > (str.length()-pos2)) ? (str.length()-pos2) : n2; + replace_str (xlen, pos1, str.data()+pos2, rlen); + return *this; +} + +template +basic_string& +basic_string::replace (size_t pos, size_t n1, const charT* s, size_t n2) + _THROW_ALLOC_LENGTH_OUTRANGE +{ + size_t xlen = (n1 > (length()-pos)) ? (length()-pos) : n1; + replace_str (xlen, pos, s, n2); + return *this; +} + +template +basic_string& +basic_string::replace (size_t pos, size_t n1, const charT* s) + _THROW_ALLOC_LENGTH_OUTRANGE +{ + size_t xlen = (n1 > (length()-pos)) ? (length()-pos) : n1; + replace_str (xlen, pos, s, baggage_type::length(s)); + return *this; +} + +template +basic_string& +basic_string::replace (size_t pos, size_t n, charT c, size_t rep) + _THROW_ALLOC_LENGTH_OUTRANGE +{ + if (pos > length()) + { + reference_class::throwrange(); + } + size_t xlen = (n > (length()-pos)) ? (length()-pos) : n; + if ((length()-xlen) >= (NPOS-rep)) + { + reference_class::throwlength(); + } + if (!rep) + return remove (pos, n); + else + { + size_t count; + if ((ref_count() > 1) || (reserve() < (length()-xlen+rep))) + { + reference_pointer tmp; + tmp = new basic_string_ref (data(), pos, + length()+((xlen > rep) ? (xlen-rep) : 0)); + if (rep < xlen) + baggage_type::copy (tmp->ptr+pos+rep, data()+pos+xlen, + length()-pos-xlen); + else + { + for (count = length()-xlen-pos; count > 0; --count) + baggage_type::assign (*(tmp->ptr+pos+rep+count-1), + *(data()+pos+xlen+count-1)); + } + tmp->len = length(); + delete_ref(); + reference = tmp; + } + else + { + if (rep < xlen) + baggage_type::copy (point()+pos+rep, data()+pos+xlen, + length()-pos-xlen); + else + { + for (count = length()-xlen-pos; count > 0; --count) + baggage_type::assign (*(point()+pos+rep+count-1), + *(data()+pos+xlen+count-1)); + } + } + for (count = 0; count < rep; ++count) + baggage_type::assign (*(point()+pos+count), c); + reference->len += (rep-xlen); + } + return *this; +} + +template +void +basic_string::put_at (size_t pos, charT c) _THROW_ALLOC_OUTRANGE +{ + if (pos > length()) + { + reference_class::throwrange(); + } + if ((ref_count() > 1) || (pos == reserve())) + { + reference_pointer tmp; + tmp = new basic_string_ref (data(), length(), + length()+((pos==length())?1:0)); + delete_ref(); + reference = tmp; + } + if (pos == length()) + ++reference->len; + baggage_type::assign (*(point()+pos), c); +} + +template +charT& +basic_string::operator[] (size_t pos) _THROW_ALLOC_OUTRANGE +{ + if (pos >= length()) + { + reference_class::throwrange(); + } + if (ref_count() > 1) + { + reference_pointer tmp; + tmp = new basic_string_ref (data(), length(), length()); + delete_ref(); + reference = tmp; + } + return *(point()+pos); +} + +template +const charT* +basic_string::c_str () const _THROW_ALLOC +{ +#if 0 + if (c_str_ptr) + delete[] ((basic_string*)this)->c_str_ptr; + ((basic_string*)this)->c_str_ptr = new charT [length()+1]; + if (length()) + baggage_type::copy (((basic_string*)this)->c_str_ptr, data(), + length()); + baggage_type::assign (*(((basic_string*)this)->c_str_ptr+length()), + eos()); + return c_str_ptr; +#else + if (!length()) { + baggage_type::assign ((charT &)empty_string, eos()); + return &empty_string; + } + baggage_type::assign (*(charT *)(data()+length()), + eos()); + return data(); +#endif +} + +template +void +basic_string::resize (size_t n, charT c) _THROW_ALLOC_LENGTH +{ + if (n == NPOS) + { + reference_class::throwlength(); + } + if ((ref_count() > 1) || (n > reserve())) + { + reference_pointer tmp; + tmp = new basic_string_ref (data(), + ((n > length()) ? length() : n), n); + delete_ref(); + reference = tmp; + } + while (reference->len < n) + { + baggage_type::assign (*(reference->ptr+length()), c); + ++reference->len; + } + reference->len = n; +} + +template +void +basic_string::resize (size_t n) _THROW_ALLOC_LENGTH +{ + resize (n, eos()); +} + +template +void +basic_string::reserve (size_t res_arg) _THROW_ALLOC_LENGTH +{ + if (res_arg == NPOS) + { + reference_class::throwlength(); + } + if (res_arg > reserve()) + { + reference_pointer tmp; + tmp = new basic_string_ref (data(), length(), res_arg); + delete_ref(); + reference = tmp; + } +} + +template +size_t +basic_string::copy (charT* s, size_t n, size_t pos) const _THROW_OUTRANGE +{ + if (pos > length()) + { + reference_class::throwrange(); + } + size_t rlen = (n > (length()-pos)) ? (length()-pos) : n; + if (length()) + baggage_type::copy (s, data()+pos, rlen); + return rlen; +} + +template +size_t +basic_string::find (const basic_string& str, size_t pos) const + _THROW_NONE +{ + return find_str (str.data(), pos, str.length()); +} + +template +size_t +basic_string::find (const charT* s, size_t pos, size_t n) const + _THROW_NONE +{ + return find_str (s, pos, n); +} + +template +size_t +basic_string::find (const charT* s, size_t pos) const _THROW_NONE +{ + return find_str (s, pos, baggage_type::length(s)); +} + +template +size_t +basic_string::find (charT c, size_t pos) const _THROW_NONE +{ + while ((pos < length()) && (baggage_type::ne(*(data()+pos), c))) + ++pos; + return ((pos < length()) ? pos : NPOS); +} + +template +size_t +basic_string::rfind (const basic_string& str, size_t pos) const + _THROW_NONE +{ + return rfind_str (str.data(), pos, str.length()); +} + +template +size_t +basic_string::rfind (const charT* s, size_t pos, size_t n) const + _THROW_NONE +{ + return rfind_str (s, pos, n); +} + +template +size_t +basic_string::rfind (const charT* s, size_t pos) const _THROW_NONE +{ + return rfind_str (s, pos, baggage_type::length(s)); +} + +template +size_t +basic_string::rfind (charT c, size_t pos) const _THROW_NONE +{ + size_t count = ((pos < length()) ? pos+1 : length()); + if (length() == 0) + return NPOS; + while ((baggage_type::ne(*(data()+count-1), c)) && (count > 1)) + --count; + if ((count == 1) && (baggage_type::ne(*(data()), c))) + return NPOS; + else + return count-1; +} + +template +size_t +basic_string::find_first_of (const basic_string& str, size_t pos) const + _THROW_NONE +{ + return find_first_of_str (str.data(), pos, str.length()); +} + +template +size_t +basic_string::find_first_of (const charT* s, size_t pos, size_t n) const + _THROW_NONE +{ + return find_first_of_str (s, pos, n); +} + +template +size_t +basic_string::find_first_of (const charT* s, size_t pos) const + _THROW_NONE +{ + return find_first_of_str (s, pos, baggage_type::length(s)); +} + +template +size_t +basic_string::find_first_of (charT c, size_t pos) const _THROW_NONE +{ + return find (c, pos); +} + +template +size_t +basic_string::find_last_of (const basic_string& str, size_t pos) const + _THROW_NONE +{ + return find_last_of_str (str.data(), pos, str.length()); +} + +template +size_t +basic_string::find_last_of (const charT* s, size_t pos, size_t n) const + _THROW_NONE +{ + return find_last_of_str (s, pos, n); +} + +template +size_t +basic_string::find_last_of (const charT* s, size_t pos) const _THROW_NONE +{ + return find_last_of_str (s, pos, baggage_type::length(s)); +} + +template +size_t +basic_string::find_last_of (charT c, size_t pos) const _THROW_NONE +{ + return rfind (c, pos); +} + +template +size_t +basic_string::find_first_not_of (const basic_string& str, size_t pos) + const _THROW_NONE +{ + return find_first_not_of_str (str.data(), pos, str.length()); +} + +template +size_t +basic_string::find_first_not_of (const charT* s, size_t pos, size_t n) + const _THROW_NONE +{ + return find_first_not_of_str (s, pos, n); +} + +template +size_t +basic_string::find_first_not_of (const charT* s, size_t pos) const + _THROW_NONE +{ + return find_first_not_of_str (s, pos, baggage_type::length(s)); +} + +template +size_t +basic_string::find_first_not_of (charT c, size_t pos) const _THROW_NONE +{ + while ((pos < length()) && (baggage_type::eq(*(data()+pos), c))) + ++pos; + return ((pos < length()) ? pos : NPOS); +} + +template +size_t +basic_string::find_last_not_of (const basic_string& str, size_t pos) + const _THROW_NONE +{ + return find_last_not_of_str (str.data(), pos, str.length()); +} + +template +size_t +basic_string::find_last_not_of (const charT* s, size_t pos, size_t n) + const _THROW_NONE +{ + return find_last_not_of_str (s, pos, n); +} + +template +size_t +basic_string::find_last_not_of (const charT* s, size_t pos) const + _THROW_NONE +{ + return find_last_not_of_str (s, pos, baggage_type::length(s)); +} + +template +size_t +basic_string::find_last_not_of (charT c, size_t pos) const _THROW_NONE +{ + size_t count = ((pos < length()) ? pos+1 : length()); + if (length() == 0) + return NPOS; + while ((baggage_type::eq(*(data()+count-1), c)) && (count > 1)) + --count; + if ((count == 1) && (baggage_type::eq(*(data()), c))) + return NPOS; + else + return count-1; +} + +template +basic_string +basic_string::substr (size_t pos, size_t n) const _THROW_ALLOC_OUTRANGE +{ + if (pos > length()) + { + reference_class::throwrange(); + } + if (length()) + return basic_string (data()+pos, + (n > (length()-pos)) ? (length()-pos) : n); + else + return basic_string(); +} + +template +int +basic_string::compare (const basic_string& str, size_t pos, + size_t n) const _THROW_OUTRANGE +{ + size_t slen = (n > (length()-pos)) ? (length()-pos) : n; + return compare_str (pos, str.data(), slen, str.length()); +} + +template +int +basic_string::compare (const charT* s, size_t pos, size_t n) const + _THROW_LENGTH_OUTRANGE +{ + if (n == NPOS) + { + reference_class::throwlength(); + } + return compare_str (pos, s, length()-pos, n); +} + +template +int +basic_string::compare (const charT* s, size_t pos) const _THROW_OUTRANGE +{ + return compare_str (pos, s, length()-pos, baggage_type::length(s)); +} + +template +int +basic_string::compare (charT c, size_t pos, size_t rep) const + _THROW_LENGTH_OUTRANGE +{ + if (pos > length()) + { + reference_class::throwrange(); + } + if (rep == NPOS) + { + reference_class::throwlength(); + } + if (rep) + { + size_t count = 0; + while ((count < rep) && (count < (length()-pos)) && + baggage_type::eq (*(data()+pos+count), c)) + ++count; + if ((count == rep) || (count == (length()-pos))) + return (length()-pos-count); + else + return (*(data()+pos+count)-c); + } + else + { + return (length()-pos); + } +} + +template +basic_string +basic_string::op_plus (const basic_string& lhs, + const basic_string& rhs) + _THROW_ALLOC_LENGTH +{ + typedef basic_string::baggage_type baggage_type; + basic_string tmp(lhs.data(), lhs.length(), rhs.length()); + if (rhs.length()) + baggage_type::copy (tmp.point()+lhs.length(), rhs.data(), rhs.length()); + tmp.len() += rhs.length(); + return tmp; +} + +template +basic_string +basic_string::op_plus (const charT* lhs, + const basic_string& rhs) + _THROW_ALLOC_LENGTH +{ + typedef basic_string::baggage_type baggage_type; + size_t slen = baggage_type::length(lhs); + basic_string tmp(lhs, slen, rhs.length()); + if (rhs.length()) + baggage_type::copy (tmp.point()+slen, rhs.data(), rhs.length()); + tmp.len() += rhs.length(); + return tmp; +} + +template +basic_string +basic_string::op_plus (charT lhs, const basic_string& rhs) + _THROW_ALLOC_LENGTH +{ + typedef basic_string::baggage_type baggage_type; + basic_string tmp(&lhs, 1, rhs.length()); + if (rhs.length()) + baggage_type::copy (tmp.point()+1, rhs.data(), rhs.length()); + tmp.len() += rhs.length(); + return tmp; +} + +template +basic_string +basic_string::op_plus (const basic_string& lhs, const charT* rhs) + _THROW_ALLOC_LENGTH +{ + typedef basic_string::baggage_type baggage_type; + size_t slen = baggage_type::length(rhs); + basic_string tmp(lhs.data(), lhs.length(), slen); + if (slen) + baggage_type::copy (tmp.point()+lhs.length(), rhs, slen); + tmp.len() += slen; + return tmp; +} + +template +basic_string +basic_string::op_plus (const basic_string& lhs, charT rhs) + _THROW_ALLOC_LENGTH +{ + typedef basic_string::baggage_type baggage_type; + basic_string tmp(lhs.data(), lhs.length(), 1); + baggage_type::assign (*(tmp.point()+lhs.length()), rhs); + ++tmp.len(); + return tmp; +} + +/* +template +ostream& +basic_string::op_lshift (ostream& o, const basic_string& s) + _THROW_NONE +{ + typedef basic_string::baggage_type baggage_type; + for (size_t count = 0; count < s.length(); ++count) + baggage_type::char_out (o, *(s.data()+count)); + return o; +} + +template +istream& +basic_string::op_rshift (istream& i, basic_string& s) + _THROW_ALLOC_LENGTH +{ + typedef basic_string::baggage_type baggage_type; + s.remove(); + while (true) + { + charT value; + baggage_type::char_in (i, value); + if (!i.operator void*()) + break; + if (!baggage_type::is_del (value)) + { + s.append(value); + while (true) + { + baggage_type::char_in (i, value); + if (!i.operator void*()) + break; + if (!baggage_type::is_del (value)) + { + s.append(value); + } + else + break; + } + break; + } + } + return i; +} +*/ + +template +inline basic_string +operator+ (const basic_string& lhs, const basic_string& rhs) + _THROW_ALLOC_LENGTH +{ + return basic_string::op_plus (lhs, rhs); +} + +template +inline basic_string +operator+ (const charT* lhs, const basic_string& rhs) + _THROW_ALLOC_LENGTH +{ + return basic_string::op_plus (lhs, rhs); +} + +template +inline basic_string +operator+ (charT lhs, const basic_string& rhs) + _THROW_ALLOC_LENGTH +{ + return basic_string::op_plus (lhs, rhs); +} + +template +inline basic_string +operator+ (const basic_string& lhs, const charT* rhs) + _THROW_ALLOC_LENGTH +{ + return basic_string::op_plus (lhs, rhs); +} + +template +inline basic_string +operator+ (const basic_string& lhs, charT rhs) + _THROW_ALLOC_LENGTH +{ + return basic_string::op_plus (lhs, rhs); +} +/* +template +inline ostream& +operator<< (ostream& o, const basic_string& s) + _THROW_NONE +{ + return basic_string::op_lshift (o, s); +} + +template +inline istream& +operator>> (istream& i, basic_string& s) + _THROW_ALLOC_LENGTH +{ + return basic_string::op_rshift (i, s); +} +*/ + + +typedef basic_string cstring; +typedef basic_string string; +// typedef basic_string 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 + +#endif diff --git a/ministl/defalloc.h b/ministl/defalloc.h new file mode 100644 index 00000000..3298b219 --- /dev/null +++ b/ministl/defalloc.h @@ -0,0 +1,83 @@ +/* + * + * 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 DEFALLOC_H +#define DEFALLOC_H + + +template +inline void destroy(T* pointer) +{ + pointer->~T(); +} + +static inline void destroy(char*) {} +static inline void destroy(unsigned char*) {} +static inline void destroy(short*) {} +static inline void destroy(unsigned short*) {} +static inline void destroy(int*) {} +static inline void destroy(unsigned int*) {} +static inline void destroy(long*) {} +static inline void destroy(unsigned long*) {} +static inline void destroy(float*) {} +static inline void destroy(double*) {} +static inline void destroy(char**) {} +static inline void destroy(unsigned char**) {} +static inline void destroy(short**) {} +static inline void destroy(unsigned short**) {} +static inline void destroy(int**) {} +static inline void destroy(unsigned int**) {} +static inline void destroy(long**) {} +static inline void destroy(unsigned long**) {} +static inline void destroy(float**) {} +static inline void destroy(double**) {} + + +template +inline void destroy(T* beg, T* end) +{ + for ( ; beg != end; ++beg) + beg->~T(); +} + +static inline void destroy(char*, char*) {} +static inline void destroy(unsigned char*, unsigned char*) {} +static inline void destroy(short*, short*) {} +static inline void destroy(unsigned short*, unsigned short*) {} +static inline void destroy(int*, int*) {} +static inline void destroy(unsigned int*, unsigned int*) {} +static inline void destroy(long*, long*) {} +static inline void destroy(unsigned long*, unsigned long*) {} +static inline void destroy(float*, float*) {} +static inline void destroy(double*, double*) {} +static inline void destroy(char**, char**) {} +static inline void destroy(unsigned char**, unsigned char**) {} +static inline void destroy(short**, short**) {} +static inline void destroy(unsigned short**, unsigned short**) {} +static inline void destroy(int**, int**) {} +static inline void destroy(unsigned int**, unsigned int**) {} +static inline void destroy(long**, long**) {} +static inline void destroy(unsigned long**, unsigned long**) {} +static inline void destroy(float**, float**) {} +static inline void destroy(double**, double**) {} + +#if defined (__GNUG__) +static inline void *operator new(size_t, void *place) { return place; } +static inline void *operator new[](size_t, void *place) { return place; } +#else +#include +#endif + +#endif diff --git a/ministl/function b/ministl/function new file mode 100644 index 00000000..03160c59 --- /dev/null +++ b/ministl/function @@ -0,0 +1,23 @@ +/* + * 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: + * mico@informatik.uni-frankfurt.de + */ + +#include diff --git a/ministl/function.h b/ministl/function.h new file mode 100644 index 00000000..b52d2e11 --- /dev/null +++ b/ministl/function.h @@ -0,0 +1,285 @@ +/* + * + * 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 +#endif + +#if 0 +template +inline bool operator!=(const T1& x, const T2& y) { + return !(x == y); +} +#endif + +template +inline bool operator>(const T1& x, const T2& y) { + return y < x; +} + +template +inline bool operator<=(const T1& x, const T2& y) { + return !(y < x); +} + +template +inline bool operator>=(const T1& x, const T2& y) { + return !(x < y); +} + +template +struct unary_function { + typedef Arg argument_type; + typedef Result result_type; +}; + +template +struct binary_function { + typedef Arg1 first_argument_type; + typedef Arg2 second_argument_type; + typedef Result result_type; +}; + +template +struct plus : binary_function { + T operator()(const T& x, const T& y) const { return x + y; } +}; + +template +struct minus : binary_function { + T operator()(const T& x, const T& y) const { return x - y; } +}; + +template +struct multiplies : binary_function { + T operator()(const T& x, const T& y) const { return x * y; } +}; + +template +struct divides : binary_function { + T operator()(const T& x, const T& y) const { return x / y; } +}; + +template +#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 operator()(const T& x, const T& y) const { return x % y; } +}; +#endif + +template +struct negate : unary_function { + T operator()(const T& x) const { return -x; } +}; + +template +struct equal_to : binary_function { + bool operator()(const T& x, const T& y) const { return x == y; } +}; + +template +struct not_equal_to : binary_function { + bool operator()(const T& x, const T& y) const { return x != y; } +}; + +template +struct greater : binary_function { + bool operator()(const T& x, const T& y) const { return x > y; } +}; + +template +struct less : binary_function { + bool operator()(const T& x, const T& y) const { return x < y; } +}; + +template +struct greater_equal : binary_function { + bool operator()(const T& x, const T& y) const { return x >= y; } +}; + +template +struct less_equal : binary_function { + bool operator()(const T& x, const T& y) const { return x <= y; } +}; + +template +struct logical_and : binary_function { + bool operator()(const T& x, const T& y) const { return x && y; } +}; + +template +struct logical_or : binary_function { + bool operator()(const T& x, const T& y) const { return x || y; } +}; + +template +struct logical_not : unary_function { + bool operator()(const T& x) const { return !x; } +}; + +template +class unary_negate : public unary_function { +protected: + Predicate pred; +public: + unary_negate(const Predicate& x) : pred(x) {} + bool operator()(const typename Predicate::argument_type& x) const + { return !pred(x); } +}; + +template +unary_negate not1(const Predicate& pred) { + return unary_negate(pred); +} + +template +class binary_negate + : public binary_function { +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 +binary_negate not2(const Predicate& pred) { + return binary_negate(pred); +} + +template +class binder1st : public unary_function { +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 +binder1st bind1st(const Operation& op, const T& x) { + return binder1st(op, Operation::first_argument_type(x)); +} + +template +class binder2nd : public unary_function { +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 +binder2nd bind2nd(const Operation& op, const T& x) { + return binder2nd(op, Operation::second_argument_type(x)); +} + +template +class unary_compose : public unary_function { +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 +unary_compose compose1(const Operation1& op1, + const Operation2& op2) { + return unary_compose(op1, op2); +} + +template +class binary_compose : public unary_function { +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 +binary_compose +compose2(const Operation1& op1, const Operation2& op2, const Operation3& op3) { + return binary_compose(op1, op2, op3); +} + +template +class pointer_to_unary_function : public unary_function { +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 +pointer_to_unary_function ptr_fun(Result (*x)(Arg)) { + return pointer_to_unary_function(x); +} + +template +class pointer_to_binary_function : public binary_function { +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 +pointer_to_binary_function +ptr_fun(Result (*x)(Arg1, Arg2)) { + return pointer_to_binary_function(x); +} + +#endif diff --git a/ministl/list b/ministl/list new file mode 100644 index 00000000..d0dc0558 --- /dev/null +++ b/ministl/list @@ -0,0 +1,23 @@ +/* + * 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: + * mico@informatik.uni-frankfurt.de + */ + +#include diff --git a/ministl/list.h b/ministl/list.h new file mode 100644 index 00000000..98f21559 --- /dev/null +++ b/ministl/list.h @@ -0,0 +1,416 @@ +// -*- 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: + * mico@informatik.uni-frankfurt.de + */ + +#ifndef __ministl_list_h__ +#define __ministl_list_h__ + +#include +#ifndef __GNUG__ +#include +#endif + +template +class listNode { + listNode *_prev, *_next; + T _data; +public: + listNode (const T &data = T(), listNode *next = 0, + listNode *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 *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 *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 *next () + { + return _next; + } + listNode *prev () + { + return _prev; + } +}; + +template class list; +template class listConstIterator; + +template +class listIterator { + friend class list; + friend class listConstIterator; + typedef listNode node; + node *n; + listIterator (node *_n) + : n (_n) + { + } +public: + listIterator () + : n (0) + { + } + bool operator== (const listIterator &it) const + { + return it.n == n; + } + bool operator!= (const listIterator &it) const + { + return !(it.n == n); + } + listIterator operator++ () + { + n = n->next(); + ministl_assert (n); + return *this; + } + listIterator operator++ (int) + { + listIterator tmp = *this; + n = n->next(); + ministl_assert (n); + return tmp; + } + listIterator operator-- () + { + n = n->prev(); + ministl_assert (n); + return *this; + } + listIterator operator-- (int) + { + listIterator tmp = *this; + n = n->prev(); + ministl_assert (n); + return tmp; + } + T &operator* () + { + return n->data(); + } +}; + +template +class listConstIterator { + friend class list; + typedef listNode node; + node *n; + listConstIterator (node *_n) + : n (_n) + { + } +public: + listConstIterator () + : n (0) + { + } + listConstIterator (const listIterator &i) + : n (i.n) + { + } + bool operator== (const listConstIterator &it) const + { + return it.n == n; + } + bool operator!= (const listConstIterator &it) const + { + return !(it.n == n); + } + listConstIterator operator++ () + { + n = n->next(); + ministl_assert (n); + return *this; + } + listConstIterator operator++ (int) + { + listConstIterator tmp = *this; + n = n->next(); + ministl_assert (n); + return tmp; + } + listConstIterator operator-- () + { + n = n->prev(); + ministl_assert (n); + return *this; + } + listConstIterator operator-- (int) + { + listConstIterator tmp = *this; + n = n->prev(); + ministl_assert (n); + return tmp; + } + const T &operator* () const + { + return n->data(); + } +}; + +template +class list { + typedef listNode node; +public: + typedef unsigned long size_type; + typedef listIterator iterator; + typedef listConstIterator 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 list_T; + list (const list_T &list) + : _length (0) + { + _begin = _end = new node (); + insert (begin(), list.begin(), list.end()); + } + list &operator= (const list &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 +bool operator== (const list &v1, const list &v2) +{ + if (v1.size() != v2.size()) + return false; + typename list::const_iterator i1 = v1.begin(); + typename list::const_iterator i2 = v2.begin(); + for ( ;i1 != v1.end() && i2 != v2.end(); ++i1, ++i2) { + if (!(*i1 == *i2)) + return false; + } + return true; +} + +template +bool operator< (const list &v1, const list &v2) +{ + long minlast = _min_ (v1.size(), v2.size()); + typename list::const_iterator i1 = v1.begin(); + typename list::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__ diff --git a/ministl/map b/ministl/map new file mode 100644 index 00000000..a793a804 --- /dev/null +++ b/ministl/map @@ -0,0 +1,23 @@ +/* + * 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: + * mico@informatik.uni-frankfurt.de + */ + +#include diff --git a/ministl/map.h b/ministl/map.h new file mode 100644 index 00000000..7e67045a --- /dev/null +++ b/ministl/map.h @@ -0,0 +1,374 @@ +// -*- 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: + * mico@informatik.uni-frankfurt.de + */ + +#ifndef __ministl_map_h__ +#define __ministl_map_h__ + +#include +#include +#include +#include +#ifndef __GNUG__ +#include +#endif + +template class map; +template class mapConstIterator; + +template +class mapIterator { + friend class map; + friend class mapConstIterator; + typedef mapIterator my_type; + typedef pair value_type; + typedef simplevec 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 mapConstIterator { + friend class map; + typedef mapConstIterator my_type; + typedef pair value_type; + typedef simplevec rep_type; + typedef typename rep_type::const_iterator repiterator; + repiterator n; + + mapConstIterator (repiterator _n) + : n (_n) + { + } +public: + mapConstIterator () + : n (0) + { + } + mapConstIterator (const mapIterator &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 map { +public: + typedef keyT key_type; + typedef pair value_type; + typedef unsigned long size_type; + typedef simplevec rep_type; + typedef mapIterator iterator; + typedef mapConstIterator const_iterator; + // XXX typedefs done to work around g++ bug + typedef pair 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 &m) + : _comp (m._comp) + { + insert (m.begin(), m.end()); + } + map &operator= (const map &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 +inline bool +map::lookup (const kT &k, mapIterator &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 (_ents.begin()+m); + return true; + } + r = m; + } + } + ministl_assert (l == r); + it = mapIterator (_ents.begin()+l); + return l < (int)size() && + // (*it).first == k; + !_comp ((*it).first, k) && !_comp (k, (*it).first); +} + +template +bool operator== (const map &v1, const map &v2) +{ + if (v1.size() != v2.size()) + return false; + typename map::const_iterator i1 = v1.begin(); + typename map::const_iterator i2 = v2.begin(); + for ( ;i1 != v1.end() && i2 != v2.end(); ++i1, ++i2) { + if (!(*i1 == *i2)) + return false; + } + return true; +} + +template +bool operator< (const map &v1, const map &v2) +{ + long minlast = _min_ (v1.size(), v2.size()); + typename map::const_iterator i1 = v1.begin(); + typename map::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__ diff --git a/ministl/ministl.h b/ministl/ministl.h new file mode 100644 index 00000000..8dff5553 --- /dev/null +++ b/ministl/ministl.h @@ -0,0 +1,48 @@ +// -*- 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: + * mico@informatik.uni-frankfurt.de + */ + +#ifndef __ministl_ministl_h__ +#define __ministl_ministl_h__ + +#ifndef assert +#include +#endif + + +#ifdef MINISTL_NDEBUG +#define ministl_assert(exp) +#else +#define ministl_assert(exp) assert(exp) +#endif + +static inline long _min_ (long x, long y) +{ + return x < y ? x : y; +} + +static inline long _max_ (long x, long y) +{ + return x > y ? x : y; +} + +#endif // __ministl_ministl_h__ diff --git a/ministl/pair b/ministl/pair new file mode 100644 index 00000000..cdea0f36 --- /dev/null +++ b/ministl/pair @@ -0,0 +1,23 @@ +/* + * 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: + * mico@informatik.uni-frankfurt.de + */ + +#include diff --git a/ministl/pair.h b/ministl/pair.h new file mode 100644 index 00000000..cd2b40cd --- /dev/null +++ b/ministl/pair.h @@ -0,0 +1,51 @@ +/* + * + * 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 +#endif + +template +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 +inline bool operator==(const pair& x, const pair& y) { + return x.first == y.first && x.second == y.second; +} + +template +inline bool operator<(const pair& x, const pair& y) { + return x.first < y.first || (!(y.first < x.first) && x.second < y.second); +} + +template +inline pair make_pair(const T1& x, const T2& y) { + return pair(x, y); +} + +#endif diff --git a/ministl/set b/ministl/set new file mode 100644 index 00000000..cd5cae26 --- /dev/null +++ b/ministl/set @@ -0,0 +1,23 @@ +/* + * 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: + * mico@informatik.uni-frankfurt.de + */ + +#include diff --git a/ministl/set.h b/ministl/set.h new file mode 100644 index 00000000..c8f6a7db --- /dev/null +++ b/ministl/set.h @@ -0,0 +1,368 @@ +// -*- 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: + * mico@informatik.uni-frankfurt.de + */ + +#ifndef __ministl_set_h__ +#define __ministl_set_h__ + +#include +#include +#include +#include +#ifndef __GNUG__ +#include +#endif + +template class set; +template class setConstIterator; + +template +class setIterator { + friend class set; + friend class setConstIterator; + typedef setIterator my_type; + typedef vT value_type; + typedef simplevec 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 setConstIterator { + friend class set; + typedef setConstIterator my_type; + typedef vT value_type; + typedef simplevec rep_type; + typedef typename rep_type::const_iterator repiterator; + repiterator n; + + setConstIterator (repiterator _n) + : n (_n) + { + } +public: + setConstIterator () + : n (0) + { + } + setConstIterator (const setIterator &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 set { +public: + typedef valT value_type; + typedef unsigned long size_type; + typedef simplevec rep_type; + typedef setIterator iterator; + typedef setConstIterator const_iterator; + // XXX typedefs done to work around g++ bug + typedef pair 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 &m) + : _comp (m._comp) + { + insert (m.begin(), m.end()); + } + set &operator= (const set &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 +inline bool +set::lookup (const vT &k, setIterator &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 (_ents.begin()+m); + return true; + } + r = m; + } + } + ministl_assert (l == r); + it = setIterator (_ents.begin()+l); + return l < (int)size() && + // k == *it + !_comp (*it, k) && !_comp (k, *it); +} + +template +bool operator== (const set &v1, const set &v2) +{ + if (v1.size() != v2.size()) + return false; + typename set::const_iterator i1 = v1.begin(); + typename set::const_iterator i2 = v2.begin(); + for ( ;i1 != v1.end() && i2 != v2.end(); ++i1, ++i2) { + if (!(*i1 == *i2)) + return false; + } + return true; +} + +template +bool operator< (const set &v1, const set &v2) +{ + long minlast = _min_ (v1.size(), v2.size()); + typename set::const_iterator i1 = v1.begin(); + typename set::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__ diff --git a/ministl/simplevec.h b/ministl/simplevec.h new file mode 100644 index 00000000..45f7630a --- /dev/null +++ b/ministl/simplevec.h @@ -0,0 +1,270 @@ +// -*- 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: + * mico@informatik.uni-frankfurt.de + */ + +#ifndef __ministl_simplevec_h__ +#define __ministl_simplevec_h__ + +#include +#ifndef __GNUG__ +#include +#endif +#include + + +template +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) : _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) + { + } + simplevec (size_type n, const T& t = T()) + : _last (0), _size (0), _buf (0) + { + insert (begin(), n, t); + } + simplevec (const_iterator first, const_iterator last) + : _last (0), _size (0), _buf (0) + { + insert (begin(), first, last); + } + simplevec (const simplevec &v) + : _last (0), _size (0), _buf (0) + { + reserve (v._last); + memcpy (_buf, v.begin(), v.size()*sizeof(T)); + _last = v._last; + } + simplevec &operator= (const simplevec &v) + { + if (this != &v) { + _last = 0; + reserve (v._last); + memcpy (_buf, v.begin(), v.size()*sizeof(T)); + _last = v._last; + } + return *this; + } + ~simplevec () + { + 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 () + { + _last = 0; + } + void push_back (const T &t) + { + reserve (_last+1); + *end() = t; + ++_last; + } + void pop_back () + { + //ministl_assert (size() > 0); + --_last; + } + 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; + *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; + } + 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; + } + void erase (iterator first, iterator last) + { + 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; + } + } +}; + +template +bool operator== (const simplevec &v1, const simplevec &v2) +{ + if (v1.size() != v2.size()) + return false; + return !v1.size() || !memcmp (&v1[0], &v2[0], v1.size()*sizeof(T)); +} + +template +bool operator< (const simplevec &v1, const simplevec &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(); +} + +#endif diff --git a/ministl/string b/ministl/string new file mode 100644 index 00000000..f9fc96bd --- /dev/null +++ b/ministl/string @@ -0,0 +1,23 @@ +/* + * 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: + * mico@informatik.uni-frankfurt.de + */ + +#include diff --git a/ministl/vector b/ministl/vector new file mode 100644 index 00000000..035fb842 --- /dev/null +++ b/ministl/vector @@ -0,0 +1,23 @@ +/* + * 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: + * mico@informatik.uni-frankfurt.de + */ + +#include diff --git a/ministl/vector.h b/ministl/vector.h new file mode 100644 index 00000000..a6e4d648 --- /dev/null +++ b/ministl/vector.h @@ -0,0 +1,318 @@ +// -*- 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: + * mico@informatik.uni-frankfurt.de + */ + +#ifndef __ministl_vector_h__ +#define __ministl_vector_h__ + +#include +#ifndef __GNUG__ +#include +#endif +#include + + +template +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 &v) + : _last (0), _size (0), _buf (0) + { + reserve (v._last); + construct (begin(), v.begin(), v.end()); + _last = v._last; + } + vector &operator= (const vector &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 +bool operator== (const vector &v1, const vector &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 +bool operator< (const vector &v1, const vector &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(); +} + +#endif