/*
 *  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, G1K 7P4
 *  http://vision.gel.ulaval.ca
 *
 */

/*!
 *  \file   beagle/BreederNode.hpp
 *  \brief  Definition of the class BreederNode.
 *  \author Christian Gagne
 *  \author Marc Parizeau
 *  $Revision: 1.4 $
 *  $Date: 2004/04/25 23:12:20 $
 */

 
#ifndef Beagle_BreederNode_hpp
#define Beagle_BreederNode_hpp

#include "beagle/config.hpp"
#include "beagle/macros.hpp"
#include "beagle/Object.hpp"
#include "beagle/Pointer.hpp"
#include "beagle/PointerT.hpp"
#include "beagle/Allocator.hpp"
#include "beagle/AllocatorT.hpp"
#include "beagle/AbstractAllocT.hpp"
#include "beagle/ContainerAllocator.hpp"
#include "beagle/Container.hpp"
#include "beagle/ContainerT.hpp"
#include "beagle/Operator.hpp"
#include "beagle/Individual.hpp"


namespace Beagle {

// Forward declaration.
class BreederOp;

/*!
 *  \class BreederNode beagle/BreederNode.hpp "beagle/BreederNode.hpp"
 *  \brief Breeder node class, the skeleton of the breeder trees.
 *  \ingroup ECF
 *  \ingroup Op
 */
class BreederNode : public Object {

public:

  //! BreederNode allocator type.
  typedef AllocatorT<BreederNode,Object::Alloc>
          Alloc;
  //! BreederNode handle type.
  typedef PointerT<BreederNode,Object::Handle>
          Handle;
  //! BreederNode bag type.
  typedef ContainerT<BreederNode,Object::Bag>
          Bag;
          
           BreederNode(PointerT<BreederOp,Operator::Handle> inBreederOp=NULL,
                       PointerT<BreederNode,Object::Handle> inFirstChild=NULL,
                       PointerT<BreederNode,Object::Handle> inNextSibbling=NULL);
  virtual ~BreederNode() { }

  virtual void initialize(System& ioSystem);
  virtual void postInit(System& ioSystem);
  virtual void readWithMap(XMLNode::Handle& inNode, OperatorMap& inOpMap);
  virtual void write(XMLStreamer& ioStreamer) const;
  
  /*!
   *  \return Breeder operator associated to node.
   */
  inline PointerT<BreederOp,Operator::Handle> getBreederOp() const
  {
    return mBreederOp;
  }
  
  /*!
   *  \return First child to the breeder.
   */
  inline PointerT<BreederNode,Object::Handle> getFirstChild() const
  {
    return mChild;
  }

  /*!
   *  \return Next sibbling to the breeder.
   */
  inline PointerT<BreederNode,Object::Handle> getNextSibbling() const
  {
    return mSibbling;
  }

  /*!
   *  \brief Set breeder operator associated to actual node.
   *  \param inBreederOp New breeder operator associated to breeder node.
   */
  inline void setBreederOp(PointerT<BreederOp,Operator::Handle> inBreederOp)
  {
    mBreederOp = inBreederOp;
  }
  
  /*!
   *  \brief Set first child of the breeder.
   *  \param inChild New first child.
   */
  inline void setFirstChild(PointerT<BreederNode,Object::Handle> inChild)
  {
    mChild = inChild;
  }

  /*!
   *  \brief Set next sibbling of the breeder.
   *  \param inSibbling New next sibbling.
   */
  inline void setNextSibbling(PointerT<BreederNode,Object::Handle> inSibbling)
  {
    mSibbling = inSibbling;
  }
  
private:
  PointerT<BreederOp,Operator::Handle> mBreederOp;  //!< Breeder operator associated to the node.
  PointerT<BreederNode,Object::Handle> mChild;      //!< First breeder node child.
  PointerT<BreederNode,Object::Handle> mSibbling;   //!< Next breeder node sibbling.

public:
  virtual void read(XMLNode::Handle& inNode);       // Undefined read method!
  
};

}

#endif // Beagle_BreederNode_hpp

