⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 partialmsgdictc.c

📁 linux下的E_MAIL客户端源码
💻 C
📖 第 1 页 / 共 2 页
字号:
//// PartialMsgDictC.C//#include <config.h>#include "PartialMsgDictC.h"/*  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. *                  1315 Dell Avenue *                  Campbell, CA  95008 * * Author: Greg Hilton * Contributors: Tom Lang, Frank Bieser, and others * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program 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 General Public License for more details. * * http://www.gnu.org/copyleft/gpl.html * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. *//* * OListC.meth -- method definition file for class OListC * *   This type of list store the members themselves *   PListC stores only pointers to the members */#include <stdlib.h>	// For qsort#ifndef FALSE#define FALSE	0#define TRUE	(!FALSE)#endif/*------------------------------------------------------------------------ * PartialMsgDictCEntryList constructors */PartialMsgDictCEntryList::PartialMsgDictCEntryList() : GROWTH_AMOUNT(4), NULL_INDEX(-1), MAX_GROWTH(32768){   _list		= (PartialMsgDictCEntry*)NULL;   _count		= 0;   _space		= 0;   allow_duplicates	= FALSE;   sorted		= FALSE;   adjustGrowth		= TRUE;   autoShrink		= TRUE;}PartialMsgDictCEntryList::PartialMsgDictCEntryList(unsigned ga) : GROWTH_AMOUNT(ga), NULL_INDEX(-1), MAX_GROWTH(ga){   _list		= (PartialMsgDictCEntry*)NULL;   _count		= 0;   _space		= 0;   allow_duplicates	= FALSE;   sorted		= FALSE;   adjustGrowth		= FALSE;   autoShrink		= TRUE;}PartialMsgDictCEntryList::PartialMsgDictCEntryList(const PartialMsgDictCEntryList& l):GROWTH_AMOUNT(4), NULL_INDEX(-1), MAX_GROWTH(32768){   _list		= (PartialMsgDictCEntry*)NULL;   _count		= 0;   _space		= 0;   allow_duplicates	= FALSE;   sorted		= FALSE;   adjustGrowth		= TRUE;   autoShrink		= TRUE;   *this		= l;}/*------------------------------------------------------------------------ * PartialMsgDictCEntryList destructor */PartialMsgDictCEntryList::~PartialMsgDictCEntryList(){   if (_list) delete [] _list;}/*------------------------------------------------------------------------ * Append another list to this one */PartialMsgDictCEntryList&PartialMsgDictCEntryList::operator+=(const PartialMsgDictCEntryList& l){   if ( this != &l ) {      register int count = l.size();      register int i;      for (i=0; i<count; i++) {	 PartialMsgDictCEntry *item = l[i];	 add(*item);      }   }   return *this;}/*------------------------------------------------------------------------ * Copy another list to this one */PartialMsgDictCEntryList&PartialMsgDictCEntryList::operator=(const PartialMsgDictCEntryList& l){   if ( this != &l ) {      removeAll();      *this += l;   }   return *this;}/*------------------------------------------------------------------------ * Return non-zero if the specified object is in the list */intPartialMsgDictCEntryList::includes(const PartialMsgDictCEntry& obj) const{   return (indexOf(obj) != NULL_INDEX);}/*------------------------------------------------------------------------ * Add the specified object to the list in the requested position *    The position is ignored if this list is sorted */PartialMsgDictCEntry*PartialMsgDictCEntryList::append(const PartialMsgDictCEntry& obj){   return insert(obj, _count);}PartialMsgDictCEntry*PartialMsgDictCEntryList::prepend(const PartialMsgDictCEntry& obj){   return insert(obj, 0);}PartialMsgDictCEntry*PartialMsgDictCEntryList::add(const PartialMsgDictCEntry& obj){   return append(obj);}/*------------------------------------------------------------------------ * Remove the specified object or index from the list */voidPartialMsgDictCEntryList::removeAll(){   _count = 0;   if (autoShrink) shrink();}voidPartialMsgDictCEntryList::removeLast(){   if ( _count > 0 ) remove(_count-1);}/*------------------------------------------------------------------------ * Functions to support sorting */voidPartialMsgDictCEntryList::SetSorted(char val){   if ( sorted != val ) {      sorted = val;      if ( sorted ) sort();   }}/*------------------------------------------------------------------------ * Misc */void	PartialMsgDictCEntryList::AllowDuplicates(char val){   allow_duplicates = val;}void	PartialMsgDictCEntryList::AutoShrink(char val){   autoShrink = val;   if ( autoShrink ) shrink();}void	PartialMsgDictCEntryList::SetCapacity(unsigned count){   grow(count*sizeof(PartialMsgDictCEntry));}/*------------------------------------------------------------------------ * Indexing functions */PartialMsgDictCEntry*PartialMsgDictCEntryList::operator[](unsigned i) const{   PartialMsgDictCEntry	*tp = (PartialMsgDictCEntry*)NULL;   if (i < _count)      tp = &_list[i];   else {      cerr << "PartialMsgDictCEntryList[" << i << "]: reference out of bounds.";      if ( _count > 0 ) cerr << " Valid range is 0:" << _count-1 <<".";      else		cerr << " List is empty.";      cerr <<endl;      abort();   }   return tp;}PartialMsgDictCEntry*PartialMsgDictCEntryList::First() const{   PartialMsgDictCEntry	*tp = (PartialMsgDictCEntry*)NULL;   if ( _count > 0 ) tp = &_list[0];   return tp;}PartialMsgDictCEntry*PartialMsgDictCEntryList::Last() const{   PartialMsgDictCEntry	*tp = (PartialMsgDictCEntry*)NULL;   if ( _count > 0 ) tp = &_list[_count-1];   return tp;}/*------------------------------------------------------------------------ * Printing */ostream&PartialMsgDictCEntryList::printOn(ostream& strm) const{   for (int i=0; i<_count; i++) {      strm << _list[i] <<endl;   }   return strm;}/*-------------------------------------------------------------*/voidPartialMsgDictCEntryList::grow(unsigned newSize){/* Increase space */   if ( newSize == 0 ) {      _space += GROWTH_AMOUNT;      if ( adjustGrowth && GROWTH_AMOUNT < MAX_GROWTH ) {	 GROWTH_AMOUNT *= 2;         if ( GROWTH_AMOUNT > MAX_GROWTH ) GROWTH_AMOUNT = MAX_GROWTH;      }   }   else if ( newSize == _space ) {      return;   }   else if ( newSize < _space ) {      if ( !autoShrink ) return;      _space = newSize;      if ( newSize < _count ) _count = newSize; /* Only copy this many */   }   else {      _space = newSize;   }/* Allocate memory for new list */   PartialMsgDictCEntry	*old_list = _list;   _list = new PartialMsgDictCEntry[_space];   if ( !_list ) {      cerr << "Could not allocate memory for OListC of size: " << _space <<endl;      exit(1);   }/* Copy list to new memory */   register int i;   for (i=0; i<_count; i++) {      _list[i] = old_list[i]; /* Copying objects here */   }/* Free up old memory */   if ( old_list ) delete [] old_list;}/*-------------------------------------------------------------*/voidPartialMsgDictCEntryList::shrink(){   if ( !autoShrink ) return;/* Decrease space if necessary */   int  needed = _count * sizeof(PartialMsgDictCEntry);   if ( needed > (_space>>1) ) return;/* Start from scratch and get just as much space as necessary */   if ( adjustGrowth ) GROWTH_AMOUNT = 4;   _space = GROWTH_AMOUNT;   if ( adjustGrowth && GROWTH_AMOUNT < MAX_GROWTH ) {      GROWTH_AMOUNT *= 2;      if ( GROWTH_AMOUNT > MAX_GROWTH ) GROWTH_AMOUNT = MAX_GROWTH;   }   while ( _space < needed ) {      _space += GROWTH_AMOUNT;      if ( adjustGrowth && GROWTH_AMOUNT < MAX_GROWTH ) {	 GROWTH_AMOUNT *= 2;	 if ( GROWTH_AMOUNT > MAX_GROWTH ) GROWTH_AMOUNT = MAX_GROWTH;      }   }/* Allocate memory for new list */   PartialMsgDictCEntry	*old_list = _list;   _list = new PartialMsgDictCEntry[_space];/* Copy list to new memory */   register int i;   for (i=0; i<_count; i++) {      _list[i] = old_list[i]; /* Copying objects here */   }/* Free up old memory */   if ( old_list ) delete [] old_list;}/*-------------------------------------------------------------*/intPartialMsgDictCEntryList::indexOf(const PartialMsgDictCEntry& obj) const{/* Use the orderOf call if the list is sorted.  This should increase speed *//* for very large lists (djl) */   if (sorted) {     int i = orderOf(obj);     if (i == _count)	return NULL_INDEX;     if (_list[i] == obj)	return i;     else		        return NULL_INDEX;   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -