#ifndef POST_H
#define POST_H

#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <ccmio.h>
#include "IOException.h"

typedef std::basic_string<char> String;

using namespace std;
struct BoundaryData {
    int id;
    float priority;
    float value[9];

    BoundaryData() : id(0), priority(0)
	{
	    for (int i = 0;  i < 9;  ++i)
		this->value[i] = 0.0;
	};
    bool operator==(const BoundaryData& that) const
	{
	    for (int i = 0;  i < 9;  ++i)
		if (this->value[i] != that.value[i])
		    return(false);
	    return(this->id == that.id &&
		   this->priority == that.priority);
	};
    bool operator!=(const BoundaryData& that) const
	{ return(!(*this == that)); };
};

std::ostream& operator<<(std::ostream& out, BoundaryData& data);

class PostField {
 public:
    typedef std::map<int, BoundaryData> BoundaryArray;
    typedef std::vector<float> DataArray;
    
    std::basic_string<char> name;
    DataArray data;
    BoundaryArray boundaryData;
    std::vector<bool> cellmap;

    PostField( const char *_name )
	: name(_name), dims(0)
	{};
    int GetDims() { return(this->dims); };

 protected:
    int dims;
};

struct PostScalarField : public PostField {
    PostScalarField( const char *name )
	: PostField(name)
	{ this->dims = 1; };
};

struct PostVectorField : public PostField {
    PostVectorField( const char *name )
	: PostField(name)
	{ this->dims = 2; };
};

class Post {
 public:
    typedef std::map< String, PostField* > FieldArray;

    Post() {};
    virtual ~Post()
	{
	    FieldArray::iterator f;

	    for (f = this->fields.begin();  f != this->fields.end();  ++f)
		delete f->second;
	};

    bool WriteCCMIO( CCMIOID& processor );

    bool operator== (const Post& that) const;
    inline bool operator!= (const Post& that) const
	{ return(!(*this == that)); };

 protected:
    FieldArray fields;
};

#endif // POST_H
