|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| 11/03/2009 at 07:42AM PST, ID: 24867454 | Points: 500 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: |
//Motion.h
#ifndef MOTION_H
#define MOTION_H
#include <iostream>
#include <string>
using namespace std;
class Motion
{
friend ostream &operator << (ostream &out, const Motion &m);
private:
static bool instanceFlag;
static Motion *single;
public:
// return a C-style string representing the concrete motion
virtual char * toString() const = 0;
// return true if key is found within the motion actors
virtual bool contains(const char * key) const = 0;
static Motion* getInstance();
inline virtual ~Motion()
{
instanceFlag = false;
}
};
#endif
//-----------------------------------------------------------
//Motion.cxx
#include <iostream>
#include <sstream>
#include <string>
#include "Motion.h"
ostream &operator << (ostream &out, const Motion &m)
{
out << "- I " << m.toString();
return out;
}
bool Motion::instanceFlag = false;
Motion* Motion::single = NULL;
Motion* Motion::getInstance()
{
if(! instanceFlag)
{
single = new Motion();
instanceFlag = true;
return single;
}
else
{
return single;
}
}
//-----------------------------------------------------------
//FlyMotion.h
#ifndef FLYMOTION_H
#define FLYMOTION_H
#include <iostream>
#include <string>
#include <set>
using namespace std;
#include "Motion.h"
class FlyMotion : public Motion
{
public:
static FlyMotion* instance();
virtual char * toString() const;
virtual bool contains(const char * key) const;
//~FlyMotion(){};
private:
static FlyMotion *inst;
set <string> actors;
set<char>::iterator act;
FlyMotion();
//FlyMotion(const FlyMotion&);
};
#endif
//-----------------------------------------------------------
//FlyMotion.cxx
#include <iostream>
#include <sstream>
#include <string>
#include "FlyMotion.h"
using namespace std;
FlyMotion* FlyMotion::inst = 0;
FlyMotion::FlyMotion()
{
inst = 0;
actors.insert("pigeon");
actors.insert("plane");
actors.insert("time");
actors.insert("goose");
}
FlyMotion* FlyMotion::instance()
{
if(inst == 0)
{
inst = new FlyMotion;
}
return inst;
}
char* FlyMotion::toString() const
{
ostringstream outStr;
outStr << Motion::toString() << "fly " << flush;
return outStr.str();
}
bool FlyMotion::contains(const char *key) const
{
act=actors.find(key);
return act!=actors.end();
}
//-----------------------------------------------------------
//mainDRV.cxx
#include <iostream>
#include <set>
#include "Motion.h"
#include "FlyMotion.h"
#include "RunMotion.h"
#include "SwimMotion.h"
#include "CrawlMotion.h"
#include "WalkMotion.h"
#include "RollMotion.h"
//const int size = 6;
int main()
{
FlyMotion *test1;
test1 = FlyMotion::getInstance();
if(test1->contains("pigeon"))
{
cout << "Test" << endl;
}
cout << "Press Enter to continue..." << flush;
cin.get();
return 0;
}
//-----------------------------------------------------------
|
Advertisement