Skip to content

Commit

Permalink
Detach()
Browse files Browse the repository at this point in the history
  • Loading branch information
wildwoong@gmail.com committed Jan 21, 2011
1 parent 62c29bf commit e8c6e8e
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions Paper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Paper& Paper::operator=(const Paper& source)
this->linkedList = source.linkedList;
this->length = source.length;
this->current = 0;

return *this;
}

Expand All @@ -33,47 +34,50 @@ Label* Paper::Attach(Label label)
{
LinkedList<Label>::Node* node = this->linkedList.GetCurrent();

if(node == 0) {
if(node == 0)
{
node = this->linkedList.AppendFromHead(label);
} else {
}
else
{
node = this->linkedList.InsertAfter(node, label);
}
this->length++;

this->current = &(node->GetObject());
this->length++;

return this->current;
}

Label Paper::Detach()
{
LinkedList<Label>::Node* node = this->linkedList.LinearSearchUnique(this->current, CompareLabel);
Label label = node->GetObject();

LinkedList<Label>::Node* previous = this->linkedList.Previous();
Label label = *(this->current);

if(previous != node)
LinkedList<Label>::Node* node = this->linkedList.Delete();

if(node != 0)
{
this->current = &(previous->GetObject());
this->current = &(node->GetObject());
}
else
{
this->current = 0;
}

this->linkedList.Delete(node);
this->length--;


this->length--;

return label;
}

int CompareLabel(void* one, void* other)
{
int ret = -1;

if(one == other)
{
ret = 0;
}

return ret;
}

Expand Down

0 comments on commit e8c6e8e

Please sign in to comment.