Changes

Jump to: navigation, search

OOP344 Assignment Two

33 bytes removed, 09:27, 2 November 2009
IO_Label
<hr width="50%" />
<hr width="50%" />
 
 
===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 could hold holds its data dynamically or simply and will never 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;
<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'''.
''Note that '''data''' is a void pointer; to use it here, you must cast it to a character pointer!''<br />
'''_dynamic''' attribute is set to true in this case.<big><pre>
<big><pre>
IO_Label(char* str, int row, int col, int len = -1);
 
</pre></big>
This constructor will create an IO_Label, with its IO_Field::_data pointing to where '''str''' is pointing to.
Like the previous If '''len''' is greater than zero, This constructor it will pass create an IO_Label by allocating len + 1 characters pointed by IO_Field::_data, and then the contents of '''rowstr''' and is copied into IO_Fiedl::_data up to '''collen''' to its parent and set the characters. '''_len''' attribute is set to the incoming '''len''' argument. ; If '''_dynamiclen''' attribute is less than or equal to zero, then '''len''' will be set to false in this case, since the data length of '''str''' and then constructor will work as previous case. Like the class is externalprevious constructor it will pass '''row''' and '''col''' to its parent.
====Public Methods====
 
<big><pre>
 
void Display(void);
 
</pre></big>
<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>
<big><pre>
 
~IO_Label(void);
 
</pre></big>
The destructor, delete[]s the '''_data''' only if . (make sure '''_dynamic_data''' is truecasted to char* before deleting.
<big><pre>
 
IO_Label &operator=(const char* str);
 
</pre></big>

Navigation menu