/** @file enumencoder.h
*	enum encoder/decoder macros
*	@author Chris Burns (cburns@ea.com)
*
*	EABaseTypes
*	(c) 2012 Electronic Arts Inc.
*/

#ifndef EABASETYPES_ENUMENCODER_H_
#define EABASETYPES_ENUMENCODER_H_

#include "EABaseTypes/nativetraits.h"
#include "coreallocator/icoreallocatormacros.h"

namespace EA
{
	namespace Types
	{
		struct RawEnumTraits
		{
			typedef IntContext									EncoderContext;
			struct Value
			{
				Value(Factory*):mValue(0) {}
				int mValue;
				Value& operator=(int rhs)
				{
					mValue = rhs;
					return *this;
				}
			};

			typedef Value										EncodeValue;
			typedef Value										ReturnEncodeValue;
			typedef Value										DecodeValue;

			static inline NativeDecoderType GetDecoderType() { return NATIVE_DECODER_TYPE_INT; }
			static inline void*	GetEncodePointer(Value& value) { return &value.mValue; }
			static inline void* GetDecodePointer(const Value& value) { return const_cast<int*>(&value.mValue); }
			static inline NativeDecodeFunction GetDecodeFunction() { return NULL; }
		};
	}
}

#define EABASETYPES_RAWENUM(T) \
namespace EA\
{\
	namespace Types\
	{\
		template<>\
		struct NativeTraits<T> : RawEnumTraits\
		{\
			typedef RawEnumTraits::EncoderContext				EncoderContext;\
			typedef RawEnumTraits::Value						Value;\
			typedef	Value										EncodeValue;\
			typedef Value										EncodeReturnValue;\
			typedef Value										DecodeValue;\
			\
			static inline T GetValue(Value& value) { return static_cast<T>(value.mValue); }\
			static inline T GetReturnValue(const Value& value) { return static_cast<T>(value.mValue); }\
			using RawEnumTraits::GetDecodePointer;\
			static inline void* GetDecodePointer(const T& value) { return const_cast<T*>(&value); }\
		};\
		\
		template<>\
		struct BaseTypeTraits1<T>\
		{\
			static BaseTypeReturn BaseType(Factory* factory, T value) { return factory->Number(static_cast<int>(value)); }\
		};\
	}\
}

#endif /* EABASETYPES_ENUMENCODER_H_ */
