/****************************************************************************
	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
****************************************************************************/


// commands.h: Schnittstelle für die Klasse commands.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_COMMANDS_H__E9F07200_AF60_11D8_BEF3_08001717B9AF__INCLUDED_)
#define AFX_COMMANDS_H__E9F07200_AF60_11D8_BEF3_08001717B9AF__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "fnlist_internal.h"

namespace Kalkulon{
namespace cmd{

//////////////////////////////////////////////////////////////////////
// exported commands

double		Size(const DataObject& dob);								// returns size of dob
double		Type(const DataObject& dob);								// returns type of dob

DataObject	Back(const DataObject& dob);								// returns last element
DataObject	Front(const DataObject& dob);								// returns first element

DataObject	PopBack(const DataObject& dob);								// removes last element from list
DataObject	PopFront(const DataObject& dob);							// removes first element from list

DataObject	PushBack(const DataObject& dob, const DataObject& elem);	// inserts elem at end of list
DataObject	PushFront(const DataObject& dob, const DataObject& elem);	// inserts elem at begin of list

DataObject	Insert(const DataObject& dob, const DataObject& idx_dob, const DataObject& elem);	// inserts elem or list of elems at pos idx
DataObject	Replace(const DataObject& dob, const DataObject& idx_dob, const DataObject& elem);	// replaces elem or list of elems at pos idx
DataObject	Sub1(const DataObject& dob, const DataObject& beg);									// cuts from beg to real end
DataObject	Sub2(const DataObject& dob, const DataObject& beg, const DataObject& end);			// cuts from beg to end - [beg, end[
DataObject	Erase1(const DataObject& dob, const DataObject& pos);								// erases elem at pos
DataObject	Erase2(const DataObject& dob, const DataObject& beg, const DataObject& end);		// erases from beg to end - [beg, end[

double		Load(CRPNStackEval *p, std::string file);			// loads Kalkulon script
DataObject	ClearAll(CRPNStackEval *p);							// clears all variables and functions
DataObject	Version(CRPNStackEval *p);							// returns version string

DataObject	LinePos(const DataObject& file, const DataObject& offset);		// returns line and column from char offset

DataObject	Print(CRPNStackEval *p, const DataObject& dob);			// calls CallbackPrint(string)
double		PrintLn0(CRPNStackEval *p);								// calls CallbackPrintLn
DataObject	PrintLn1(CRPNStackEval *p, const DataObject& dob);		// calls CallbackPrintLn(string)
std::string Sprintf(std::string format, const DataObject& dob);		// formats string like sprintf
DataObject	FullForm(const DataObject& dob);						// converts dob to string in full form

double      Error(std::string reason);							// throws user defined error

std::string      SetNumFormat(std::string format_string);		// sets number format to printf format string, returns old value
std::string      SetStdFormat();
std::string      SetHexFormat();
std::string      SetBinFormat();
std::string      SetSciFormat();

double		SetRecursionLimit(int rec_limit);					// sets new recursion limit for evaluator, returns old value, BEWARE: bigger values may lead to stack overflow!

DataObject  Eval(CRPNStackEval *p, std::string expr);			// evaluates expr contained in string

DataObject  ForEach1(CRPNStackEval *p, const DataObject& list, const DataObject& purefunc);								// evaluates unary purefunc for each element in list
DataObject  ForEach2(CRPNStackEval *p, const DataObject& list1, const DataObject& list2, const DataObject& purefunc);	// evaluates binary purefunc for each element in list1 and list2
DataObject  Table1(CRPNStackEval *p, const DataObject& end, const DataObject& purefunc);								// evaluates purefunc for i in [1, end]
DataObject  Table2(CRPNStackEval *p, const DataObject& start, const DataObject& end, const DataObject& purefunc);		// evaluates purefunc for i in [start, end]
DataObject  Table3(CRPNStackEval *p, const DataObject& start, const DataObject& end, const DataObject& delta, const DataObject& purefunc);		// evaluates purefunc for i in [start, end, delta]
DataObject  Fold(CRPNStackEval *p, const DataObject& list, const DataObject& first, const DataObject& purefunc);			// evaluates pf(pf(first, list[0]), list[1])...
DataObject  FoldList(CRPNStackEval *p, const DataObject& list, const DataObject& first, const DataObject& purefunc);		// evaluates {pf(first, list[0]), pf(pf(first, list[0]), list[1])...}

DataObject  ReadData(const DataObject& file);							// reads file as ascii data and return as list of text lines
DataObject  WriteData(const DataObject& file, const DataObject& list);	// writes list of dobs as text lines to ascii file
DataObject  ReadBinData0(const DataObject& file);						// reads file as binary data and return as list of bytes
DataObject  ReadBinData1(const DataObject& file, const DataObject& beg, const DataObject& end);	// reads file as binary data and return as list of bytes
DataObject  WriteBinData(const DataObject& file, const DataObject& list);		// writes list of bytes to binary file

// platform dependent
double Beep(double freq, double dur);							// simple beep
double Exec1(std::string app);									// start application
double Exec2(std::string app, std::string param);				// start application with parameters
double GetTicks();												// returns tick timer in ms

//////////////////////////////////////////////////////////////////////

}} // end namespace

#endif // !defined(AFX_COMMANDS_H__E9F07200_AF60_11D8_BEF3_08001717B9AF__INCLUDED_)
