GEGELATI

Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
Program::Program Class Reference

The Program class contains a list of program lines that can be executed within a well defined Environment. More...

`#include <program.h>`

## Public Member Functions
| Program (const Environment &e, bool actProgram)
| Main constructor of the Program.
| Program (const Program &other)
| Copy constructor of the Program.
| Program (const Program &other, bool actProgram)
| Copy constructor of the Program.
Program & | operator= (const Program &other)=delete
| ~Program ()
| Destructor for the Program class.
Line & | addNewLine ()
| Add a new line to the Program with only 0 bits.
Line & | addNewLine (const uint64_t idx)
| Add a new line to the Program with only 0 bits.
void | addNewLine (Line newLine)
| Add a new line to the Program at the end of the program.
void | clearIntrons ()
| Clear all intron instructions in the Program.
void | removeLine (const uint64_t idx)
| Remove a Line from the Program.
void | swapLines (const uint64_t idx0, const uint64_t idx1)
| Swap two existing lines from the Program.
const Environment & | getEnvironment () const
| Get the environment associated to the Program at construction.
size_t | getNbLines () const
| Get the number of lines in the Program.
const Line & | getLine (uint64_t index) const
| Get a const ref to a Line of the Program.
Line & | getLine (uint64_t index)
| Get a non-const ref to a Line of the Program.
bool | isIntron (uint64_t index) const
| Checks whether a Line at the given index is an intron.
bool | isActionProgram () const
| Checks wether the current program is or not an action program.
uint64_t | identifyIntrons ()
| Scan the Line of the Program to identify introns.
Data::ConstantHandler & | getConstantHandler ()
| get the constantHandler object of the Program
const Data::ConstantHandler & | cGetConstantHandler () const
| get a const reference to the constantHandler object of the Program
const Data::Constant | getConstantAt (size_t index) const
| Get the value of a constant at a given index.
bool | hasIdenticalBehavior (const Program &other) const
| Check if two Program have the same behavior.
uint64_t | getProgramID () const
| Get the unique identifier of the Program.
virtual void | setProgramID (uint64_t newID)
| Set a new unique identifier to the Program.

## Static Public Member Functions
static uint64_t | getProgramIDCounter ()
| Get the current value of the program ID counter.

## Protected Member Functions
| Program ()=delete
| Delete the default constructor.

## Static Protected Member Functions
static uint64_t | incrementeCounter ()
| Incremente the program ID counter and return the new value.
static void | resetProgramIDCounter ()
| Reset the program ID counter.

## Protected Attributes
const Environment & | environment
| Environment within which the Program will be executed.
bool | actionProgram
| Boolean indicating if true that the program is an action program, if false that it is a context program.
std::vector< std::pair< Line *, bool > > | lines
| Lines of the program and intron property.
Data::ConstantHandler | constants
| Constants of the Program.
uint64_t | programID
| Unique identifier of the Program.

## Friends
struct | ::CounterReset

## Detailed Description

The Program class contains a list of program lines that can be executed within a well defined Environment.

## Constructor & Destructor Documentation

## ◆ Program() [1/3]

Program::Program::Program | ( | const Environment & | e,
|  | bool | actProgram )
| inline

Main constructor of the Program.

Parameters

  [in] | e | the reference to the Environment that will be referenced
  [in] | actProgram | boolean specifying if the program is action or context in the Program attributes.

## ◆ Program() [2/3]

Program::Program::Program | ( | const Program & | other | ) |
| inline

Copy constructor of the Program.

This copy constructor realises a deep copy of the Line of the given Program, instead of the default shallow copy.

Parameters

  [in] | other | a const reference the the copied Program.

## ◆ Program() [3/3]

Program::Program::Program | ( | const Program & | other,
|  | bool | actProgram )
| inline

Copy constructor of the Program.

This copy constructor realises a deep copy of the Line of the given Program, instead of the default shallow copy.

Parameters

  [in] | other | a const reference the the copied Program.
  [in] | actProgram | boolean specifying if the program is action or context

## ◆ ~Program()

Program::Program::~Program | ( |  | ) |

Destructor for the Program class.

This destructor deallocates all memory allocated for Program lines (if any).

## Member Function Documentation

## ◆ addNewLine() [1/3]

Program::Line & Program::Program::addNewLine | ( |  | ) |

Add a new line to the Program with only 0 bits.

The new line is inserted at the end of the program.

Returns
  a non-const reference to the newly added Line.

## ◆ addNewLine() [2/3]

Program::Line & Program::Program::addNewLine | ( | const uint64_t | idx | ) |

Add a new line to the Program with only 0 bits.

The new line is inserted at the given position of the program.

Parameters

  [in] | idx | the position at which the line should be inserted.

Returns
  a non-const reference to the newly added Line.

Exceptions

  std::out_of_range | if the given position is beyond the end of the Program.

## ◆ addNewLine() [3/3]

void Program::Program::addNewLine | ( | Line | newLine | ) |

Add a new line to the Program at the end of the program.

Parameters

  [in] | newLine | new Line added to the program

## ◆ cGetConstantHandler()

const Data::ConstantHandler & Program::Program::cGetConstantHandler | ( |  | ) | const

get a const reference to the constantHandler object of the Program

This method gives a const reference to the constantHandler associated with the program

Returns
  the constantHandler of the program through a const reference

## ◆ clearIntrons()

void Program::Program::clearIntrons | ( |  | ) |

Clear all intron instructions in the Program.

All introns lines from the Program are removed by this method. The behavior of the Program should not be modified after a call to this function.

Introns should have been identified before calling this methos, as this method does NOT call the identifyIntrons method.

## ◆ getConstantAt()

const Data::Constant Program::Program::getConstantAt | ( | size_t | index | ) | const

Get the value of a constant at a given index.

Although this method is not required as the data is accessible from the constantHandler, it allows a shortcut and add readability.

Parameters

  [in] | index | the position at which we access the constant

Returns
  the value of the constant at the given index

## ◆ getConstantHandler()

Data::ConstantHandler & Program::Program::getConstantHandler | ( |  | ) |

get the constantHandler object of the Program

This method gives a reference to the constantHandler associated with the program

Returns
  the constantHandler of the program

## ◆ getEnvironment()

const Environment & Program::Program::getEnvironment | ( |  | ) | const

Get the environment associated to the Program at construction.

Returns
  a const reference to the Environment of the Program and all its Line.

## ◆ getLine() [1/2]

Program::Line & Program::Program::getLine | ( | uint64_t | index | ) |

Get a non-const ref to a Line of the Program.

Parameters

  [in] | index | The integer index of the retrieved Line within the Program.

Returns
  a const reference to the indexed Line of the Program.

Exceptions

  std::out_of_range | if the index is too large.

## ◆ getLine() [2/2]

const Program::Line & Program::Program::getLine | ( | uint64_t | index | ) | const

Get a const ref to a Line of the Program.

Parameters

  [in] | index | The integer index of the retrieved Line within the Program.

Returns
  a const reference to the indexed Line of the Program.

Exceptions

  std::out_of_range | if the index is too large.

## ◆ getNbLines()

size_t Program::Program::getNbLines | ( |  | ) | const

Get the number of lines in the Program.

Returns
  the number of line contained in the Program.

## ◆ getProgramID()

uint64_t Program::Program::getProgramID | ( |  | ) | const

Get the unique identifier of the Program.

Returns
  the unique identifier of the Program.

## ◆ getProgramIDCounter()

uint64_t Program::Program::getProgramIDCounter | ( |  | ) |
| static

Get the current value of the program ID counter.

This method is mainly used for testing purpose to ensure that program IDs are predictable.

Returns
  the current value of the program ID counter.

## ◆ hasIdenticalBehavior()

bool Program::Program::hasIdenticalBehavior | ( | const Program & | other | ) | const

Check if two Program have the same behavior.

Two Program have the same behaviour if their sequence of non-intron Lines are strictly identical (i.e. same instructions and operands, in the same order, and used Constant with identical values).

Parameters

  [in] | other | the Program whose behavior is compared.

## ◆ identifyIntrons()

uint64_t Program::Program::identifyIntrons | ( |  | ) |

Scan the Line of the Program to identify introns.

This method update the boolean value associated to each Line of the Program to indicate if this Line is an intron or not.

Returns
  the number of intron Lines idendified.

## ◆ isActionProgram()

bool Program::Program::isActionProgram | ( |  | ) | const

Checks wether the current program is or not an action program.

Returns
  true if the procram is an action program.

## ◆ isIntron()

bool Program::Program::isIntron | ( | uint64_t | index | ) | const

Checks whether a Line at the given index is an intron.

Parameters

  [in] | index | The integer index of the checked Line within the Program.

Returns
  true if the Line is an intron, false otherwise.

Exceptions

  std::out_of_range | if the index is too large.

## ◆ operator=()

Program & Program::Program::operator= | ( | const Program & | other | ) |
| delete

Disable Program default assignment operator.

Until we see the need for it, there si no reason to enable assignment operator of Program.

## ◆ removeLine()

void Program::Program::removeLine | ( | const uint64_t | idx | ) |

Remove a Line from the Program.

Remove the Line at the given index from the Program and free the associated memory.

Parameters

  [in] | idx | the integer index of the Program Line to remove.

Exceptions

  std::out_of_range | if the index is too large.

## ◆ resetProgramIDCounter()

void Program::Program::resetProgramIDCounter | ( |  | ) |
| static protected

Reset the program ID counter.

This method set the ID counter to a new value. It can quickly lead to segmentation fault if not used carefully.

## ◆ setProgramID()

void Program::Program::setProgramID | ( | uint64_t | newID | ) |
| virtual

Set a new unique identifier to the Program.

Parameters

  [in] | newID | the new integer ID to set to the Program.

## ◆ swapLines()

void Program::Program::swapLines | ( | const uint64_t | idx0,
|  | const uint64_t | idx1 )

Swap two existing lines from the Program.

Parameters

  [in] | idx0 | the index of the first line to swap.
  [in] | idx1 | the index of the second line to swap.

Exceptions

  std::out_of_range | if any of the two index is too large.

## Member Data Documentation

## ◆ actionProgram

bool Program::Program::actionProgram
| protected

Boolean indicating if true that the program is an action program, if false that it is a context program.

An action program is a program used for taking continuous actions, in contrast with classic, or context programs, that output a bid. An Action program source must be a TPGAction.

## ◆ constants

Data::ConstantHandler Program::Program::constants
| protected

Constants of the Program.

A Program contains a set of constants in a dedicated Data::DataHandler

## ◆ lines

std::vector<std::pair<Line*, bool> > Program::Program::lines
| protected

Lines of the program and intron property.

Each element of this vector stores a pointer to a Line, and a boolean value indicating whether this Line is an Intron whithin the program.

Introns are Lines of the program that do not contribute to its final result, stored in the first register. Hence, skipping these lines during a program execution can speed up the Program execution.

The documentation for this class was generated from the following files:

- D:/a/gegelati/gegelati/gegelatilib/include/program/program.h
- D:/a/gegelati/gegelati/gegelatilib/src/program/program.cpp