📄 tarray.hh
字号:
#ifndef __TARRAY_HH#define __TARRAY_HH//// Project : threadpool// File : TArray.hh// Author : Ronald Kriemann// Purpose : class for a dyn. array of templates//// Copyright (C) 2003 - Ronald Kriemann//// This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public// License as published by the Free Software Foundation; either// version 2.1 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 Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser 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 <assert.h>#include "types.hh"#include "iostream"using std::cout;using std::endl;//// class for a template-vector//template <class T> class TArray{public: /////////////////////////////////////////////// // // local types // typedef unsigned int t_size; protected: T * _data; // the array with the stored elements t_size _size; // number of the element with the max. indexpublic: ///////////////////////////////////////// // // constructor and destructor // TArray ( t_size size = 0 ); TArray ( const TArray<T> & vec ) : _data(NULL), _size(0) { (*this) = vec; } ~TArray () { delete[] _data; } ///////////////////////////////////////// // // manipulate array // // get/set size of the vector t_size size () const { return _size; } void set_size ( t_size n ); // copy operator TArray<T> & operator = ( const TArray<T> & vec ); ///////////////////////////////////////// // // access array // T & operator [] ( t_size i ) { assert( i < _size ); return _data[i]; } const T & operator [] ( t_size i ) const { assert( i < _size ); return _data[i]; } // return c-style array T * c_array () { return _data; } const T * c_array () const { return _data; } // copy c-style array TArray & copy ( T * data, t_size size ); ///////////////////////////////////////// // // misc. // // return size in bytes used by this object ulong byte_size () const { return sizeof(t_size) + (_size * sizeof(T)); }};#include "TArray.cc"#endif // __TARRAY_HH
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -