#pragma once

#include "ElementProxies.hpp"

namespace ElementProxies {

	class MLRPolygonProxy;
	class MLRIndexProxy;
	class MLRVertexProxy;

	//
	//#########################################################################
	//####################    MLRIndexProxy    #########################
	//#########################################################################
	//
	class MLRIndexProxy:
		public Proxies::IndexProxy
	{
	public:
		static void
			InitializeClass();
		static void
			TerminateClass();

		static ClassData
			*DefaultData;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Constructors
	//
	public:
		static MLRIndexProxy*
			MakeProxy(
				MLRPolygonProxy *polygon,
				MLRVertexProxy *vertex,
				int polygon_index
			)
				{return new MLRIndexProxy(polygon, vertex, polygon_index);}

		void
			Destroy();

		void*
			operator new(size_t)
				{return AllocatedMemory->New();}
		void
			operator delete(void *where)
				{AllocatedMemory->Delete(where);}

	protected:
		MLRIndexProxy(
			MLRPolygonProxy *polygon,
			MLRVertexProxy *vertex,
			int polygon_index
		);
		~MLRIndexProxy();

		static Stuff::MemoryBlock
			*AllocatedMemory;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Testing
	//
	public:
		void
			TestInstance() const;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Vertex management functions
	//
	public:
		//
		// Copies the elements of a polygon into this polygon
		//
		MLRPolygonProxy*
			GetPolygonProxy()
				{
					Check_Object(this);
					return Cast_Pointer(MLRPolygonProxy*, polygonProxy);
				}
		MLRVertexProxy*
			GetVertexProxy()
				{
					Check_Object(this);
					return Cast_Pointer(MLRVertexProxy*, vertexProxy);
				}

	protected:
		int
			polygonIndex;
	};

}
