/* 
 * PVM++ - A C++ library for easy use of PVM
 * Copyright (C) 1997-2001 Sebastian Wilhelmi; University of Karlsruhe
 *
 * 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
 */

#ifndef __PVM_STRUCT_II__
#define __PVM_STRUCT_II__

#include <pvm++/struct.hh>
#include <pvm++/receiveaction.hh>
#include <pvm++/taskset.hh>

#include <cstddef>

namespace Pvm
{

  template< class Type > 
  inline 
  Type * 
  GetNewInstance (const Type &)
  {
    return new Type;
  }
  
  inline 
  Struct::Struct () : StructIdForAutomaticUnpack (-1)
  {
  }
  
  inline 
  Struct::Struct (const Struct &What)
  {
  }
  
  inline 
  void
  Struct::Pack () const
  {
    CurrentlyPacking = true;
    /* Pack should indeed br const, but PackOrUnPack is only const for
     * CurrentlyPacking == true, thus we have to fool the compiler into
     * believing, we're right */
    (const_cast< Struct * >(this))->PackOrUnPack ();
  }
  
  inline 
  void
  Struct::UnPack ()
  {
    CurrentlyPacking = false;
    PackOrUnPack ();
  }
  
  inline 
  Struct & 
  Struct::operator = (const Struct &What)
  {
    return *this;
  }
  
  inline 
  ReceiveAction 
  Struct::InstallHandler (HandlerFunc Func)
  {
    return ReceiveAction (Func);
  }
  
  inline 
  ReceiveAction 
  Struct::AutomaticUnPack ()
  {
    return ReceiveAction (ReceiveAction::AutoUnpack);
  }
  
  inline 
  ReceiveAction 
  Struct::SwallowOnReceive ()
  {
    return ReceiveAction (ReceiveAction::Swallow);
  }
  
  inline 
  ReceiveAction 
  Struct::NormalReceive ()
  {
    return ReceiveAction (ReceiveAction::Normal);
  }
  
  inline 
  void
  Struct::Send (const TaskSet &To) const
  {
    TaskSet::iterator Current;
    TaskSet::iterator Last = To.end ();
    
    for (Current = To.begin (); Current != Last; ++Current)
      Send (*Current);
  }

} // namespace Pvm

#endif /* __PVM_STRUCT_II__ */
