📄 gblock.imp
字号:
//// $Source: /home/gambit/CVS/gambit/sources/base/gblock.imp,v $// $Date: 2002/08/26 05:49:57 $// $Revision: 1.3 $//// DESCRIPTION:// Implementation of gBlock type//// This file is part of Gambit// Copyright (c) 2002, The Gambit Project//// 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.//// 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.//#include <stdlib.h>#include "gblock.h"template <class T> gBlock<T>::gBlock(unsigned int len) : gArray<T>(len) { }template <class T> gBlock<T>::gBlock(int lo, int hi) : gArray<T>(lo, hi) { }template <class T> gBlock<T>::gBlock(const gBlock<T> &b) : gArray<T>(b) { }template <class T> gBlock<T>::~gBlock() { }template <class T> gBlock<T> &gBlock<T>::operator=(const gBlock<T> &b){ gArray<T>::operator=(b); return *this;}template <class T> bool gBlock<T>::operator==(const gBlock<T> &b) const{ if (mindex != b.mindex || maxdex != b.maxdex) return false; for (int i = mindex; i <= maxdex; i++) if (data[i] != b.data[i]) return false; return true;}template <class T> bool gBlock<T>::operator!=(const gBlock<T> &b) const{ return !(*this == b);}template <class T> gBlock<T> gBlock<T>::operator+(const gBlock<T>& b) const{ gBlock<T> result(*this); for (int i = b.mindex; i <= b.maxdex; i++) result.Append(b[i]); return result;}template <class T> gBlock<T> gBlock<T>::operator+(const T &e) const{ gBlock<T> result(*this); result.Append(e); return result;}template <class T> gBlock<T> &gBlock<T>::operator+=(const T &e){ Append(e); return *this;}template <class T> gBlock<T> &gBlock<T>::operator+=(const gBlock<T> &b){ *this = *this + b; return *this;}template <class T> int gBlock<T>::InsertAt(const T &t, int n){ if (mindex > n || n > maxdex + 1) throw BadIndex(); T *new_data = new T[++maxdex - mindex + 1] - mindex; int i; for (i = mindex; i <= n - 1; i++) new_data[i] = data[i]; new_data[i++] = t; for (; i <= maxdex; i++) new_data[i] = data[i - 1]; if (data) delete [] (data + mindex); data = new_data; return n;}template <class T> int gBlock<T>::Append(const T &t){ return InsertAt(t, maxdex + 1);}template <class T> int gBlock<T>::Insert(const T &t, int n){ return InsertAt(t, (n < mindex) ? mindex : ((n > maxdex + 1) ? maxdex + 1 : n));}template <class T> T gBlock<T>::Remove(int n){ if (n < mindex || n > maxdex) throw BadIndex(); T ret(data[n]); T *new_data = (--maxdex>=mindex) ? new T[maxdex-mindex+1] - mindex : 0; int i; for (i = mindex; i < n; i++) new_data[i] = data[i]; for (; i <= maxdex; i++) new_data[i] = data[i + 1]; delete [] (data + mindex); data = new_data; return ret;}template <class T> int gBlock<T>::Find(const T &t) const{ int i; for (i = mindex; i <= maxdex && data[i] != t; i++); return (i <= maxdex) ? i : 0;} template <class T> int gBlock<T>::Contains(const T &t) const{ return Find(t); }template <class T> void gBlock<T>::Flush(void){ maxdex = mindex - 1; if (data) delete [] (data + mindex); data = 0; }//// Uses the Dump function to output the gBlock. Uses the << operator// overload to use output streams, gout.//template <class T> gOutput &operator<<(gOutput &f, const gBlock<T> &b){ b.Dump(f); return f;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -