DEPARTMENT OF COMPUTING

CS 3005: Programming in C++

Examples Using ActionData

Replacing Parameters with ActionData&

Most functions will need an updated parameter list, that replaces several parameters with an ActionData reference. The internals of the functions will then use the data members of the ActionData object instead of the previous parameters. Here is an example of the changes to the getInteger function:

Previously:

int getInteger( std::istream& is, std::ostream& os, const std::string& prompt ) {
  int n;
  os << prompt;
  is >> n;
  return n;
}

Now:

int getInteger( ActionData& action_data, const std::string& prompt ) {
  int n;
  action_data.getOS() << prompt;
  action_data.getIS() >> n;
  return n;
}

Be sure to update the header file (image_menu.h) declaration as well as the implementation in the correct .cpp file.

Creating an ActionData Object

Many of the functions in controllers.cpp will need to update the way they call other functions, by first creating an ActionData object to be passed. Some may also need to copy the changes made to the input image 1 into the output image of the ActionData object.

Previously:

int assignment2( std::istream& is, std::ostream& os ) {
  Image image;
  diagonalQuadPattern(is, os, image);
  drawAsciiImage(is, os, image);
  return 0;
}

Now:

int assignment2(std::istream& is, std::ostream& os) {
  ActionData action_data(is, os);
  diagonalQuadPattern(action_data);
  copyImage(action_data);
  drawAsciiImage(action_data);
  return 0;
}

Last Updated 02/17/2021