Open main menu

CDOT Wiki β

OOP344 Assignment Two

Revision as of 01:12, 2 November 2009 by Fardad (talk | contribs) (Constructor)

OOP344 - OOP344 Student List - OOP344 Teams - OOP344 Assignment One - OOP344 Assignment Two - OOP344 IRC Schedules
Under construction...


File Names

Save your work in separate files for each class. Name the files to the same name as the classes. Each class should have a header file and a code file.

For example for the class IOField, create iofield.h and iofield.cpp. The header file should hold the class declaration and any other possible declaration related to the class. the "cpp" file should hold the definition (implementation) of the class and its methods and possible functions.

Create a Make file to build your project with respect to dependencies of classes.

SVN Quick Notes

  1. Checkout the code $svn co svn://zenit.senecac.on.ca/ops344_093aXX/trunk/PRJ --username yourUserName
  2. Add selected ciol.h ciol.cpp and if present the class files (all compiled) $svn add filename
  3. Commit the new files $svn commit
  4. Team members check out the individually
  5. development starts.

How to reuse your C code in C++ programs

Include your already existing C code into your C++ code as follows:

extern "C"{
#include "ciol.h"
};

This tells to C++ compiler, the included header file contains C functions and should be complied and called as such. Remember, you do not need and should not rename your ciol.c to ciol.cpp, since the compiler is already aware of the C functions in ciol.c.

Team Project Wiki Pages

Add a link to your Team project Wiki pages here:

West Side Connection

A Team

All are welcome

BITE

Team ++ website

Team BINGO

Team Temporary Name

Team Funktion website

Best Team Ever :)

ASOS_Brigade

General Definition Header file

create a file called: io_def.h. This file will contain any nessecary definitions or inclusions for the project. ultimately, users (future programmers) will only include this header file to be able to use the IO Classes. for now add the following define statements in io_def.h

#define IO_NO_ACTION (0x1)
#define IO_CLEAR (0x2)
#define IO_SHOW_ALL (0x4)
#define IO_SHOW_ERROR (0x8)
#define IO_SHOW_HELP (0x16)
#define _FRAME_CHARS "|+-+|+-+"

Mandatory Classes

As the first part of your project this semester, you are to create few classes to encapsulate Console Input Output Library

IO_Field

IO_Field is the base class for all different types of Fields on a Form.

class IO_Form;  // forward declaration
class IO_Field{
protected:
  void* _data;
  int _row;
  int _col;
public:
  IO_Field(int row, int col);
  void* Data();
  virtual void Display() = 0;
  virtual int Edit(IO_Form* Owner=NULL)= 0;
  virtual bool Editable() = 0;
  virtual void Set(const void *) = 0;
  virtual ~IO_Field();
};

IO_Field(int row, int col);

This constructor set the corresponding attributes to the values of incoming arguments and sets the data attribute to NULL.


void* Data();

Returns the value of the data attribute.

virtual ~IOField();

An empty destructor (the body of the method is blank)

virtual void Display() = 0;
virtual int Edit(IO_Form* Owner=NULL)= 0;
virtual bool Editable() = 0;
virtual void Set(const void *) = 0;


These are pure virtual methods enforcing the creation of the identical methods in the derived classes. This make the IO_Field class an abstract class. Note: The purpose of passing a IO_Form pointer to the Edit method, is to make the future Edit methods capable of sending a message (errors and help messages)to the Screen they are being Edited on.


IO_Frame

IO_Frame class, encapsulates a frame. It Draws a frame at left top corner of col and row with specified width and height.

A Frame can be instantiated as follows:

IO_Frame(int row, int col, int width, int height, const char* frameChars = (const char*)0);

the frameChars are characters used to draw the frame, characters in order are:

  1. left side
  2. left top corner
  3. top side
  4. top right corner
  5. right side
  6. right bottom corner
  7. bottom side
  8. bottom left corner

So to draw this:

  /--------\
  |        |
  |        |  
  |        |
  \--------/

frame chars should be:

"|/-\|/-\"

If however, the frameChars argument is missing (it is NULL) then a defaut, defined value in "io_def.h"; _FRAME_CHARS should be used.

Public Method

void Display(void);

Display(), displays the frame with the specified coordinates and size in its constructor

Destructor

IO_Frame has a virtual destructor. This destructor does nothing.


IO_Form

IO_Frame is inherited into a container class called IO_Form. IO_Form organizes the IO_Field classes and give the user a panel to use them sequentially.

IO_Form should be able to hold unlimited number of IO_Fields. (Use either a dynamic array, or linked list structure of IO_Fields to implement this)

Constructor

IO_Form is constructed as follows:

 IO_Form(bool framed = false, 
         int row = 0, int col = 0 , int width = 0 , int height = 0, 
         const char* frameChars = (const char*)0);

framed: if true, IO_Form will use its parent to draw a frame around itself when

  display()ed
row, col, width and height are passed to the parent under following conditions:
  if framed is true and width or height are 0 (zero) then the full size of the 
  terminal is used for dimensions of the IO_Frame.


Public Methods

Add methods

the IO_Form must be able to add several IO_Field classes to itself, one at a time and then provide the user, the means of editing them in order they were added.

int add(IO_Field* f, bool dynamic, bool submitter);

IO_Form uses this private add method to provide means of adding fields through several public add methods. this method adds an IO_Field to the end of the IO_Fields in the IO_Form;

  • f: is the address of the IO_Field begin added to the IO_Form
  • dynamic: if set to true, it sets this IO_Field to be deallocated by IO_Form's destructor at the end;
  • submitter: if set to true, it tags this IO_Field to terminate the IO_Form's edit() if ENTER_KEY is hit. see the edit() method for more info.
int add(IO_Field* f, bool submitter  = false);

Uses the private add() method to add a dynamaic IO_field.


int add(IO_Field& f, bool submitter = false);

Uses the private add() method to add a non-dynamaic IO_field.


int addHelp(IO_Label* L);

Uses the private add() method to add a dynamaic IO_field and also saves its address for the general help message label of the Form.


int addHelp(IO_Label& L);

Uses the private add() method to add a non-dynamaic IO_field and also saves its address for the general help message label of the Form.


int addError(IO_Label* L);

Uses the private add() method to add a dynamaic IO_field and also saves its address for the general error message label of the Form.


int addError(IO_Label& L);

Uses the private add() method to add a dynamaic IO_field and also saves its address for the general error message label of the Form.


--- incomplete ----

IO_Label

IO_Label class mostly, encapsulates the io_display() function. Inherit a new class called IO_Label from IO_Field to Display a text message on IO_Form. In addition to the attributes of its parent IO_Field, IO_Label has a private integer attribute called _len. _len is used to hold the length of Field in which the text is to be displayed. IO_Label could hold its data dynamically or simply point to an external one. Because of this IO_Label also has a boolean attribute called _dynamic that will hold the type of data within; being dynamic memory (value true), or external memory (value false) IO_Label can be created in two ways;

  IO_Label(int row, int col, int len);

This constructor will create an empty (blank) IO_Label with capacity of len characters. In this case row and col are passed to the parent for initialisation and _len (the attribute) is set to the incoming argument len.

Then IO_Field::_data will be set to the address of a newly allocated memory to the size of _len + 1 bytes which also will be set to an empty string.

Note that data is a void pointer; to use it here, you must cast it to a character pointer!

_dynamic attribute is set to true in this case.

  IO_Label(char* str, int row, int col, int len = -1);

This constructor will create an IO_Label, with its IO_Field::_data pointing to where str is pointing to.

Like the previous constructor it will pass row and col to its parent and set the _len attribute to the incoming len argument. _dynamic attribute is set to false in this case, since the data of the class is external.

Public Methods

void Display(void);

Display() is a direct call to io_display() function printing _data, at _row and _col up to _len characters. If _len is less than zero, then _data will be printed to the end.

  void Set(const void* str);

Set() will copy the content of str into IO_Field::_data up to _len characters, if _len is not negative.

bool IO_Label::Editable(void)const;

Editable() returns false!.

  int Edit(IO_Form* Owner=(IO_Form*)0);

Edit(), Calls Display() and returns 0. This method ignores the Owner, IO_Form pointer.

   ~IO_Label(void);

The destructor, delete[]s the _data only if _dynamic is true.

  IO_Label &operator=(const char* str);

operator=(), Calls Set() and returns itself.

IO_Edit

IO_CheckList

IO_Radio

IO_Menu

IO_MenuBar

IO_TextEdit

The Text Editor

Tips

Fardad adds io_textedit

This is an edited dialogue copied from an IRC meeting

fardad: I am going to do IO_TextEdit. I will right the steps as I am doing it

  1. I am adding a headerfile and cpp file to my visual studio
  2. In solution exp. rightclick on headerfiles, add / new item
  3. Added code/headerfile: "io_textedit.h"
  4. Now i am righclicking on sourcefiles/newitem code/cpp file
  5. Added save (gard?) code to the headerifle
  6. Included general headerifle in io_textedit.h. It will have all necessary definitions and includes for the project
  7. Adding io_textedit.h and io_textdit.cpp to rep
  8. Compiled and it was successful, so I will commit now

fardad: Done, you can now update you working copy and see what I did. You should do the same for all the other classes. It should not take you more than 30 minutes to do you part, just pick a class and write it.