/****************************************************************************
	Kalkulon - A programmable calculator for programmers

	This file is part of the Kalkulon core.
	
	If you find this source code useful, your are encouraged to use it in your own projects.
	Please give me credit!

	COPYRIGHT by Juergen Holetzeck 2003 - 2008
	e-mail:		contact@kalkulon.de
	homepage:	www.kalkulon.de
****************************************************************************/


// FuncObject.cpp: Implementierung der Klasse FuncObject.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include <sstream>
#include "FuncObject.h"
#include "serialize.h"

using namespace Kalkulon;

// output stream operator
std::ostream& operator<< (std::ostream& out, FuncObject& fo)
{
	out << fo.name << '(';
	for(unsigned int i=0; i<fo.param_list.size(); ++i)
	{
		if(i) out << ", ";
		out << fo.param_list[i];
	}

	out << ')';
	return out;
}	


FuncObject::operator std::string()
{
	std::ostringstream os;
	os << *this;
	return os.str();
}


void FuncObject::serialize(std::ostream& os) const
{
  serialize::put(os, name);
  size_t len = param_list.size();
  serialize::put(os, len);
  for(size_t i=0; i<len; ++i)
    serialize::put(os, param_list[i]);
  serialize::put(os, rpn_stack);
}

FuncObject FuncObject::deserialize(std::istream& is)
{
  FuncObject fo;

  fo.name = serialize::getString(is);
  size_t len = serialize::getSize_t(is);
  fo.param_list.resize(len);
  for(size_t i=0; i<len; ++i)
  {
    fo.param_list[i] = serialize::getString(is);
  }
  fo.rpn_stack = serialize::getRPNStack_t(is);
  return fo;
}
