/*
 *  Open BEAGLE
 *  Copyright (C) 2001-2004 by Christian Gagne and Marc Parizeau
 *
 *  This library 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 2.1 of the License, or (at your option) any later version.
 *
 *  This library 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 along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  Contact:
 *  Laboratoire de Vision et Systemes Numeriques
 *  Departement de genie electrique et de genie informatique
 *  Universite Laval, Quebec, Canada, G1V 4J7
 *  http://vision.gel.ulaval.ca
 *
 */

/*!
 *  \file   beagle/GP/PrimitiveSet.hpp
 *  \brief  Definition of the type GP::PrimitiveSet.
 *  \author Christian Gagne
 *  \author Marc Parizeau
 *  $Revision: 1.2 $
 *  $Date: 2004/01/15 21:08:56 $
 */

#ifndef Beagle_PrimitiveSet_hpp
#define Beagle_PrimitiveSet_hpp

#include <string>

#include "beagle/config.hpp"
#include "beagle/macros.hpp"
#include "beagle/Object.hpp"
#include "beagle/Allocator.hpp"
#include "beagle/Pointer.hpp"
#include "beagle/Container.hpp"
#include "beagle/System.hpp"
#include "beagle/GP/Primitive.hpp"


namespace Beagle {
namespace GP {


// Forward declaration
class System;


/*!
 *  \class PrimitiveSet beagle/GP/PrimitiveSet.hpp "beagle/GP/PrimitiveSet.hpp"
 *  \brief The GP primitive set class.
 *  \ingroup GPF
 *  \ingroup Primit
 *  \ingroup GPSys
 */
class PrimitiveSet : public Primitive::Bag {

public:

  //! GP::PrimitiveSet allocator type.
  typedef AllocatorT<PrimitiveSet,Primitive::Bag::Alloc>
          Alloc;
  //! GP::PrimitiveSet handle type.
  typedef PointerT<PrimitiveSet,Primitive::Bag::Handle>
          Handle;
  //! GP::PrimitiveSet mixed bag type.
  typedef ContainerT<PrimitiveSet,Primitive::Bag::Bag>
          Bag;

  explicit PrimitiveSet(std::string inRootType="");
  virtual ~PrimitiveSet() { }

  /*!
   *  \brief Set the associated tree's root type.
   *  \param inRootType Root type.
   */
  inline void setRootType(std::string inRootType)
  {
    mRootType = inRootType;
  }

  virtual std::string       getRootType() const;
          Primitive::Handle getPrimitiveByName(std::string inName) const;
  virtual void              initialize(GP::System& ioSystem);
  virtual void              insert(Primitive::Handle inPrimitive);
  virtual Primitive::Handle selectPrimitive(GP::System& ioSystem) const;
  virtual Primitive::Handle selectPrimitiveWithArguments(GP::System& ioSystem) const;
  virtual Primitive::Handle selectPrimitiveWithKArguments(unsigned int inK,
                                                          GP::System& ioSystem) const;
  virtual Primitive::Handle selectPrimitiveWithoutArgument(GP::System& ioSystem) const;
  virtual void              read(XMLNode::Handle& inNode);
  virtual void              write(XMLStreamer& ioStreamer) const;

protected:
  Map            mNameLUT;      //!< Look-up table (by name) of the primitives.
  Primitive::Bag mBranchesLUT;  //!< Look-up of the branches (primitives with arguments).
  Primitive::Bag mLeavesLUT;    //!< Look-up of the branches (primitives without arguments).
  std::string    mRootType;     //!< Associated root type. Used only with strongly-typed GP.

};

}
}

#endif // Beagle_PrimitiveSet_hpp

