21
edits
Changes
→IO_Label
===IO_Label===
'''IO_Label''' class mostly, encapsulates the '''[[OOP344_Assignment_One#void_io_display.28const_char_.2Astr.2C_int_row.2C_int_col.2C_int_len.29|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;
<big><pre>
IO_Label(int row, int col, int len);
</pre></big>
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!''<br />
<big><pre>
IO_Label(char* str, int row, int col, int len = -1);
</pre></big>
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====
<big><pre>
void Display(void);
</pre></big>
'''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.
<big><pre>
void Set(const void* str);
</pre></big>
'''Set()''' will copy the content of '''str''' into '''IO_Field::_data''' up to '''_len''' characters, if '''_len''' is not negative.
<big><pre>
bool IO_Label::Editable(void)const;
</pre></big>
'''Editable()''' returns false!.
<big><pre>
int Edit(IO_Form* Owner=(IO_Form*)0);
</pre></big>
'''Edit()''', Calls '''Display()''' and returns '''0'''. This method ignores the '''Owner''', IO_Form pointer.
<big><pre>
~IO_Label(void);
</pre></big>
The destructor, delete[]s the '''_data'''. (make sure '''_data''' is casted to char* before deleting.
<big><pre>
IO_Label &operator=(const char* str);
</pre></big>
'''operator=()''', Calls '''Set()''' and returns itself.