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

📄 matrix.h.svn-base

📁 Complete support for EBNF notation; Object-oriented parser design; C++ output; Deterministic bottom-
💻 SVN-BASE
字号:
#ifndef __WHALE__MATRIX_H#define __WHALE__MATRIX_H//#define DEBUG_MATRIX#include <algorithm>#include <typeinfo>template <class T> class matrix{protected:	int m, n;	T *body;public:	matrix(int supplied_m, int supplied_n)	{		body=new T[(m=supplied_m)*(n=supplied_n)];		std::fill(body, body+m*n, T());	#ifdef DEBUG_MATRIX		cout << "matrix<" << typeid(T).name() << ">::matrix(): raw size is " << m*n*sizeof(T) << "\n";	#endif	}	matrix(matrix<T> &prototype)	{		body=new T[(m=prototype.m)*(n=prototype.n)];		// DAMN! This is COPY CTOR!!!!!		std::copy(prototype.body, prototype.body + n*m, body);	#ifdef DEBUG_MATRIX		cout << "matrix<" << typeid(T).name() << ">::matrix(matrix<" << typeid(T).name() << "> &): raw size is " << m*n*sizeof(T) << "\n";	#endif	}	~matrix()	{		delete[] body;	#ifdef DEBUG_MATRIX		cout << "matrix<" << typeid(T).name() << ">::~matrix()\n";	#endif	}	matrix<T> &operator =(const matrix<T> &prototype)	{		delete[] body;		body=new T[(m=prototype.m)*(n=prototype.n)];		copy(prototype.body, prototype.body+m*n, body);	#ifdef DEBUG_MATRIX		cout << "matrix<" << typeid(T).name() << ">::operator =(matrix<" << typeid(T).name() << "> &): new raw size is " << m*n*sizeof(T) << "\n";	#endif		return *this;	}	void destructive_resize(int new_m, int new_n)	{		delete[] body;		body=new T[(m=new_m)*(n=new_n)];	#ifdef DEBUG_MATRIX		cout << "matrix<" << typeid(T).name() << ">::destructive_resize(" << new_m << ", " << new_n << "): new raw size is " << m*n*sizeof(T) << "\n";	#endif	}	int rows() { return m; }	int columns() { return n; }#if 0	typedef T * iterator;	typedef const T * const_iterator;#endif	T *operator [](int i) { return body+i*n; }	const T *operator [](int i) const { return body+i*n; }	T &operator [](const std::pair<int, int> &c) { return body[c.first*n+c.second]; }	const T &operator [](const std::pair<int, int> &c) const { return body[c.first*n+c.second]; }	T &operator ()(int i, int j) { return (*this)[i][j]; }	const T &operator()(int i, int j) const { return (*this)[i][j]; }#if 0	std::pair<int, int> locate(const iterator &p)	{		int offset=p-body;		return std::make_pair(offset/n, offset%n);	}	iterator begin() { return body; }	iterator end() { return body+m*n; }	iterator at(int i, int j) { return body+i*n+j; }#endif};#undef DEBUG_MATRIX#endif

⌨️ 快捷键说明

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