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
|
int PPCheckTwoDate(string sdt,string edt)
{
char sdtc[11],edtc[11];
strcpy(sdtc,sdt.c_str());
strcpy(edtc,edt.c_str());
int sdd,smm,syy,edd,emm,eyy;
sscanf(sdtc,"%d/%d/%d",&sdd,&smm,&syy);
sscanf(edtc,"%d/%d/%d",&edd,&emm,&eyy);
if(eyy > syy) // CHECK YEARS
return -1;
else if (eyy == syy)
{
if(emm > smm) return -1;
else if (emm == smm)
if(edd > sdd) return -1;
else if(edd == sdd) return 0;
else return 1;
else return 1;
}
else return 1;
}
class StringListCompare
{
public:
explicit StringListCompare(int column, int column2, string fCol, string sCol) : m_column(column), m_column2(column2) , fColType(fCol), sColType(sCol) {}
bool operator()(const vector<string>& lhs, const vector<string>& rhs)
{
if (lhs[m_column] == rhs[m_column])
{
if (sColType.compare("string")==0)
return lhs[m_column2] < rhs[m_column2];
else if (sColType.compare("number")==0)
return atoi(lhs[m_column2].c_str()) < atoi(rhs[m_column2].c_str());
else if (sColType.compare("date")==0)
return PPCheckTwoDate(lhs[m_column2], rhs[m_column2])<0;
}
else
{
if (fColType.compare("string")==0)
return lhs[m_column] < rhs[m_column];
else if (fColType.compare("number")==0)
return atoi(lhs[m_column].c_str()) < atoi(rhs[m_column].c_str());
else if (fColType.compare("date")==0)
return PPCheckTwoDate(lhs[m_column], rhs[m_column])<0;
}
}
private:
int m_column;
int m_column2;
string fColType;
string sColType;
};
|