diff options
author | George Hazan <ghazan@miranda.im> | 2017-02-14 18:08:41 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-02-14 18:08:41 +0300 |
commit | b8e0ee2bea6aac0a1bdf43575585ed78263bbe16 (patch) | |
tree | 281debed38d4e98275db6fa91cd8511a0dc0e08f /src/mir_core | |
parent | 43ab22c6b58eccb328b1c738e6d7aa8e171e9d3f (diff) |
handy little class for managing buffers moved to mir_core
Diffstat (limited to 'src/mir_core')
-rw-r--r-- | src/mir_core/src/binbuffer.cpp | 71 | ||||
-rw-r--r-- | src/mir_core/src/mir_core.def | 9 | ||||
-rw-r--r-- | src/mir_core/src/mir_core64.def | 9 |
3 files changed, 89 insertions, 0 deletions
diff --git a/src/mir_core/src/binbuffer.cpp b/src/mir_core/src/binbuffer.cpp new file mode 100644 index 0000000000..fe6326077a --- /dev/null +++ b/src/mir_core/src/binbuffer.cpp @@ -0,0 +1,71 @@ +/* +Copyright (C) 2012-17 Miranda NG team (http://miranda-ng.org) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation version 2 +of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "stdafx.h" + +MBinBuffer::MBinBuffer() : + m_buf(NULL), + m_len(0) +{ +} + +MBinBuffer::~MBinBuffer() +{ + mir_free(m_buf); +} + +void MBinBuffer::append(void *pBuf, size_t bufLen) +{ + if (pBuf == NULL || bufLen == 0) + return; + + m_buf = (char*)mir_realloc(m_buf, bufLen + m_len); + if (m_buf) { + memcpy(m_buf + m_len, pBuf, bufLen); + m_len += bufLen; + } + else m_len = 0; +} + +void MBinBuffer::appendBefore(void *pBuf, size_t bufLen) +{ + if (pBuf == NULL || bufLen == 0) + return; + + m_buf = (char*)mir_realloc(m_buf, bufLen + m_len); + if (m_buf) { + memmove(m_buf + bufLen, m_buf, m_len); + memcpy(m_buf, pBuf, bufLen); + m_len += bufLen; + } + else m_len = 0; +} + +void MBinBuffer::remove(size_t sz) +{ + if (sz > m_len) + m_len = sz; + + if (m_len == sz) { + m_len = 0; + mir_free(m_buf); m_buf = NULL; + } + else { + memmove(m_buf, m_buf + sz, m_len - sz); + m_len -= sz; + } +} diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index bb24cd6108..bbe3628c5d 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -1046,3 +1046,12 @@ CallFunctionSync @1170 ?GetNthPage@CCtrlPages@@QAEPAVCDlgBase@@H@Z @1203 NONAME
?GetItemPage@CCtrlPages@@AAEPAUTPageInfo@1@H@Z @1204 NONAME
?RemovePage@CCtrlPages@@QAEXH@Z @1205 NONAME
+??0MBinBuffer@@QAE@XZ @1206 NONAME
+??1MBinBuffer@@QAE@XZ @1207 NONAME
+??4MBinBuffer@@QAEAAV0@ABV0@@Z @1208 NONAME
+?append@MBinBuffer@@QAEXPAXI@Z @1209 NONAME
+?appendBefore@MBinBuffer@@QAEXPAXI@Z @1210 NONAME
+?data@MBinBuffer@@QBEPADXZ @1211 NONAME
+?isEmpty@MBinBuffer@@QBE_NXZ @1212 NONAME
+?length@MBinBuffer@@QBEIXZ @1213 NONAME
+?remove@MBinBuffer@@QAEXI@Z @1214 NONAME
diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index e8a9e2d9cb..7ce3f990e3 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -1046,3 +1046,12 @@ CallFunctionSync @1170 ?GetNthPage@CCtrlPages@@QEAAPEAVCDlgBase@@H@Z @1203 NONAME
?GetItemPage@CCtrlPages@@AEAAPEAUTPageInfo@1@H@Z @1204 NONAME
?RemovePage@CCtrlPages@@QEAAXH@Z @1205 NONAME
+??0MBinBuffer@@QEAA@XZ @1206 NONAME
+??1MBinBuffer@@QEAA@XZ @1207 NONAME
+??4MBinBuffer@@QEAAAEAV0@AEBV0@@Z @1208 NONAME
+?append@MBinBuffer@@QEAAXPEAX_K@Z @1209 NONAME
+?appendBefore@MBinBuffer@@QEAAXPEAX_K@Z @1210 NONAME
+?data@MBinBuffer@@QEBAPEADXZ @1211 NONAME
+?isEmpty@MBinBuffer@@QEBA_NXZ @1212 NONAME
+?length@MBinBuffer@@QEBA_KXZ @1213 NONAME
+?remove@MBinBuffer@@QEAAX_K@Z @1214 NONAME
|