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
|
/********************************************************************
created: 2008/07/02
created: 2:7:2008 22:20
filename: E:\Coding\CSDN_Exception\CSDN_Exception\CSDN_Exception.cpp
file path: E:\Coding\CSDN_Exception\CSDN_Exception
file base: CSDN_Exception
file ext: cpp
author: hecan
purpose:
*********************************************************************/
#include "CSDN_Exception.h"
using namespace std;
CMyException::CMyException(std::string & _sExpKind ,
int _iExpID,
std::string &_sExpEvent):
sExpKind(_sExpKind),
iExpID(_iExpID),
sExpEvent(_sExpEvent)
{
}
const string & CMyException::GetExpKind()const
{
return sExpKind;
}
const int & CMyException::GetExpID()const
{
return iExpID;
}
const string & CMyException::GetExpEven()const
{
return sExpEvent;
}
bool CMyException::operator ==(const CMyException &front)
{
return (front.GetExpKind() == sExpKind) &&
(front.GetExpID() == iExpID);
}
CMyException & CMyException::operator=(const CMyException &cmyExp_data)
{
sExpKind = cmyExp_data.GetExpKind();
iExpID = cmyExp_data.GetExpID();
sExpEvent = cmyExp_data.GetExpEven();
return *this;
}
CMyException::~CMyException()
{
}
std::ostream & operator <<(std::ostream & os, const CMyException &exp)
{
os << exp.GetExpKind() <<" " << exp.GetExpID() <<" " << exp.GetExpEven() <<endl;
return os;
}
//========================CExceptionTable==================================//
CExceptionTable::CExceptionTable(std::string & _sExpKind, int _iExpID)
:sExpKind_Query(_sExpKind), iExpID_Query(_iExpID)
{
InitData();
}
void CExceptionTable::InitData()
{
ifstream ifsExpTbl("ExceptionTable.txt", ios::in);
if (!ifsExpTbl)
{
cerr << "Can't Open File !" << endl;
}
string sLine;
while (getline(ifsExpTbl, sLine))
{
istringstream issLine(sLine);
string sExpKind_Tmp ;
int iExpID_Tmp;
string sExpEvent_Tmp;
issLine >> sExpKind_Tmp >> iExpID_Tmp >> sExpEvent_Tmp;
// cout << sExpKind_Tmp <<" " << iExpID_Tmp <<" " << sExpEvent_Tmp <<endl;
CMyException cexp_Tmp(sExpKind_Tmp, iExpID_Tmp, sExpEvent_Tmp);
vce_ExceptionTbl.push_back(cexp_Tmp);
}
copy(vce_ExceptionTbl.begin(), vce_ExceptionTbl.end(), ostream_iterator<CMyException>(cout));
}
const string CExceptionTable::What()
{
CMyException cmy_Query(sExpKind_Query, iExpID_Query);
vector< CMyException >::iterator vci_Iter = find(vce_ExceptionTbl.begin(), vce_ExceptionTbl.end(), cmy_Query);
if (vci_Iter == vce_ExceptionTbl.end())
{
return string("Error");
}
// cout << vci_Iter->GetExpEven();
return vci_Iter->GetExpEven();
// return string("error");
//string yy("yy");
//return yy;
}
void CExceptionTable::Output()
{
copy(vce_ExceptionTbl.begin(), vce_ExceptionTbl.end(), ostream_iterator<CMyException>(cout));
}
|