Difference between revisions of "Console UI Core Classes - OOP344 20121"

From CDOT Wiki
Jump to: navigation, search
(Attributes)
(Constructors / Destructor)
Line 147: Line 147:
 
   CLabel(const CLabel& L);
 
   CLabel(const CLabel& L);
 
</syntaxhighlight></big>
 
</syntaxhighlight></big>
<del>A private and empty copy Constructor. This prevents copying CLabel.</del><br />
 
 
Copies a CLabel safely to guaranty there is no memory leak.
 
Copies a CLabel safely to guaranty there is no memory leak.
 
<big><syntaxhighlight lang="cpp">
 
<big><syntaxhighlight lang="cpp">

Revision as of 14:50, 15 February 2012

Objective

Your objective at this stage is to create series of core classes designed to interact with the user. These Core Classes then can be used in development of any interactive application.

Please note that the class definitions here are minimum requirement for the Core Classes and you are free to add any enhancements or features you find useful. However make sure that you discuss these enhancements with your professor to make sure they are feasible before implementation.

It is highly recommended to develop the classes in the order they are stated here. You must create your own tester programs for each class (if possible); However, close to due date of each release, a tester program may be provided to help you verify the functionality of your classes. If tester programs are provided, then executables of the test programs will be available on matrix to show you how it is supposed to run.

Start by creating mock-up classes (class declaration and definition with empty methods that only compiles and don't do anything). Each class MUST have its own header file to hold its declaration and "cpp" file to hold its implementation. To make sure you do not do circular includes follow these simple guidelines:

  • Add recompilation safeguards to all your header files.
  • Always use forward declaration if possible instead of including a class header-file.
  • Use includes only in files in which the actual header file code is used.
  • Avoid "just in case" includes.

Student Resources

Help/Question

  • N/A

Releases and Due Dates

R0.1

To Do

checkout your repository using userids and passwords received through your learn.senecac.on.ca email
Note that the trunk holds several files that are the base of your project.
Then in the Checked out directory:

  1. Create a directory in branches. Name of this directory must be your seneca email id (NOT YOUR WHOLE EMAIL ADDRESS, ONLY THE ID) (done in lab)
    From now on, this directory will be called Your Workspace
  2. In your workspace create a direcotry called console and add the files you submitted for your console assignment to it. (done in lab)
  3. using svn command, add, add all the newly created directories and their files to svn (done in lab)
  4. commit the repository with the message (comment) "Initial branch creation" (done in lab)
  5. After doing this with all your team members present (Online or face to face), Browse your Console code as a group and choose the best version from them and manually copy and add it to trunk
    Any of the group members can do this, but it would be nice if you do this when everyone is present (only one copy of console.cpp and console.h should get copied in trunk)
  6. If further changes to console.cpp or console.h are needed, apply them too
  7. Compile your code with Test1Frame.cpp and make sure it works properly
  8. After fixing possible bugs recompile and make sure everything is ok and runs properly
  9. tag the trunk under R0.1 in tags directory

Due Date

Fri Feb 17, 11:59

Exercise

To prepare and learn how to contribute and also gain mark for your next release do the following exercise.

Tester

this tester is already in your trunk:
Test1Frame.cpp

CField

Note: The code for this class is provided. You must understand and use it to develop your core classes.

CField is an abstract base class that encapsulates the commonalities of all Input Outputs Console Fields which are placeable on a CDialog. All Fields could be Framed, therefore a CField is inherited from CFrame.

#include "cframe.h"
class CDialog;
class CField : public CFrame{
protected:
  void* _data;
public:
  CField(int Row = 0, int Col = 0,
         int Width = 0, int Height =0,
         void* Data = (void*) 0,
         bool Bordered = false,
         const char* Border=C_BORDER_CHARS);
  ~CField();
  virtual int edit() = 0;
  virtual bool editable() const = 0;
 
 
  virtual void set(const void* data) = 0;
  virtual void* data();
 
  void container(CDialog* theContainer);
  CDialog* container();
};

Attributes

  void* _data;

Will hold the address of any type of data a CField can hold.

Constructors and Methods

  CField(int Row = 0, int Col = 0,
         int Width = 0, int Height =0,
         void* Data = (void*) 0,
         bool Bordered = false,
         const char* Border=C_BORDER_CHARS);

Passes the corresponding attributes to it's parents constructor and then sets the _data attribute to the incoming Data argument.

  ~CField();

Empty Destructor

  virtual int edit() = 0;
  virtual bool editable() const = 0;
  virtual void set(const void* data) = 0;

Enforce the children to implement;

  • an edit() method
  • an editable() method that returns true if the class is to edit data and false if the class is to only display data.
  • a set() method to set the _data attribute to the data the class is to work with.
  virtual void* data();

Returns _data.

  void container(CDialog* theContainer);
  CDialog* container();

Sets and Gets the _frame attribute of CFrame by calling CFrame::frame() method. Make sure to cast The CDialog to CFrame when setting and cast CFrame to CDialog when getting!

CLabel

A readonly Field that encapsulates console.display() function. (i.e it is responsible to display a short character string on the display) CLable although, by inheritance is Frame, but it is never bordered.

#include "cfield.h"
class CLabel :  public CField{
   // int _length;     Use void CFrame::width(int) to store length, and int CFrame::width() to retrieve the length

 public:
   CLabel(const CLabel& L);
   CLabel(const char *Str, int Row, int Col,
     int Len = 0);
   CLabel(int Row, int Col, int Len);
   ~CLabel();
   void draw(int fn=C_NO_FRAME) ;
   int edit();
   bool editable()const;
   void set(const void* str);
};

Attributes

No attributes, (use Cframe attributes)

Constructors / Destructor

   CLabel(const char *Str, int Row, int Col,
     int Len = 0);

passes the Row and Col to the CField constructor and then; if len is zero, it will allocate enough memory to store the string pointed by Str and then copies the Str into it. if len > 0, then it will allocate enough memory to store len chars in a string. In any way, the allocated memory is pointed by _data

   CLabel(int Row, int Col, int Len);

Works exactly like the previous constructor, but len in this case can not be zero. (no validation required) and the string pointed by _data will be set to an empty string.

   CLabel(const CLabel& L);

Copies a CLabel safely to guaranty there is no memory leak.

   ~CLabel();

makes sure that memory pointed by _data is deallocated before the object is destroyed.

Methods

   void draw(int fn=C_NO_FRAME) ;

makes a direct call to console.display(), passing _data for the string to be printed and absRow() and absCol() for row and col and _length for len. this function ignores the argument fn.

   int edit();

calls draw, returning 0.

   bool editable()const;

always return false.

   void set(const void* str);

if _length is greater than zero, it will copy the string pointed by str into the string pointed by _data upto _length characters. if _length is zero,
It will delete the memory pointed by _data and reallocates enough memory for str and copies the string pointed by str into the newly allocated memory pointed by _data.