#pragma once

#include "MPT_Exception.h"
#include "MPT_Buffer.h"
#include "IFD_TYPE.h"


namespace MobilePhotoTool{

	class IFD_ENTRY
	{
	public:
		/**
		 * type descripe this IFD_ENTRY.
		 */
		IFD_TYPE *type;

	private:
		/**
		 * The position in the buffer.
		 */
		size_t position;

		/**
		 * The input buffer
		 */
		MPT_Buffer *buffer;



		/**
		 * The number of values in this entry
		 */
		unsigned int number_values;

		/**
		 * The position of the values in the buffer
		 */
		size_t position_values;

	public:

		/**
		 * 
		 * Creats a IFD_ENTRY with given buffer and position in the buffer;
		 * 
		 * @param buffer The buffer that holds the image.
		 * @param position The byte position of this IFD
		 * @exception MPT_Exception
		 */
		IFD_ENTRY(MPT_Exception *exception, MPT_Buffer *buffer, size_t position);

		/**
		 * Reads all integer and returns the values 
		 * as streamoff array.
		 *
		 * @return streamoff array
		 */
		size_t* get_integer_as_streamoff(MPT_Exception *exception, size_t *size);

		/**
		 *	Reads the first integer.
		 *
		 * @return unsigned int
		 */
		unsigned int get_integer_as_uinterger(MPT_Exception *exception);

		/**
		 *	Reads the all integer.
		 *
		 * @return unsigned int
		 */
		unsigned int *get_integer_as_uinterger_array(MPT_Exception *exception, size_t *size);


		/**
		 * Reads all integer as rational.
		 *
		 * param value A pointer to the return values.
		 * param size The size of the value array.
		 */
		void get_as_rational(MPT_Exception *exception, unsigned int *value, size_t size);

		/**
		 * Reads all integer as rational.
		 *
		 * param value A pointer to the return values.
		 * param size The size of the value array.
		 */
		void get_as_srational(MPT_Exception *exception, int *value, size_t size);

		/**
		 * Reads all values and returns it as float
		 *
 		 * param value A pointer to the return values.
		 * param size The size of the value array.
		 */
		void get_as_float(MPT_Exception *exception, float *values, size_t size);

		/**
		 * Reads all values and returns it as char
		 *
 		 * param value A pointer to the return values.
		 * param size The size of the value array.
		 */
		void get_as_char(MPT_Exception *exception, char *values, size_t size);

		/**
		 * Return the number of values.
		 * @return Number of values.
		 */
		unsigned int get_number_values(MPT_Exception *exception);

		~IFD_ENTRY(void);

	private:
		/**
		 * Reads the information of this IFD_entry not the data
		 */
		void read(MPT_Exception *exception);

	};

}
