00001 /* Copyright (C) 2003 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 #include "LogHandlerList.hpp" 00018 00019 #include <LogHandler.hpp> 00020 00021 // 00022 // PUBLIC 00023 // 00024 00025 LogHandlerList::LogHandlerList() : 00026 m_size(0), 00027 m_pHeadNode(NULL), 00028 m_pTailNode(NULL), 00029 m_pCurrNode(NULL) 00030 { 00031 } 00032 00033 LogHandlerList::~LogHandlerList() 00034 { 00035 removeAll(); 00036 } 00037 00038 void 00039 LogHandlerList::add(LogHandler* pNewHandler) 00040 { 00041 LogHandlerNode* pNode = new LogHandlerNode(); 00042 00043 if (m_pHeadNode == NULL) 00044 { 00045 m_pHeadNode = pNode; 00046 pNode->pPrev = NULL; 00047 } 00048 else 00049 { 00050 m_pTailNode->pNext = pNode; 00051 pNode->pPrev = m_pTailNode; 00052 } 00053 m_pTailNode = pNode; 00054 pNode->pNext = NULL; 00055 pNode->pHandler = pNewHandler; 00056 00057 m_size++; 00058 } 00059 00060 bool 00061 LogHandlerList::remove(LogHandler* pRemoveHandler) 00062 { 00063 LogHandlerNode* pNode = m_pHeadNode; 00064 bool removed = false; 00065 do 00066 { 00067 if (pNode->pHandler == pRemoveHandler) 00068 { 00069 removeNode(pNode); 00070 removed = true; 00071 break; 00072 } 00073 } while ( (pNode = next(pNode)) != NULL); 00074 00075 return removed; 00076 } 00077 00078 void 00079 LogHandlerList::removeAll() 00080 { 00081 while (m_pHeadNode != NULL) 00082 { 00083 removeNode(m_pHeadNode); 00084 } 00085 } 00086 00087 LogHandler* 00088 LogHandlerList::next() 00089 { 00090 LogHandler* pHandler = NULL; 00091 if (m_pCurrNode == NULL) 00092 { 00093 m_pCurrNode = m_pHeadNode; 00094 if (m_pCurrNode != NULL) 00095 { 00096 pHandler = m_pCurrNode->pHandler; 00097 } 00098 } 00099 else 00100 { 00101 m_pCurrNode = next(m_pCurrNode); // Next node 00102 if (m_pCurrNode != NULL) 00103 { 00104 pHandler = m_pCurrNode->pHandler; 00105 } 00106 } 00107 00108 return pHandler; 00109 } 00110 00111 int 00112 LogHandlerList::size() const 00113 { 00114 return m_size; 00115 } 00116 00117 // 00118 // PRIVATE 00119 // 00120 00121 LogHandlerList::LogHandlerNode* 00122 LogHandlerList::next(LogHandlerNode* pNode) 00123 { 00124 LogHandlerNode* pCurr = pNode; 00125 if (pNode->pNext != NULL) 00126 { 00127 pCurr = pNode->pNext; 00128 } 00129 else 00130 { 00131 // Tail 00132 pCurr = NULL; 00133 } 00134 return pCurr; 00135 } 00136 00137 LogHandlerList::LogHandlerNode* 00138 LogHandlerList::prev(LogHandlerNode* pNode) 00139 { 00140 LogHandlerNode* pCurr = pNode; 00141 if (pNode->pPrev != NULL) // head 00142 { 00143 pCurr = pNode->pPrev; 00144 } 00145 else 00146 { 00147 // Head 00148 pCurr = NULL; 00149 } 00150 00151 return pCurr; 00152 } 00153 00154 void 00155 LogHandlerList::removeNode(LogHandlerNode* pNode) 00156 { 00157 if (pNode->pPrev == NULL) // If head 00158 { 00159 m_pHeadNode = pNode->pNext; 00160 } 00161 else 00162 { 00163 pNode->pPrev->pNext = pNode->pNext; 00164 } 00165 00166 if (pNode->pNext == NULL) // if tail 00167 { 00168 m_pTailNode = pNode->pPrev; 00169 } 00170 else 00171 { 00172 pNode->pNext->pPrev = pNode->pPrev; 00173 } 00174 00175 pNode->pNext = NULL; 00176 pNode->pPrev = NULL; 00177 delete pNode->pHandler; // Delete log handler 00178 delete pNode; 00179 00180 m_size--; 00181 }
1.4.7

