/*
WARNING: This header should never be directly included. Include factory.h instead.
NOTE: This class is intended for interal usage by the Factory class.

Author:		Chris Kaynor (chris@kaynor.net)
Edited By:	

Description:		Provides an interface to store the data needed internally by the Factory
			class. Stores the usage of the object and the object itself, along with
			providing an interface to retrieve, set, and update those values.
		
Usage:		Use the derefrence, member derefrence, or implict casts to access the
			object stored (returns either a refrence or a pointer to the object).
			
			Use the increment or decrement operator to modify the usage.
			
			Use the implicit int cast to retrieve the usage.
			
			Use the constructor to load the object and initialize the usage to 0.
			
Requirements:	string as defined in the standard template libary.
			NoCopy as defined in kLibrary's common section.
			
Last Edited:	May 20th, 2008
*/
/*
Copyright 2008 Chris Kaynor

This file is part of kLibrary.

kLibrary is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or(at your option) any later version.

kLibrary 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 Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License.
*/

#ifndef KLIBRARY_FACTORY_STORAGE_H
#define KLIBRARY_FACTORY_STORAGE_H

#include <string>
#include "..\Common\NoCopy.h"

namespace kLibrary
{
	namespace factory
	{
		template<class itemType, class paramType, class nameType = std::string>
		//NOTE: This class is intended for internal usage by the Factory class.
		class _Storage : NoCopy
		{
		public:
			//Increment or decrement the usage value.
			inline _Storage& operator++(void);
			inline _Storage& operator--(void);
			inline _Storage& operator++(int);
			inline _Storage& operator--(int);
			
			//Explict derefrence to access the item stored.
			inline itemType& operator*(void);
			inline itemType* operator->(void);
			
			/*
			NOTE: Initializes the usage to zero (0).
			Construct and initialize the object and the item stored.
			*/
			inline _Storage(const nameType& name, paramType param);
			
			//Deconstruct the object.
			inline ~_Storage(void);
			
			//Implict cast to int to retrieve the usage
			inline operator int(void);
			
			//Implicit cast to the object or a pointer to the object stored.
			inline operator itemType&(void);
			inline operator itemType*(void);
			
		private:
			//The item being stored.
			itemType _item;
			
			//The number of active instances of the object.
			int _usage;
		};
	}
}

#include "factory_storage_code.h"

#endif //KLIBRARY_FACTORY_STORAGE_H