/*!\file BoolExternalResult.c
 * \brief: implementation of the BoolExternalResult object
 */

/*header files: */
/*{{{1*/
#ifdef HAVE_CONFIG_H
	#include <config.h>
#else
#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
#endif

#include <stdio.h>
#include <string.h>
#include "../objects.h"
#include "../../EnumDefinitions/EnumDefinitions.h"
#include "../../shared/shared.h"
#include "../../Container/Container.h"
#include "../../include/include.h"
/*}}}*/

/*BoolExternalResult constructors and destructor*/
/*FUNCTION BoolExternalResult::BoolExternalResult(){{{1*/
BoolExternalResult::BoolExternalResult(){
	return;
}
/*}}}*/
/*FUNCTION BoolExternalResult::BoolExternalResult(int enum_type,bool value){{{1*/
BoolExternalResult::BoolExternalResult(int in_id, int in_enum_type,bool in_value,int in_step, double in_time){

	id=in_id;
	enum_type=in_enum_type;
	value=in_value;
	step=in_step;
	time=in_time;
}
/*}}}*/
/*FUNCTION BoolExternalResult::~BoolExternalResult(){{{1*/
BoolExternalResult::~BoolExternalResult(){
	return;
}
/*}}}*/

/*Object virtual functions definitions:*/
/*FUNCTION BoolExternalResult::Echo {{{1*/
void BoolExternalResult::Echo(void){
	this->DeepEcho();
}
/*}}}*/
/*FUNCTION BoolExternalResult::DeepEcho{{{1*/
void BoolExternalResult::DeepEcho(void){

	printf("BoolExternalResult:\n");
	printf("   id: %i\n",this->id);
	printf("   enum:  %i (%s)\n",this->enum_type,EnumToStringx(this->enum_type));
	printf("   value: %s\n",this->value?"true":"false");
	printf("   step: %i\n",this->step);
	printf("   time: %g\n",this->time);
}
/*}}}*/
/*FUNCTION BoolExternalResult::Id{{{1*/
int    BoolExternalResult::Id(void){ return -1; }
/*}}}*/
/*FUNCTION BoolExternalResult::MyRank{{{1*/
int    BoolExternalResult::MyRank(void){ 
	extern int my_rank;
	return my_rank; 
}
/*}}}*/
/*FUNCTION BoolExternalResult::ObjectEnum{{{1*/
int BoolExternalResult::ObjectEnum(void){

	return BoolExternalResultEnum;

}
/*}}}*/
/*FUNCTION BoolExternalResult::copy{{{1*/
Object* BoolExternalResult::copy() {
	
	return new BoolExternalResult(this->id,this->enum_type,this->value,this->step,this->time);

}
/*}}}*/

/*BoolExternalResult management: */
/*FUNCTION BoolExternalResult::WriteData{{{1*/
void   BoolExternalResult::WriteData(FILE* fid,bool io_gather){

	int     length;
	int     type;
	int     size;
	double  boolean;
	extern  int my_rank;
	char*   name = NULL;

	/*return if now on cpu 0: */
	if(my_rank)return;

	/*First write enum: */
	EnumToStringx(&name,this->enum_type);
	length=(strlen(name)+1)*sizeof(char);
	fwrite(&length,sizeof(int),1,fid);
	fwrite(name,length,1,fid);
	xfree((void**)&name);

	/*Now write time and step: */
	fwrite(&time,sizeof(double),1,fid);
	fwrite(&step,sizeof(int),1,fid);

	/*Now write bool, after casting it: */
	boolean=(double)this->value;

	/*writing a double, type is 1, size is 1: */
	type=1;
	size=1;
	fwrite(&type,sizeof(int),1,fid);
	fwrite(&size,sizeof(int),1,fid);
	fwrite(&boolean,size*sizeof(double),1,fid);

}
/*}}}1*/
/*FUNCTION BoolExternalResult::GetResultName{{{1*/
void BoolExternalResult::GetResultName(char** pname){
	EnumToStringx(pname,this->enum_type);
}
/*}}}*/
/*FUNCTION BoolExternalResult::GetStep{{{1*/
int BoolExternalResult::GetStep(void){

	return this->step;
}
/*}}}*/
