#ifndef STORAGE_H
#define STORAGE_H
#include <map>
#include <utility>
#include <algorithm>

#ifdef Revision
#undef Revision
#endif
#define Revision "storage.h $Revision: 1.3 $";
/**
@author Messenger of death
*/
template <typename A, typename B>
class Storage
{
	private:
		std::map<A, B> _values;
	public:
		Storage() {}
		virtual ~Storage() {}

		bool exist ( A &value )
		{
			return ( _values.find ( value ) != _values.end() ) ? true : false;
		}
		bool insert ( A value1, B value2 )
		{
			if ( exist ( value1 ) ) return false;
			_values.insert ( std::make_pair<A,B> ( value1,value2 ) );
			return true;
		}
		void insert_force ( A value1, B value2 )
		{
			remove( value1 );
			_values.insert ( std::make_pair<A,B> ( value1,value2 ) );
		}
		bool remove ( A value1 )
		{
			if ( !exist ( value1 ) ) return true;
			_values.erase ( _values.find ( value1 ) );
			return true;

		}
		B get ( A value )
		{
			if ( exist ( value ) ) return ( *_values.find ( value ) ).second;
			throw ( bool ( false ) );
		}
		std::map<A, B>& get_map()
		{
			return _values;
		}
		template<typename C>
		void for_each(C &action)
		{
			std::for_each(_values.begin(), _values.end(), action);
		}
};

#endif
