Fix FTBFS with CTable on g++ 3

g++ 3 doesnt like map<>.at().

This changes how CTable stores its data internally.
This *might* be faster than the older system.

Thanks to kroimon for finding this.


git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1163 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
psychon
2008-08-23 13:24:28 +00:00
parent ecabbd2bcd
commit c0c563de55
2 changed files with 17 additions and 5 deletions
+14 -4
View File
@@ -410,7 +410,8 @@ bool CTable::AddColumn(const CString& sName) {
}
unsigned int CTable::AddRow() {
push_back(map<CString, CString>());
// Add a vector with enough space for each column
push_back(vector<CString>(m_vsHeaders.size()));
return size() -1;
}
@@ -423,7 +424,7 @@ bool CTable::SetCell(const CString& sColumn, const CString& sValue, unsigned int
uRowIdx = size() -1;
}
(*this)[uRowIdx][sColumn] = sValue;
(*this)[uRowIdx][GetColumnIndex(sColumn)] = sValue;
if (m_msuWidths[sColumn] < sValue.size())
m_msuWidths[sColumn] = sValue.size();
@@ -466,13 +467,13 @@ bool CTable::GetLine(unsigned int uIdx, CString& sLine) const {
uIdx -= 3;
if (uIdx < size()) {
const map<CString, CString>& mRow = (*this)[uIdx];
const vector<CString>& mRow = (*this)[uIdx];
ssRet.fill(' ');
ssRet << "| ";
for (unsigned int c = 0; c < m_vsHeaders.size(); c++) {
ssRet.width(GetColumnWidth(c));
ssRet << std::left << mRow.at(m_vsHeaders[c]);
ssRet << std::left << mRow[c];
ssRet << ((c == m_vsHeaders.size() -1) ? " |" : " | ");
}
@@ -511,6 +512,15 @@ bool CTable::Output(std::ostream oOut) {
}
*/
unsigned int CTable::GetColumnIndex(const CString& sName) const {
for (unsigned int i = 0; i < m_vsHeaders.size(); i++) {
if (m_vsHeaders[i] == sName)
return i;
}
return 0;
}
unsigned int CTable::GetColumnWidth(unsigned int uIdx) const {
if (uIdx >= m_vsHeaders.size()) {
return 0;
+3 -1
View File
@@ -198,7 +198,7 @@ protected:
};
class CTable : public vector<map<CString, CString> > {
class CTable : public vector<vector<CString> > {
public:
CTable() {}
virtual ~CTable() {}
@@ -210,6 +210,8 @@ public:
unsigned int GetColumnWidth(unsigned int uIdx) const;
private:
unsigned int GetColumnIndex(const CString& sName) const;
protected:
vector<CString> m_vsHeaders;
map<CString, unsigned int> m_msuWidths; // Used to cache the width of a column