📄 pixmapdatadictc.c
字号:
/* Loop through the list until the entry is found *//* Compare actual objects */ register int i; for (i=0; (i<_count && (_list[i] != obj)); i++); if (i == _count) { return NULL_INDEX; } return i;}/*-------------------------------------------------------------*/PixmapDataDictCEntry*PixmapDataDictCEntryList::insert(const PixmapDataDictCEntry& obj, unsigned i){/* If this list is sorted, ignore the given index and compute the real one */ if ( sorted ) i = orderOf(obj);/* Otherwise, see if index is valid */ if (i > _count) return (PixmapDataDictCEntry*)NULL;/* Don't allow same address in list twice */ if ( !allow_duplicates && includes(obj) ) return (PixmapDataDictCEntry*)NULL;/* See if there is enough space for another entry */ if ( _count >= _space ) grow();/* Insert entry in position i *//* Make a space for the new entry by moving all others back */ register int j; for (j=_count; j>i; j--) { _list[j] = _list[j-1]; /* Copying objects here */ } _count++; PixmapDataDictCEntry *tp = (PixmapDataDictCEntry *)&obj;/* Copy the object to the list object */ _list[i] = *tp; return &_list[i];}/*-------------------------------------------------------------*/voidPixmapDataDictCEntryList::remove(unsigned index){ if (index < _count) { /* Move entries forward in list and overwrite this one */ register int i; for (i=index+1; i<_count; i++) { _list[i-1] = _list[i]; /* Copying objects here */ } _count--; if ( autoShrink ) shrink(); }}/*-------------------------------------------------------------*/voidPixmapDataDictCEntryList::remove(const PixmapDataDictCEntry& obj){/* Look up this entry */ register unsigned i = indexOf(obj); if ( i != NULL_INDEX ) remove(i);}/*-------------------------------------------------------------*//* Return a pointer to the list entry just before this one */PixmapDataDictCEntry*PixmapDataDictCEntryList::before(const PixmapDataDictCEntry& obj) const{/* Look up this entry */ register int i = indexOf(obj); if ( i == NULL_INDEX || i == 0 ) return (PixmapDataDictCEntry*)NULL; return &_list[i-1];}/*-------------------------------------------------------------*/unsignedPixmapDataDictCEntryList::orderOf(const PixmapDataDictCEntry& obj) const{/* * This algorithm is a simple binary search * If the object is in the list, the index of the object is returned. * If the object is not in the list, the index where the object would fit * iN THE SOrting order is returned. *//* Check special cases first */ if ( _count == 0 || obj < _list[0] ) return 0; if ( obj > _list[_count-1] ) return _count; int low = 0; int high = _count - 1; int mid = 0; while ( low <= high ) { mid = (low + high) / 2; /*int comp = obj.compare(_list[mid]); */ int comp = (obj < _list[mid]) ? -1 : ((obj > _list[mid]) ? 1 : 0); if ( comp > 0 ) low = mid + 1; else if (comp == 0) return mid; else high = mid - 1; }/* * If the last comparison said the value was greater than the mid, * then we want to return an index 1 greater than the mid because * the entry should get inserted after the mid. */ if (low > mid) mid++; return mid;} /* End PixmapDataDictCEntryList::orderOf *//*-------------------------------------------------------------*/intPixmapDataDictCEntryList::compare(const void *a, const void *b){ PixmapDataDictCEntry *ta = (PixmapDataDictCEntry *)a; PixmapDataDictCEntry *tb = (PixmapDataDictCEntry *)b; /* return ta->compare(*tb); */ return (*ta < *tb) ? -1 : ((*ta > *tb) ? 1 : 0);}/*-------------------------------------------------------------*/voidPixmapDataDictCEntryList::sort(){ qsort((void *)_list, (size_t)_count, (size_t)sizeof(PixmapDataDictCEntry), (int (*)(const void*, const void*))compare);}/*-------------------------------------------------------------*/voidPixmapDataDictCEntryList::sort(int (*compar)(const void*, const void*)){ if ( !compar ) return; qsort((void *)_list, (size_t)_count, (size_t)sizeof(PixmapDataDictCEntry), compar);}/* * 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. *//* * ODictC.meth -- method definition file for class ODictC * * This type of list store the members themselves * PDictC stores only pointers to the members *//* Copy one dictionary to another */PixmapDataDictC&PixmapDataDictC::operator=(const PixmapDataDictC& d){ if ( this != &d ) { _count = 0; register int count = d.size();//// Add each entry in source to destination// register int i; for (i=0; i<count; i++) { PixmapDataDictCEntry *e = d[i]; add(e->key, e->val); } } return *this;}/* Lookup up entries */intPixmapDataDictC::indexOf(const PixmapDataDictCEntry& entry) const{ return PixmapDataDictCEntryList::indexOf(entry);}intPixmapDataDictC::includes(const PtrT& key) const{ return (indexOf(key) != NULL_INDEX);}intPixmapDataDictC::includes(const PixmapDataDictCEntry& entry) const{ return PixmapDataDictCEntryList::includes(entry);}/* Deleting entries */voidPixmapDataDictC::remove(unsigned index){ PixmapDataDictCEntryList::remove(index);}voidPixmapDataDictC::remove(PixmapDataDictCEntry& entry){ PixmapDataDictCEntryList::remove(entry);}/*-------------------------------------------------------------*/intPixmapDataDictC::indexOf(const PtrT& key) const{/* Loop through list, checking keys for a match */ register int i; for (i=0; i<_count; i++) {/* If this one matches, return the index */ if ( _list[i].key == key ) { return i; } } return NULL_INDEX;}/*-------------------------------------------------------------*/PixmapPtrT*PixmapDataDictC::definitionOf(const PtrT& key) const{ int i = indexOf(key); /* Look up this entry */ return ((i==NULL_INDEX) ? (PixmapPtrT*)NULL : &_list[i].val);}/*-------------------------------------------------------------*/PtrT&PixmapDataDictC::keyOf(const int index) const{ return _list[index].key;}/*-------------------------------------------------------------*/PixmapPtrT&PixmapDataDictC::valOf(const int index) const{ return _list[index].val;}/*-------------------------------------------------------------*/PixmapDataDictCEntry*PixmapDataDictC::entryOf(const PtrT& key) const{ int i = indexOf(key); /* Get index of key */ return ((i==NULL_INDEX) ? (PixmapDataDictCEntry*)NULL : &_list[i]);}/*-------------------------------------------------------------*/PixmapDataDictCEntry*PixmapDataDictC::add(const PtrT& key, const PixmapPtrT& val){/* Check if this entry is already present */ if ( includes(key) ) { if ( *definitionOf(key) != val ) { return (PixmapDataDictCEntry*)NULL; /* Same key with different value */ } else { return entryOf(key); } } else { /* Add it */ PixmapDataDictCEntry ent(key, val); return append(ent); }}/*-------------------------------------------------------------*//* Change the definition for this key */PixmapDataDictCEntry*PixmapDataDictC::modify(const PtrT& key, const PixmapPtrT& val){ int i = indexOf(key); /* Look up this entry */ if ( i == NULL_INDEX ) { return (PixmapDataDictCEntry*)NULL; } else { _list[i].val = val; /* Change it */ return &_list[i]; }}/*-------------------------------------------------------------*/PixmapDataDictCEntry*PixmapDataDictC::modify(unsigned index, const PixmapPtrT& val){ if (index < _count) { _list[index].val = val; /* Change it */ return &_list[index]; } else { return (PixmapDataDictCEntry*)NULL; }}/*-------------------------------------------------------------*/voidPixmapDataDictC::remove( PtrT& key){ int i = indexOf(key); /* Look up this entry */ if ( i != NULL_INDEX ) { PixmapDataDictCEntryList::remove(i); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -