From c0c563de5513cfe3ef53d6c10de633daf6168c48 Mon Sep 17 00:00:00 2001 From: psychon Date: Sat, 23 Aug 2008 13:24:28 +0000 Subject: [PATCH] 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 --- Utils.cpp | 18 ++++++++++++++---- Utils.h | 4 +++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Utils.cpp b/Utils.cpp index 903f6ff5..f6429643 100644 --- a/Utils.cpp +++ b/Utils.cpp @@ -410,7 +410,8 @@ bool CTable::AddColumn(const CString& sName) { } unsigned int CTable::AddRow() { - push_back(map()); + // Add a vector with enough space for each column + push_back(vector(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& mRow = (*this)[uIdx]; + const vector& 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; diff --git a/Utils.h b/Utils.h index fb087c4d..8b0c4d37 100644 --- a/Utils.h +++ b/Utils.h @@ -198,7 +198,7 @@ protected: }; -class CTable : public vector > { +class CTable : public vector > { 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 m_vsHeaders; map m_msuWidths; // Used to cache the width of a column