| 1 | #include "IdentifierList.h" |
|---|
| 2 | #include "Identifier.h" |
|---|
| 3 | |
|---|
| 4 | namespace orxonox |
|---|
| 5 | { |
|---|
| 6 | // ############################### |
|---|
| 7 | // ### IdentifierList ### |
|---|
| 8 | // ############################### |
|---|
| 9 | IdentifierList::IdentifierList() |
|---|
| 10 | { |
|---|
| 11 | this->first_ = 0; |
|---|
| 12 | } |
|---|
| 13 | |
|---|
| 14 | IdentifierList::~IdentifierList() |
|---|
| 15 | { |
|---|
| 16 | IdentifierListElement* temp; |
|---|
| 17 | while (this->first_) |
|---|
| 18 | { |
|---|
| 19 | temp = this->first_->next_; |
|---|
| 20 | delete this->first_; |
|---|
| 21 | this->first_ = temp; |
|---|
| 22 | } |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | void IdentifierList::add(Identifier* identifier) |
|---|
| 26 | { |
|---|
| 27 | IdentifierListElement* temp = this->first_; |
|---|
| 28 | this->first_ = new IdentifierListElement(identifier); |
|---|
| 29 | this->first_->next_ = temp; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | void IdentifierList::remove(Identifier* identifier) |
|---|
| 33 | { |
|---|
| 34 | if (!identifier) |
|---|
| 35 | return; |
|---|
| 36 | |
|---|
| 37 | if (this->first_->identifier_ == identifier) |
|---|
| 38 | { |
|---|
| 39 | IdentifierListElement* temp = this->first_->next_; |
|---|
| 40 | delete this->first_; |
|---|
| 41 | this->first_ = temp; |
|---|
| 42 | |
|---|
| 43 | return; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | IdentifierListElement* temp = this->first_; |
|---|
| 47 | while (temp->next_) |
|---|
| 48 | { |
|---|
| 49 | if (temp->next_->identifier_ == identifier) |
|---|
| 50 | { |
|---|
| 51 | IdentifierListElement* temp2 = temp->next_->next_; |
|---|
| 52 | delete temp->next_; |
|---|
| 53 | temp->next_ = temp2; |
|---|
| 54 | |
|---|
| 55 | return; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | temp = temp->next_; |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | bool IdentifierList::isInList(Identifier* identifier) |
|---|
| 63 | { |
|---|
| 64 | IdentifierListElement* temp = this->first_; |
|---|
| 65 | while (temp) |
|---|
| 66 | { |
|---|
| 67 | if (temp->identifier_ == identifier) |
|---|
| 68 | return true; |
|---|
| 69 | |
|---|
| 70 | temp = temp->next_; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | return false; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | std::string IdentifierList::toString() |
|---|
| 77 | { |
|---|
| 78 | IdentifierListElement* temp = this->first_; |
|---|
| 79 | std::string output = ""; |
|---|
| 80 | |
|---|
| 81 | while (temp) |
|---|
| 82 | { |
|---|
| 83 | output += temp->identifier_->getName(); |
|---|
| 84 | output += " "; |
|---|
| 85 | |
|---|
| 86 | temp = temp->next_; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | return output; |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | // ############################### |
|---|
| 94 | // ### IdentifierListElement ### |
|---|
| 95 | // ############################### |
|---|
| 96 | IdentifierListElement::IdentifierListElement(Identifier* identifier) |
|---|
| 97 | { |
|---|
| 98 | this->identifier_ = identifier; |
|---|
| 99 | this->next_ = 0; |
|---|
| 100 | this->bDirect_ = true; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | IdentifierListElement::~IdentifierListElement() |
|---|
| 104 | { |
|---|
| 105 | } |
|---|
| 106 | } |
|---|