cimforreduceloss/testHasttable/cimexporter.cpp

72 lines
1.5 KiB
C++

#include "cimexporter.h"
CIMExporter::CIMExporter()
{
}
void CIMExporter::add(const QPair<QString,QString>& fromTo,Line* line)
{
CIMExporter::LineStru lineStru;
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)
{
CIMExporter::SwitchStru switchStru;
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)
{
CIMExporter::TransformerStru tfStru;
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)
{
if(this->number.contains(id))
{
return this->number.value(id);
}
else
{
int n=this->number.values().length()+1;
this->number[id]=n;
return n;
}
}