Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

SIGEL_Program::SIG_ProgramLine Class Reference

This class represents a program line that contains robot instructions (and more). More...

#include <SIG_ProgramLine.h>

List of all members.

Public Methods

 SIG_ProgramLine ()
 This constructor initializes an empty program line that does not contain any elements. More...

 SIG_ProgramLine ( SIGEL_Tools::SIG_Randomizer &r, SIGEL_Robot::SIG_LanguageParameters &languageP, QArray< int > &prob )
 This constructor generates a random instruction that is dependend on the language parameters. More...

virtual ~SIG_ProgramLine ()
 An empty destructor. More...

void generateRandomRobotInstruction ( SIGEL_Robot::SIG_LanguageParameters &languageP, SIGEL_Tools::SIG_Randomizer &r, QArray< int > &prob )
 This function generates a random instruction that is dependend on the language parameters. More...

void clearLine ()
 This function deletes the data of a program line completely. More...

void copyLine ( SIGEL_Program::SIG_ProgramLine *source, SIGEL_Program::SIG_ProgramLine *destination )
 This instruction copies the program line source into the line destination. More...

void randomRobotinstruction ( SIGEL_Robot::SIG_LanguageParameters &languageP, SIGEL_Tools::SIG_Randomizer &r, QArray< int > &prob )
 This function generates randomly a robot instruction. More...

void print ()
 This function is only for test purposes and prints a program line. More...

void setElement ( int no, int value )
 This function sets an element (with index no) to the value. More...

void resizeElements ( int size )
 This function changes to size of the array that saves the elements. More...

void writeToFile ( QTextStream &file )
 This function writes a program line into a QTextStream. More...

bool readFromFile ( QString &str, SIGEL_Program::SIG_ProgramLine *line )
 This function will generate a program line from the read QTextStream.It will return true if a robot instruction could be generated. More...

void printToString (QString &lineStr)
 This function prepares a QString. More...

QArray< int > getElementsArray ()
 This function returns the array of a line's elements. More...

Robotinstruction getRobotinstructionType ()
 This function returns the type of the current robotinstruction. More...

int getInstructionElement (int no)
 This function returns the element of the current robotinstruction. More...

int getElement (int no)
 This function returns the element with the index no. More...

int getNumberOfElements ()
 This function gives an inormation about the number of elements at all. More...

SIGEL_Program::SIG_ProgramLine& operator= (SIGEL_Program::SIG_ProgramLine const & prgLine)
 This operator copies a complete program line. More...

void setRobotinstructionType ( Robotinstruction instr )
 Sets the robot instrction type, e.g. More...

void setRobotinstruction (SIGEL_Program::Robotinstruction instr, int op1, int op2)
 A robot instruction can be set explicitely by using this function. More...


Protected Methods

void readTwoRegisters (QString &str,int &reg1,int &reg2)
 Internal function, only internal usage. More...

void readOneRegisterAndIntegerConstant (QString &str,int &reg1,int &cnst)
 Internal function, only internal usage. More...

void readOneRegister (QString &str,int &reg)
 Internal function, only internal usage. More...


Protected Attributes

Robotinstruction instructionType
 The type of the current robot inbstruction, e.g. More...

QArray< int > element
 This array contains the elements of a program line. More...


Detailed Description

This class represents a program line that contains robot instructions (and more).

A program line is a set of elements. The meaning of the elements is dependend on the type of an instruction. Every instruction type defines a fix meaning for every element.

Definition at line 63 of file SIG_ProgramLine.h.


Constructor & Destructor Documentation

SIGEL_Program::SIG_ProgramLine::SIG_ProgramLine ( )
 

This constructor initializes an empty program line that does not contain any elements.

Postcondition:
An empty line that does not contain any data will be created.

Definition at line 23 of file SIG_ProgramLine.cpp.

SIGEL_Program::SIG_ProgramLine::SIG_ProgramLine ( SIGEL_Tools::SIG_Randomizer & r,
SIGEL_Robot::SIG_LanguageParameters & languageP,
QArray< int >& prob )
 

This constructor generates a random instruction that is dependend on the language parameters.

The probability to be chosen randomly is dependend on the given probabilities (prob).

Definition at line 34 of file SIG_ProgramLine.cpp.

SIGEL_Program::SIG_ProgramLine::~SIG_ProgramLine ( ) [virtual]
 

An empty destructor.

Postcondition:
All data is destructed.

Definition at line 26 of file SIG_ProgramLine.cpp.


Member Function Documentation

void SIGEL_Program::SIG_ProgramLine::clearLine ( )
 

This function deletes the data of a program line completely.

Postcondition:
The program line is deleted completely.

Definition at line 29 of file SIG_ProgramLine.cpp.

void SIGEL_Program::SIG_ProgramLine::copyLine ( SIGEL_Program::SIG_ProgramLine * source,
SIGEL_Program::SIG_ProgramLine * destination )
 

This instruction copies the program line source into the line destination.

Precondition:
The lines source and destination have to exist.
Postcondition:
The content of source has been copied into destination. WARNING: The content of destination will be deleted before the copy process starts.

Definition at line 857 of file SIG_ProgramLine.cpp.

void SIGEL_Program::SIG_ProgramLine::generateRandomRobotInstruction ( SIGEL_Robot::SIG_LanguageParameters & languageP,
SIGEL_Tools::SIG_Randomizer & r,
QArray< int >& prob )
 

This function generates a random instruction that is dependend on the language parameters.

The probability to be chosen randomly is dependend on the given probabilities (prob).

Definition at line 849 of file SIG_ProgramLine.cpp.

Referenced by SIG_ProgramLine().

int SIGEL_Program::SIG_ProgramLine::getElement ( int no )
 

This function returns the element with the index no.

Precondition:
The index must be smaller than the number of elements.
Returns:
This function returns the element with the index no (in case of a correct index)

Definition at line 171 of file SIG_ProgramLine.cpp.

Referenced by printToString(), and writeToFile().

QArray< int > SIGEL_Program::SIG_ProgramLine::getElementsArray ( )
 

This function returns the array of a line's elements.

Definition at line 166 of file SIG_ProgramLine.cpp.

int SIGEL_Program::SIG_ProgramLine::getInstructionElement ( int no )
 

This function returns the element of the current robotinstruction.

The first element, e.g. a register, is to be accessed with index 0. In case of an invalid access, e.g. a not defined index, this function returns -1. Example 1: LOAD 1,432 -> getInstructionElement(0)=1,getInstructionElement(1)=432; Example 2: ADD 1,2 -> getInstructionElement(0)=1,getInstructionElement(1)=2;

Returns:
This function returns (in case of a valid access) the element with the index no.

Definition at line 145 of file SIG_ProgramLine.cpp.

Referenced by SIGEL_Simulation::SIG_Interpreter::interprete(), and SIGEL_GP::SIG_GPOperations::mutation().

int SIGEL_Program::SIG_ProgramLine::getNumberOfElements ( )
 

This function gives an inormation about the number of elements at all.

Returns:
The number of elements will be returned.

Definition at line 216 of file SIG_ProgramLine.cpp.

Referenced by getElement(), getInstructionElement(), SIGEL_GP::SIG_GPOperations::mutation(), and setElement().

SIGEL_Program::Robotinstruction SIGEL_Program::SIG_ProgramLine::getRobotinstructionType ( )
 

This function returns the type of the current robotinstruction.

Definition at line 140 of file SIG_ProgramLine.cpp.

Referenced by SIGEL_Simulation::SIG_Interpreter::interprete(), SIGEL_GP::SIG_GPOperations::mutation(), printToString(), and writeToFile().

SIGEL_Program::SIG_ProgramLine & SIGEL_Program::SIG_ProgramLine::operator= ( SIGEL_Program::SIG_ProgramLine const & prgLine )
 

This operator copies a complete program line.

Postcondition:
The current program line will be copied completely.

Definition at line 9 of file SIG_ProgramLine.cpp.

void SIGEL_Program::SIG_ProgramLine::print ( )
 

This function is only for test purposes and prints a program line.

Definition at line 221 of file SIG_ProgramLine.cpp.

Referenced by SIGEL_GP::SIG_GPOperations::mutation().

void SIGEL_Program::SIG_ProgramLine::printToString ( QString & lineStr )
 

This function prepares a QString.

This QString will contain the current program line.

Postcondition:
The QString will contain the current program line.

Definition at line 230 of file SIG_ProgramLine.cpp.

Referenced by SIGEL_Simulation::SIG_Interpreter::interprete(), and print().

void SIGEL_Program::SIG_ProgramLine::randomRobotinstruction ( SIGEL_Robot::SIG_LanguageParameters & languageP,
SIGEL_Tools::SIG_Randomizer & r,
QArray< int >& prob )
 

This function generates randomly a robot instruction.

The choice is depended on the current language parameters and the given probabilities (prob).

Definition at line 657 of file SIG_ProgramLine.cpp.

Referenced by generateRandomRobotInstruction(), and SIGEL_GP::SIG_GPOperations::mutation().

bool SIGEL_Program::SIG_ProgramLine::readFromFile ( QString & str,
SIGEL_Program::SIG_ProgramLine * line )
 

This function will generate a program line from the read QTextStream.It will return true if a robot instruction could be generated.

If no defined instruction could be generated, the current read line will be ignored. So comments can be used within a robot program. Comments always have to use a complete line, and comments are not allowed to contain any keywords (=robot instructions, e.g. ADD).

Precondition:
The QTextStream file must exist, and it has to contain a complete program line. Either this text stream has been created by writeToFile, or the stream has been edited by the user. The stream has to have a defined format, which is described more in detail in the corresponding specification.
Postcondition:
The program line, which is described in the text stream, has been transfered (and translated) into a (new created) program line. All neccessary data is prepared. WARNING: An existing program line will be deleted by calling this function.

Definition at line 456 of file SIG_ProgramLine.cpp.

Referenced by SIGEL_Program::SIG_Program::readFromFile().

void SIGEL_Program::SIG_ProgramLine::readOneRegister ( QString & str,
int & reg ) [protected]
 

Internal function, only internal usage.

Definition at line 341 of file SIG_ProgramLine.cpp.

Referenced by readFromFile().

void SIGEL_Program::SIG_ProgramLine::readOneRegisterAndIntegerConstant ( QString & str,
int & reg1,
int & cnst ) [protected]
 

Internal function, only internal usage.

Definition at line 372 of file SIG_ProgramLine.cpp.

Referenced by readFromFile().

void SIGEL_Program::SIG_ProgramLine::readTwoRegisters ( QString & str,
int & reg1,
int & reg2 ) [protected]
 

Internal function, only internal usage.

Definition at line 413 of file SIG_ProgramLine.cpp.

Referenced by readFromFile().

void SIGEL_Program::SIG_ProgramLine::resizeElements ( int size )
 

This function changes to size of the array that saves the elements.

Postcondition:
The size of the array will be changed. WARNING: Values (above the new size) are deleted (and lost).

Definition at line 336 of file SIG_ProgramLine.cpp.

Referenced by setRobotinstruction().

void SIGEL_Program::SIG_ProgramLine::setElement ( int no,
int value )
 

This function sets an element (with index no) to the value.

value has to be a pre-defined constant value.

Postcondition:
The element (with index no) is set to value.

Definition at line 193 of file SIG_ProgramLine.cpp.

Referenced by operator=(), and setRobotinstruction().

void SIGEL_Program::SIG_ProgramLine::setRobotinstruction ( SIGEL_Program::Robotinstruction instr,
int op1,
int op2 )
 

A robot instruction can be set explicitely by using this function.

The robot instruction is set to instructionType. The operands are defined by op1 and op2. If an instruction only needs one operad (op1) the second operand (op2) will be ignored.

Definition at line 46 of file SIG_ProgramLine.cpp.

Referenced by SIGEL_GP::SIG_GPOperations::mutation(), randomRobotinstruction(), and readFromFile().

void SIGEL_Program::SIG_ProgramLine::setRobotinstructionType ( Robotinstruction instr )
 

Sets the robot instrction type, e.g.

SIGEL_Program::COPY, ...

Definition at line 41 of file SIG_ProgramLine.cpp.

Referenced by operator=(), and setRobotinstruction().

void SIGEL_Program::SIG_ProgramLine::writeToFile ( QTextStream & file )
 

This function writes a program line into a QTextStream.

Postcondition:
The current program line will be added to the given QTextStream.

Definition at line 563 of file SIG_ProgramLine.cpp.


Member Data Documentation

QArray< int > SIGEL_Program::SIG_ProgramLine::element [protected]
 

This array contains the elements of a program line.

Elements are coded with values between 0 and MAXINT. The meaning of these elements is dependend on the instruction type. Elements can represent registers or integer values.

Definition at line 80 of file SIG_ProgramLine.h.

Robotinstruction SIGEL_Program::SIG_ProgramLine::instructionType [protected]
 

The type of the current robot inbstruction, e.g.

LOAD, COPY, ...

Definition at line 71 of file SIG_ProgramLine.h.


The documentation for this class was generated from the following files:
Generated at Mon Sep 3 01:32:53 2001 for PG 368 - SIGEL by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000