#include <string>
#include <vector>
#include <exception>

class PGM_Image {
public:
	PGM_Image();
	PGM_Image(const std::string& fileName);
	// construtor may throw std::invalid_argument

	typedef unsigned char value_type;
	
	// iterator interface
	typedef std::vector<value_type>::iterator iterator;
	typedef std::vector<value_type>::const_iterator const_iterator;
	iterator begin();
	const_iterator begin() const;
	iterator end();
	const_iterator end() const;

	// size
	typedef std::vector<value_type>::size_type size_type;
	size_type size() const;

	// index interface
	typedef std::vector<value_type>::reference reference;
	typedef std::vector<value_type>::const_reference const_reference;
	reference operator[](size_type i);
	const_reference operator[](size_type i) const;

	void saveAs(const std::string& fileName) const;
	// saveAs may throw std::invalid_argument

	// equal operator
	bool operator==(const PGM_Image& right);
private:
	std::vector<value_type> data;
	int xsize;
	int ysize;
};


