#include<fstream>
#include<string>

#include "Piece.h"
#include "Rule.h"

Piece::Piece(Rule* rule){
    string desFileName = "pieces/" + rule->getType() + ".des";
    ifstream ifs(desFileName.c_str());
    if(!ifs.is_open()){
        cout << "Description files missing." << endl;
        exit(1);
    }
    char opChar;
    unsigned  int attribute;
    
    //cout << "Creating new piece from rule:" 
            //<< rule->getName() << endl;
    
    this->rule=rule;
    inputY=new vector<int>();
    outputY=new vector<int>();
    
    while(!ifs.eof()){
        ifs >>opChar >> ws >> attribute;
        if(opChar=='w'){
            width=attribute;
            //cout << "\t width:" << width << endl;
        }
        if(opChar=='h'){
            height=attribute;
            //cout << "\t height:" << height << endl;
        }
        if(opChar=='i'){
            inputY->push_back(attribute);
            //cout << "\t input y:" << attribute << endl;
        }
        if(opChar=='o'){
            outputY->push_back(attribute);
            //cout << "\t output y:" << attribute << endl;
        }
    }
    ifs.close();
}

bool Piece::operator<(Piece &p){
	return (y < p.y);
}

