![](/media/cache/profiles/94aef38441efa3380a3bed3faf1f9d5d.50x50_q85.jpg)
Dependencies: EthernetNetIf NTPClient_NetServices mbed
ItemSet.cpp@0:d441275f622f, 2010-08-09 (annotated)
- Committer:
- nucho
- Date:
- Mon Aug 09 07:01:43 2010 +0000
- Revision:
- 0:d441275f622f
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nucho | 0:d441275f622f | 1 | #include "ItemSet.h" |
nucho | 0:d441275f622f | 2 | #include "mbed.h" |
nucho | 0:d441275f622f | 3 | using namespace mbed; |
nucho | 0:d441275f622f | 4 | |
nucho | 0:d441275f622f | 5 | ItemSet::ItemSet() { |
nucho | 0:d441275f622f | 6 | firstItem = currentItem = NULL; |
nucho | 0:d441275f622f | 7 | numOfItems = 0; |
nucho | 0:d441275f622f | 8 | } |
nucho | 0:d441275f622f | 9 | |
nucho | 0:d441275f622f | 10 | Object* ItemSet::First() { |
nucho | 0:d441275f622f | 11 | currentItem = firstItem; |
nucho | 0:d441275f622f | 12 | if (currentItem == NULL) return(NULL); |
nucho | 0:d441275f622f | 13 | |
nucho | 0:d441275f622f | 14 | return(currentItem->object); |
nucho | 0:d441275f622f | 15 | } |
nucho | 0:d441275f622f | 16 | |
nucho | 0:d441275f622f | 17 | Object* ItemSet::Next() { |
nucho | 0:d441275f622f | 18 | if (currentItem != NULL) { |
nucho | 0:d441275f622f | 19 | if (currentItem->nextItem != NULL) { |
nucho | 0:d441275f622f | 20 | currentItem = currentItem->nextItem; |
nucho | 0:d441275f622f | 21 | }else{ |
nucho | 0:d441275f622f | 22 | return NULL; |
nucho | 0:d441275f622f | 23 | } |
nucho | 0:d441275f622f | 24 | return(currentItem->object); |
nucho | 0:d441275f622f | 25 | } else { |
nucho | 0:d441275f622f | 26 | return(NULL); |
nucho | 0:d441275f622f | 27 | } |
nucho | 0:d441275f622f | 28 | } |
nucho | 0:d441275f622f | 29 | |
nucho | 0:d441275f622f | 30 | void ItemSet::AddItem(Object* inObj) { |
nucho | 0:d441275f622f | 31 | Item* theItem; |
nucho | 0:d441275f622f | 32 | theItem = new Item; |
nucho | 0:d441275f622f | 33 | theItem->object = inObj; |
nucho | 0:d441275f622f | 34 | |
nucho | 0:d441275f622f | 35 | if (numOfItems == 0) { |
nucho | 0:d441275f622f | 36 | theItem->nextItem =NULL; |
nucho | 0:d441275f622f | 37 | firstItem = theItem; |
nucho | 0:d441275f622f | 38 | } else { |
nucho | 0:d441275f622f | 39 | theItem->nextItem = firstItem; |
nucho | 0:d441275f622f | 40 | firstItem =theItem; |
nucho | 0:d441275f622f | 41 | } |
nucho | 0:d441275f622f | 42 | |
nucho | 0:d441275f622f | 43 | currentItem = theItem; |
nucho | 0:d441275f622f | 44 | numOfItems++; |
nucho | 0:d441275f622f | 45 | |
nucho | 0:d441275f622f | 46 | return; |
nucho | 0:d441275f622f | 47 | } |
nucho | 0:d441275f622f | 48 | |
nucho | 0:d441275f622f | 49 | int ItemSet::GetNumOfItems() { |
nucho | 0:d441275f622f | 50 | return(numOfItems); |
nucho | 0:d441275f622f | 51 | } |
nucho | 0:d441275f622f | 52 | |
nucho | 0:d441275f622f | 53 | Object* ItemSet::GetCurrentObject() { |
nucho | 0:d441275f622f | 54 | |
nucho | 0:d441275f622f | 55 | if (currentItem != NULL) { |
nucho | 0:d441275f622f | 56 | return(currentItem->object); |
nucho | 0:d441275f622f | 57 | } else { |
nucho | 0:d441275f622f | 58 | return(NULL); |
nucho | 0:d441275f622f | 59 | } |
nucho | 0:d441275f622f | 60 | } |
nucho | 0:d441275f622f | 61 | |
nucho | 0:d441275f622f | 62 | |
nucho | 0:d441275f622f | 63 | Object* ItemSet::SerchId(unsigned int inId) { |
nucho | 0:d441275f622f | 64 | Item* item=firstItem; |
nucho | 0:d441275f622f | 65 | |
nucho | 0:d441275f622f | 66 | while (item != NULL) { |
nucho | 0:d441275f622f | 67 | if (item->object->CompareId(inId)) { |
nucho | 0:d441275f622f | 68 | return(item->object); |
nucho | 0:d441275f622f | 69 | } |
nucho | 0:d441275f622f | 70 | item = item->nextItem; |
nucho | 0:d441275f622f | 71 | } |
nucho | 0:d441275f622f | 72 | |
nucho | 0:d441275f622f | 73 | return NULL; |
nucho | 0:d441275f622f | 74 | } |