OOP344 Assignment Two

From CDOT Wiki
Revision as of 11:57, 3 November 2009 by Fardad (talk | contribs) (Displaying the Form)
Jump to: navigation, search

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.

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.


Destructor

virtual ~IO_Form();

When IO_Form is going out of scope, is being destroyed, all dynamic IO_Fields are deleted. (the rest will not be deallocated)


Privete Methods

Adding a Field to the Form

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.

add() returns the number of fields currently in IO_FORM.


Public Methods

Add methods

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

Uses the private add() method to add a dynamic 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.


IO_Form &operator<<(IO_Field* f);

Uses the private add() method to add a non-submitter, dynamic IO_field.


IO_Form &operator<<(IO_Field& f);

Uses the private add() method to add a non-submitter, non-dynamic IO_field.


Setting General Error and Help messages

void setError(const char* mes);
void setHelp(const char* mes);

Set the text of the general Error message and the general Help message of the Form.


Number of fields in Form

int lenght();

Returns number of fields currently in IO_Form.


Acessing Field Data

void* data(unsigned int fieldnumber=0);

Returns address of the data of "fieldnumber"th, IO_Field in the IO_Form. If "fieldnumber" is zero, then it returns the data of the current IO_Field.



The index operator

IO_Field& operator[](unsigned int index);

Returns the reference of the IO_Field, number "fieldnumber-1". First Field has the index 0;


Displaying the Form

void display(unsigned int how = IO_CLEAR | IO_SHOW_ALL ,unsigned int fieldnumber = 0 );  

Displays the Form and all the Fields on it. fieldnumber is the number of the field that was returned by any of the add() functions. how: is a binary mask, and following bits can be set in it:

IO_CLEAR (0x2u)
IO_SHOW_ALL (0x4u)
IO_SHOW_ERROR (0x8u)
IO_SHOW_HELP (0x16u)

The display function work in following order:

  1. If IO_CLEAR bit is set in how, then before anything the screen should be be cleared.
  2. If the field number is 0 (zero) then
    1. if IO_SHOW_ALL is set in how, then all the fields are displayed in the order they where added
    2. otherwise either of IO_SHOW_ERROR or IO_SHOW_HELP is set, only their corresponding designated IO_Label will be displayed.
  3. if the filed number is not zero, then the IO_Field number "fieldnumber" will be displayed. If the number is larger than the number of fields in the IO_Form then it will be rotated back from the beginning. (i.e. if there are 4 fields in the form and fieldnumber is 5, then filed number 1 will be displayed)

Editing(running) the Form

int edit(unsigned int fieldnumber = 0);

--- 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 holds its data dynamically and will never point to an external one. 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!

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

If len is greater than zero, This constructor will create an IO_Label by allocating len + 1 characters pointed by IO_Field::_data, and then the contents of str is copied into IO_Fiedl::_data up to len characters. _len attribute is set to len; If len is less than or equal to zero, then len will be set to the length of str and then constructor will work as previous case. Like the previous constructor it will pass row and col to its parent.

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. (make sure _data is casted to char* before deleting.

  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

IO_Form

If you want to use a linkedlist to implement IO_Form having a node like this would be a good idea:

class IO_Node{
  IO_Field* _f;
  bool _dynamic;
  bool _submitter;
  IO_Node* next;
  IO_Node* prev;
  ...
  ...
  ...
};

And then make your IO_Form a linkedlist of IO_Nodes....

With this you can have the IO_field kept in the node and at the same time keep track of the IO_Field being dynamically created and if it is a submitter or not. So the data of the node will be the three attributes; _f, _dynamic, and submitter.

Fardad adds io_textedit

This is an edited dialogue copied from an IRC meeting

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

  1. I am adding a headerfile and cpp file to my visual studio this will add the headerfile and the cpp file to the working copy.
  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 inclusion guards code to the headerifle (#ifndef __IO_TEXTEDIT_H__.....)
  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 working copy($svn add ..., this tags them to be added to repository the next time svn is commited)
  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.