用模板实现对不同元件进行编号。

Signed-off-by: facat@lab.com <facat@lab.com>
This commit is contained in:
facat@lab.com 2014-12-28 17:16:29 +08:00
parent cbe9e1f261
commit 7fa4d1d98b
2 changed files with 25 additions and 1 deletions

View File

@ -10,6 +10,7 @@ void CIMExporter::add(const QPair<QString,QString>& fromTo,Line* line)
lineStru.line=line;
lineStru.fromID=fromTo.first;
lineStru.toID=fromTo.second;
this->line.push_back(lineStru);
}
void CIMExporter::add(const QPair<QString,QString>& fromTo,Switch* sw)
@ -18,6 +19,7 @@ void CIMExporter::add(const QPair<QString,QString>& fromTo,Switch* sw)
switchStru.sw=sw;
switchStru.fromID=fromTo.first;
switchStru.toID=fromTo.second;
this->sw.push_back(switchStru);
}
void CIMExporter::add(const QPair<QString,QString>& fromTo,Transformer* tf)
{
@ -25,12 +27,32 @@ void CIMExporter::add(const QPair<QString,QString>& fromTo,Transformer* tf)
tfStru.tf=tf;
tfStru.fromID=fromTo.first;
tfStru.toID=fromTo.second;
this->tf.push_back(tfStru);
}
void CIMExporter::exportTo(const QString& path)
{
//先给所有节点都编号
this->idToNumber(this->line);
this->idToNumber(this->sw);
this->idToNumber(this->tf);
}
template<typename T>
void CIMExporter::idToNumber(QList<T> &s)//把所有元件的标识进行编号
{
for(typename QList<T>::iterator ite=s.begin();
ite!=s.end();
ite++
)
{
T _t=*ite;
_t.fromNum=this->numberIt(_t.fromID);
_t.toNum=this->numberIt(_t.toID);
*ite=_t;
}
}
int CIMExporter::numberIt(const QString& id)

View File

@ -38,10 +38,12 @@ public:
void exportTo(const QString& path);
private:
QList<LineStru> line;
QList<Switch> sw;
QList<SwitchStru> sw;
QList<TransformerStru> tf;
QHash<QString,int> number;
int numberIt(const QString &id);//编号
template<typename T>
void idToNumber(QList<T> &s);//把所有元件的标识进行编号
};
#endif // CIMEXPORTER_H