/*
Copyright (C) 2006 Evan Teran
                   eteran@alum.rit.edu

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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#ifndef MEMREGION_20081209_H_
#define MEMREGION_20081209_H_

#include "Types.h"
#include <QString>
class DebuggerCoreInterface;
class MemoryRegions;
class DebugEventHandlerInterface;

class MemRegion {
	friend class MemoryRegions;
public:
	MemRegion() : start(0), end(0), base(0), m_Permissions(0) {
	}

	virtual ~MemRegion();

public:
	MemRegion(const MemRegion &o) : start(o.start), end(o.end), base(o.base), name(o.name), m_Permissions(o.m_Permissions) {
	}

	MemRegion &operator=(const MemRegion &o) {
		if(&o != this) {
			start			= o.start;
			end				= o.end;
			base			= o.base;
			name			= o.name;
			m_Permissions	= o.m_Permissions;
		}
		return *this;
	}

	bool operator==(const MemRegion &o) const {
		return 
			start			== o.start &&
			end				== o.end &&
			base			== o.base &&
			name			== o.name &&
			m_Permissions	== o.m_Permissions;
	}

	bool operator!=(const MemRegion &o) const {
		return !(operator==(o));
	}

	bool operator<(const MemRegion &o) const {
		return start < o.start;
	}

public:
	bool accessible() const;
	bool readable() const;
	bool writable() const;
	bool executable() const;
	int size() const;

	void setPermissions(DebugEventHandlerInterface *(*setDebugEventHandler)(DebugEventHandlerInterface *), const MemoryRegions &memoryRegions, DebuggerCoreInterface *debug, bool read, bool write, bool execute);

private:
	void setPermissions(DebugEventHandlerInterface *(*setDebugEventHandler)(DebugEventHandlerInterface *), DebuggerCoreInterface *debug, bool read, bool write, bool execute, edb::address_t tempAddress);

public:
	edb::address_t	start;
	edb::address_t	end;
	edb::address_t	base;
	QString			name;
	
public:
	quint8			m_Permissions;
};

#endif
