#ifndef FUNC_TAB_H_
#define FUNC_TAB_H_

#include <map>
#include <string>

class Function;
class InverseLinkFunc;

/** 
 * The FuncTab class provides a convenient way of storing Function
 * objects and referencing them by name.
 *
 * The FuncTab owns the function objects it contains and will delete
 * them when it is destroyed.  Therefore the FunTab object must be
 * persistent. It must not be deleted while its functions are in use.
 *
 * @short Function table
 * @see Function
 */
class FuncTab
{
  std::map < const std::string, const Function *> _table, _link_table;
public:
  /**
   * Constructor.  A newly constructed FuncTab will automatically
   * contain the standard JAGS functions.
   */
  FuncTab ();
  /** 
   * Destructor. The memory associated with all the functions
   * contained in the FuncTab is freed.
   */
  ~FuncTab ();
  /**
   * Inserts an inverse link function into the table. This function
   * works the same way as the standard insert function (see below)
   * but additionally registers the function by its link name 
   * @see InverseLinkFunc
   */
  bool insert (InverseLinkFunc const *func);
  /**
   * Inserts a function into the table.
   *
   * @return logical value indicating success.  The insertion will
   * fail if a function with the same name is already in the FuncTab.
   *
   * @param func Pointer to the function to insert, which should
   * be dynamically allocated. The FuncTab is responsible for freeing
   * the memory allocated to func.
   */
  bool insert (Function const *func);
  /** 
   * Removes a function by name and frees the associated memory.
   * 
   * With a combination of erase and insert calls, you can
   * replace the standard JAGS functions.
   *
   * @return a logical value indicating success.  The removal
   * will fail if there is no function with the given name
   * in the FuncTab.
   */
  bool erase (std::string const &name);
  /**
   * Finds a function by name 
   *
   * @return a pointer to the function or 0 if it was not found.
   */
  Function const *find (std::string const &name) const;
  /**
   * Finds the inverse of a link function by the link name
   *
   * @return a pointer to the inverse function or 0 if it was not found.
   */
  Function const *findInverse (std::string const &name) const;
};

#endif /* FUNC_TAB_H_ */


syntax highlighted by Code2HTML, v. 0.9.1