69 lines
1014 B
C
69 lines
1014 B
C
|
#ifndef _ITERATOR_H_
|
|||
|
#define _ITERATOR_H_
|
|||
|
|
|||
|
#pragma once
|
|||
|
#include "Aggregate.h"
|
|||
|
|
|||
|
#include <vector>
|
|||
|
using namespace std;
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
class Iterator
|
|||
|
{
|
|||
|
public:
|
|||
|
Iterator(){}
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
virtual void first() = 0;
|
|||
|
virtual void last() = 0;
|
|||
|
virtual void next() = 0;
|
|||
|
virtual void previous() = 0;
|
|||
|
virtual bool hasNext() = 0;
|
|||
|
virtual bool hasPrevious() = 0;
|
|||
|
virtual void currentChannel() = 0;
|
|||
|
private:
|
|||
|
|
|||
|
};
|
|||
|
|
|||
|
// ң<><D2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
class RemoteControl :public Iterator
|
|||
|
{
|
|||
|
public:
|
|||
|
RemoteControl(){}
|
|||
|
void setTV(Television *iTv){
|
|||
|
this->tv = iTv;
|
|||
|
cursor = -1;
|
|||
|
totalNum = tv->getTotalChannelNum();
|
|||
|
}
|
|||
|
// ʵ<>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
void first(){
|
|||
|
cursor = 0;
|
|||
|
}
|
|||
|
void last(){
|
|||
|
cursor = totalNum - 1;
|
|||
|
}
|
|||
|
void next(){
|
|||
|
cursor++;
|
|||
|
}
|
|||
|
void previous(){
|
|||
|
cursor--;
|
|||
|
}
|
|||
|
bool hasNext(){
|
|||
|
return !(cursor == totalNum);
|
|||
|
}
|
|||
|
bool hasPrevious(){
|
|||
|
return !(cursor == -1);
|
|||
|
}
|
|||
|
void currentChannel(){
|
|||
|
tv->play(cursor);
|
|||
|
}
|
|||
|
private:
|
|||
|
// <20>α<EFBFBD>
|
|||
|
int cursor;
|
|||
|
// <20>ܵ<EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>Ŀ
|
|||
|
int totalNum;
|
|||
|
// <20><><EFBFBD><EFBFBD>
|
|||
|
Television* tv;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
#endif
|