#ifndef _AP_RESULT_H_
#define _AP_RESULT_H_

#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>

#include "parse.h"
#include "xml_util.h"
#include "track_mem.h"
#include "db_table.h"
#include "../db/ap_schema.h"


#include "ap_validate_inc.h"

/*BOINC LIB*/
#include "parse.h"

// Result Flags.  Can be passed from validator to assimilator
// via the BOINC result.opaque field.  Note that you have
// to cast to float in order to assign a flag to the opaque
// field.  OR into a temp int and then assign with a cast.
#define RESULT_FLAG_OVERFLOW 0x00000001

class ResultFile : public track_mem<ResultFile> {
private:
	int max_coadd;
	vector<float> thresholds;

	std::string get_result_file(RESULT& result);
	int parse_file(RESULT& result);
	int overflow_result(RESULT& result);

public:
	vector<ap_signal> pulses;
	bool has_pulse;
	int result_id;
	int validate_state;
	double claimed_credit;

	ResultFile() : track_mem<ResultFile>("ResultFile"), 
	  max_coadd(0), thresholds(), pulses(), has_pulse(false), 
	  result_id(0), validate_state(0), claimed_credit(0) {};
	ResultFile(const ResultFile &a) : track_mem<ResultFile>("ResultFile (copy)"), 
	  max_coadd(a.max_coadd), thresholds(a.thresholds), pulses(a.pulses),
	  has_pulse(a.has_pulse), result_id(a.result_id),
	  validate_state(a.validate_state), claimed_credit(a.claimed_credit) {};
	ResultFile(RESULT& result);
	int init(RESULT& result);
};

#endif
