#include "../../include/CosiGlobal.h"

#ifndef CONSTRAINTPARSER_H_
#define CONSTRAINTPARSER_H_

#include <set>
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include "Constraint.h"
#include "../../environment/onchipcommunication/IpCore.h"
#include "../../environment/onchipcommunication/PlacedIpCore.h"
#include "tinyxml.h"

namespace cosi {

namespace io {

namespace onchipcommunication {

using namespace std ;
using namespace cosi::environment::onchipcommunication ;

class ConstraintParser {
public:

    /**\brief Constructor by file name.
     * This constructor takes as parameter the name of the file
     * that contains the description of all constraints.
     * */
    ConstraintParser( string pFname ) ;

	/**\brief This function parses the constraint file.
	 * */
    void Parse( ) ;

	/**\brief This function returns the set of placed IPs.
	 * This function returns the set of IPs that have already
	 * a position on the chip.
	 * */
    vector< PlacedIpCore > GetPlacedIpCore( ) ;


    PlacedIpCore  GetPlacedIpCore( string pName ) ;

    vector< IpCore > GetIpCore( ) ;

    IpCore GetIpCore(string pName) ;


    vector< Constraint > GetConstraints( ) ;

    set<int> GetExclusions( int i ) ;

    bool AllPlaced( ) ;

    void WritePlacement( string pFname) ;


private:

    void ParseNode( TiXmlNode* pParent ) ;

    void AddConstraint( TiXmlNode* pParent );

    void AddCore( TiXmlNode* pParent ) ;

    void AddExclusion( TiXmlNode* pParent ) ;


    string mFname ;

    vector< Constraint > mConstraint ;

    map< int , string > mIntToName ;
    map< string , int > mNameToInt ;

    //Exclusion sets
    map< string , set< string > > mExclusions ;

    bool mPlaced ;

    map< string , PlacedIpCore > mPlacedIp ;

    map< string , IpCore > mIp ;

} ;
}
}
}
#endif /*CONSTRAINTPARSER_H_*/
