//---------------------------------------------------------------------------

#ifndef TermH
#define TermH

class Term:public Cube {
  friend class PLA;
  private:
    string OM;          // the term output. '0', '1', '-' and '~' are valid values

  public:

    Term(void);
    Term( unsigned int iv, unsigned int ov );
    ~Term(void);

	void clear(void);				// clears all data
	void init( const unsigned int iv, const unsigned int ov );	// assigns all DC values to the term

		// setters and getters
    void SetOM( const unsigned int pos, const char val );      // sets one value in the OM
    void SetOM( const string val );      // sets OM
    char GetOM( const unsigned int pos ) const { return OM[pos]; };
    string GetOM(void) const { return OM; };
    unsigned int GetOMSize(void) const { return OM.size(); };
    unsigned int GetOC(void) const;
	unsigned int GetOutputs(void) const { return OM.size(); };	// returns the number of outputs
		
 //   void DiscardDim();            //will it be needed?
    bool Intersects( const Term& t ) const;					// do they intersect? Both inputs and outputs must intersect.
    int IntersectSize( const Term& t ) const;					// do they intersect? Both inputs and outputs must intersect. The number of DC x non-DCs or -1 is returned
    bool Intersects( const Term& t, const unsigned int _ov ) const;  // do they intersect in an output _ov?
    bool Contains( const Term& t ) const;					// does it contain t? Both inputs and outputs must match
	unsigned int Relation( const Term& t ) const;			// computes more complex relations (equality, containment, intersection)
	unsigned int Relation2( const Term& t ) const;			// computes more complex relations (equality, containment, intersection). Terminates when there is no IM intersection.
    void Merge( const Term& t );							// Merge the terms by output matrices. The terms are considered to have equal IM! Only for f(d) type!

		// for debug purposes
	unsigned short origin;		// bit 0 - produced by CD-S, bit 1 - produced by FC-Min, bit 2 - produced by IE, bit 3 - produced by IR
};

typedef list<Term> TermList;

//---------------------------------------------------------------------------
#endif