/*
 *  Agent's ALLL register set
 *
 *  2004 - 2011 Frantisek Zboril jr.
 *  Faculty of Information Technology
 *  zborilf@fit.vutbr.cz
 *  http://www.fit.vutbr.cz/~zborilf
 *
 * (C) Brno University of Technology
 * Freeware licence VUT v Brně
 * https://wis.fit.vutbr.cz/FIT/db/dir.php/dr/VZ2007/externiInformace/softwareNaWebu/Priloha2_rozh23.pdf

 */

package jTMass.core.jAMass;

import jTMass.TMass;
import jTMass.core.jALLL.jTObjects.TAtom;
import jTMass.core.jALLL.jTObjects.TConstants;
import jTMass.core.jALLL.jTObjects.TObject;

public class TRegisters {
    
    private int PRegisterIndex=0;
    private TObject[] PRegister=new TObject[TConstants._NORegisters];
	
    // ===== TERMINAL =====

    public void printRegisters(){
        TObject object;
	for(int i=1; i<=TConstants._NORegisters; i++){
            object=getRegister(i);
            TMass._Terminal.printlnSystemInfo("REG "+i+": "+object.getContent());
	}
    }

    // ===== READERS, WRITERS =====
	
    public TObject getRegister(){
	return(PRegister[PRegisterIndex]);
    }
	
    public TObject getRegister(int nor){
    // indexed 1..NoRegister; array 0..NoRegister-1
        nor--;
        return(PRegister[nor]);
    }

    public int getSize(){
        int size=0;
        for(int i=0;i<TConstants._NORegisters;i++)
            size=size+PRegister[i].getContent().length();
        return(size);
    }
	
    public void setRegister(TObject data){
        PRegister[PRegisterIndex]=data;
	return;
    }
	
    protected void setRegister(int nor, TObject data){
        nor--;
	PRegister[nor]=data;
	return;
    }
	
    // ===== ACTIVE REGISTER

    public int switchRegister(int nor){
        nor--;
	if((nor>=0)&&(nor<TConstants._NORegisters)){
            PRegisterIndex=nor;
            return(nor);
	}
        return(-1);		// wrong register number
    }

    public int getActiveRegIndex(){
        return(PRegisterIndex);
    }

    // ===== CONSTRUCTOR =====

    public TRegisters(){
        PRegisterIndex=0;
	for(int i=0;i<TConstants._NORegisters;i++)
            PRegister[i]=new TAtom("$null");
    }
	
}
