Monday, November 23, 2009

io_checklist with comments

I added some comments to setItems() in io_checklist:

void IO_CheckList::setItems(const char *str){
int i;
unsigned int maxlen = 0;
int strLen= strlen((char*)str);
_itemstr = new char[strLen+1];
strcpy(_itemstr, (char*)str); // copy str into _itemstr
for(_len = 0,i=0;i if(_itemstr[i] == '\n'){
_len++; // number of items separated by '\n'
}
}
_items = new char*[_len+1]; //_items is pointer to an array of pointer
_status = new bool[_len+1];
for(i=0;i<_len+1;i++){
_status[i] = false;
}

/* Following lines of code:
_itemstr contains a string of items in the checklist, each one separated by '\n';
_items is made to point to the beginning of the string before the for loop;
Through the for loop, _itemstr is cycled through character by character.
Each time a '\n' is reached, _item is made to point to the character after the '\n'.
The '\n' is replaced with NULL and thus truncating the rest of the string so _item pointer in the array of pointers points to only 1 item in the checklist. */

_items[0] = _itemstr; // point to where _itemstr is pointing to
for(_len = 1,i=0;i if(_itemstr[i] == '\n'){
_items[_len]=&_itemstr[i+1]; // when '\n' is reached, _item points to first character after '\n'
_itemstr[i] = 0; // replace '\n' with NULL
if(strlen(_items[_len-1])> maxlen){
maxlen = strlen(_items[_len-1]); // keep track of the longest string copied
}
_len++; // keep track of number of items
}
}
if(strlen(_items[_len-1])> maxlen){
maxlen = strlen(_items[_len-1]);
}
IO_Frame::set(IO_Field::getRow(), IO_Field::getCol(), maxlen + 6, _len+2);
_titlelen = maxlen;
}

No comments:

Post a Comment