📄 vectorclass.h
字号:
/* * =========================================================================== * PRODUCTION $Log: VectorClass.h,v $ * PRODUCTION Revision 1000.0 2004/04/12 18:22:39 gouriano * PRODUCTION PRODUCTION: IMPORTED [CATCHUP_003] Dev-tree R1.1 * PRODUCTION * =========================================================================== *//* * These files were imported into NCBI's CVS directly from FLU version 2.9.1. * Modifications to the source are listed below. * * ========================================================================== * $Log: VectorClass.h,v $ * Revision 1000.0 2004/04/12 18:22:39 gouriano * PRODUCTION: IMPORTED [CATCHUP_003] Dev-tree R1.1 * * Revision 1.1 2004/03/11 13:51:55 dicuccio * Imported FLU version 2.9.1. Altered export specifiers to match NCBI layout. * Altered include paths to match NCBI toolkit layout. * * ========================================================================== */// $Id: VectorClass.h,v 1000.0 2004/04/12 18:22:39 gouriano Exp $/*************************************************************** * FLU - FLTK Utility Widgets * Copyright (C) 2002 Ohio Supercomputer Center, Ohio State University * * This file and its content is protected by a software license. * You should have received a copy of this license with this file. * If not, please contact the Ohio Supercomputer Center immediately: * Attn: Jason Bryan Re: FLU 1224 Kinnear Rd, Columbus, Ohio 43212 * ***************************************************************/#ifndef _FLU_VECTOR_CLASS_H#define _FLU_VECTOR_CLASS_H#define MakeVectorClass( T, C ) \class C \{ \public: \ \ C() { _array = NULL; _size = 0; } \ \ ~C() { clear(); } \ \ inline void add( const T& item ) { insert( size(), item ); } \ \ inline T& operator [](int i) { return _array[i]; } \ \ inline T operator [](int i) const { return _array[i]; } \ \ inline unsigned int size() const { return _size; } \ \ C& operator =( const C &v ) \ { \ clear(); \ if( v.size() ) \ { \ _array = new T[v.size()]; \ for( unsigned int i = 0; i < v.size(); i++ ) \ _array[i] = v._array[i]; \ } \ return *this; \ } \ \ void insert( unsigned int pos, const T &item ) \ { \ if( pos > _size ) \ pos = _size; \ if( _size == 0 ) \ { \ _array = new T[1]; \ } \ else \ { \ if( !( _size & (_size-1) ) ) \ { \ T* temp = new T[_size*2]; \ for( unsigned int i = 0; i < _size; i++ ) \ temp[i] = _array[i]; \ delete[] _array; \ _array = temp; \ } \ for( unsigned int s = _size; s > pos; s-- ) \ _array[s] = _array[s-1]; \ } \ _size++; \ _array[pos] = item; \ } \ \ void erase( unsigned int pos ) \ { \ if( pos >= _size ) \ return; \ _size--; \ if( _size == 0 ) \ { \ delete[] _array; \ _array = NULL; \ } \ else \ { \ for( ; pos < _size; pos++ ) \ _array[pos] = _array[pos+1]; \ } \ } \ \ void clear() \ { \ if( _array ) \ delete[] _array; \ _array = NULL; \ _size = 0; \ } \ \protected: \ T *_array; \ unsigned int _size; \}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -