用c++实现了一个最简单的Singleton模式,后来没用上,先记录下来:
folder.h
#pragma once
#include <string>
using namespace std;
struct Parameter{
string Hand;
string ROI;
CPoint pointOfImage[2];
string mode;
double Bspeed;
double stepSize;
double pauseTime;
};
class FolderStructure {
public:
struct Parameter scanPara;
static FolderStructure *getInstance();
string getPath(int n);
private:
FolderStructure(void){}
static FolderStructure *folder;
};
folder.cpp
#include "folder.h"
FolderStructure * FolderStructure::folder=NULL;//static variable must have definition
FolderStructure *FolderStructure::getInstance(){
if(folder==0) {
folder=new FolderStructure();
}
return folder;
}
string FolderStructure::getPath(int n){
string path=father;
switch(n){
case 0:
break;
case 1:
path+="\\";
path+=patientName;
break;
case 2:
path+="\\";
path+=patientName;
path+="\\";
path+=date;
break;
case 3:
path+="\\";
path+=patientName;
path+="\\";
path+=date;
path+="\\";
path+=scanPara.Hand;
break;
case 4:
path+="\\";
path+=patientName;
path+="\\";
path+=date;
path+="\\";
path+=scanPara.Hand;
path+="\\";
path+=scanPara.ROI;
break;
case 5:
path+="\\";
path+=patientName;
path+="\\";
path+=date;
path+="\\";
path+=scanPara.Hand;
path+="\\";
path+=scanPara.ROI;
path+="\\";
path+=scanPara.mode;
break;
default:
break;
}
return path;
}