/*********************************************************************
 * This file is part of the cpplibs suite.
 *
 * Copyright (C) 2001 Topi Mäenpää
 * All rights reserved.
 *
 * This program is free software. You can redistribute and/or modify
 * it under the terms of the free software licence found in the
 * accompanying file "COPYING". The licence terms must always be
 * redistributed with this source file. The above copyright notice
 * must be reproduced in all modified and unmodified copies of this
 * source file.
 *
 * $Revision: 1.4 $
 *********************************************************************/

#ifndef _MAP_H
#define _MAP_H

#include "Object.h"

namespace util
{
	/**
	 * Map is an interface for data structures that hold name-value
	 * pairs.
	 **/
	template <class key, class value> class Map : virtual public Object
	{
	public:
		/**
		 * Get the value associated with <i>key</i> from the map. The
		 * default implementation calls the non-const version and returns
		 * the result as a const pointer.
		 * @param obj the association key
		 * @return a pointer to the stored object or NULL if it was not found
		 **/
		virtual const value* get(const key& obj) const { return (const value*)((Map<key,value>*)this)->get(obj); }

		/**
		 * Get the value associated with <i>key</i> from the map.
		 * @param obj the association key
		 * @return a pointer to the stored object or NULL if it was not found
		 **/
		virtual value* get(const key& obj) = 0;

		/**
		 * Get a pointer to a stored object. Calls get(obj).
		 * @param obj the key object that references the wanted object
		 * @return a pointer to the value or NULL if it was not found
		 **/
		const value* operator[](const key& obj) const { return get(obj); }
		/**
		 * Get a pointer to a stored object. Calls get(obj).
		 * @param obj the key object that references the wanted object
		 * @return a pointer to the value or NULL if it was not found
		 **/
		value* operator[](const key& obj) { return get(obj); }

		/**
		 * Put a value into the map.
		 * @param obj the key object
		 * @param val a value associated with the key
		 **/
		virtual void put(const key& obj, const value& val) = 0;
	};
}

#endif
