Added a debugger call in case the reallocation fails.
We can't handle an allocation failure there (at least for now). Took the chance to stylize the code. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9782 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Copyright (c) 2001-2003, OpenBeOS
|
// Copyright (c) 2001-2004, Haiku, Inc.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
// copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -20,7 +20,8 @@
|
|||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
// File Name: TextViewSupportBuffer.h
|
// File Name: TextViewSupportBuffer.h
|
||||||
// Author: Marc Flerackers ([email protected])
|
// Authors Marc Flerackers ([email protected])
|
||||||
|
// Stefano Ceccherini ([email protected])
|
||||||
// Description: Template class used to implement the various BTextView
|
// Description: Template class used to implement the various BTextView
|
||||||
// buffer classes.
|
// buffer classes.
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -28,20 +29,12 @@
|
|||||||
#ifndef __TEXT_VIEW_SUPPORT_BUFFER__H__
|
#ifndef __TEXT_VIEW_SUPPORT_BUFFER__H__
|
||||||
#define __TEXT_VIEW_SUPPORT_BUFFER__H__
|
#define __TEXT_VIEW_SUPPORT_BUFFER__H__
|
||||||
|
|
||||||
// Standard Includes -----------------------------------------------------------
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
// System Includes -------------------------------------------------------------
|
#include <OS.h>
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
// Project Includes ------------------------------------------------------------
|
|
||||||
|
|
||||||
// Local Includes --------------------------------------------------------------
|
|
||||||
|
|
||||||
// Local Defines ---------------------------------------------------------------
|
|
||||||
|
|
||||||
// Globals ---------------------------------------------------------------------
|
|
||||||
|
|
||||||
// _BTextViewSupportBuffer_ class ----------------------------------------------
|
// _BTextViewSupportBuffer_ class ----------------------------------------------
|
||||||
template <class T>
|
template <class T>
|
||||||
@@ -62,7 +55,8 @@ protected:
|
|||||||
int32 fBufferCount;
|
int32 fBufferCount;
|
||||||
T* fBuffer;
|
T* fBuffer;
|
||||||
};
|
};
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
_BTextViewSupportBuffer_<T>::_BTextViewSupportBuffer_(int32 inExtraCount,
|
_BTextViewSupportBuffer_<T>::_BTextViewSupportBuffer_(int32 inExtraCount,
|
||||||
int32 inCount)
|
int32 inCount)
|
||||||
@@ -73,15 +67,18 @@ _BTextViewSupportBuffer_<T>::_BTextViewSupportBuffer_(int32 inExtraCount,
|
|||||||
{
|
{
|
||||||
fBuffer = (T *)calloc(fExtraCount + fItemCount, sizeof(T));
|
fBuffer = (T *)calloc(fExtraCount + fItemCount, sizeof(T));
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
_BTextViewSupportBuffer_<T>::~_BTextViewSupportBuffer_()
|
_BTextViewSupportBuffer_<T>::~_BTextViewSupportBuffer_()
|
||||||
{
|
{
|
||||||
free(fBuffer);
|
free(fBuffer);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void _BTextViewSupportBuffer_<T>::InsertItemsAt(int32 inNumItems,
|
void
|
||||||
|
_BTextViewSupportBuffer_<T>::InsertItemsAt(int32 inNumItems,
|
||||||
int32 inAtIndex,
|
int32 inAtIndex,
|
||||||
const T *inItem)
|
const T *inItem)
|
||||||
{
|
{
|
||||||
@@ -96,6 +93,8 @@ void _BTextViewSupportBuffer_<T>::InsertItemsAt(int32 inNumItems,
|
|||||||
if ((logSize + delta) >= fBufferCount) {
|
if ((logSize + delta) >= fBufferCount) {
|
||||||
fBufferCount = logSize + delta + (fExtraCount * sizeof(T));
|
fBufferCount = logSize + delta + (fExtraCount * sizeof(T));
|
||||||
fBuffer = (T *)realloc(fBuffer, fBufferCount);
|
fBuffer = (T *)realloc(fBuffer, fBufferCount);
|
||||||
|
if (fBuffer == NULL)
|
||||||
|
debugger("InsertItemsAt(): reallocation failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
T *loc = fBuffer + inAtIndex;
|
T *loc = fBuffer + inAtIndex;
|
||||||
@@ -104,7 +103,8 @@ void _BTextViewSupportBuffer_<T>::InsertItemsAt(int32 inNumItems,
|
|||||||
|
|
||||||
fItemCount += inNumItems;
|
fItemCount += inNumItems;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
_BTextViewSupportBuffer_<T>::RemoveItemsAt(int32 inNumItems,
|
_BTextViewSupportBuffer_<T>::RemoveItemsAt(int32 inNumItems,
|
||||||
@@ -126,24 +126,20 @@ _BTextViewSupportBuffer_<T>::RemoveItemsAt(int32 inNumItems,
|
|||||||
if (extraSize > (fExtraCount * sizeof(T))) {
|
if (extraSize > (fExtraCount * sizeof(T))) {
|
||||||
fBufferCount = (logSize - delta) + (fExtraCount * sizeof(T));
|
fBufferCount = (logSize - delta) + (fExtraCount * sizeof(T));
|
||||||
fBuffer = (T *)realloc(fBuffer, fBufferCount);
|
fBuffer = (T *)realloc(fBuffer, fBufferCount);
|
||||||
|
if (fBuffer == NULL)
|
||||||
|
debugger("RemoveItemsAt(): reallocation failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
fItemCount -= inNumItems;
|
fItemCount -= inNumItems;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline int32
|
inline int32
|
||||||
_BTextViewSupportBuffer_<T>::ItemCount() const
|
_BTextViewSupportBuffer_<T>::ItemCount() const
|
||||||
{
|
{
|
||||||
return fItemCount;
|
return fItemCount;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#endif // __TEXT_VIEW_SUPPORT_BUFFER__H__
|
#endif // __TEXT_VIEW_SUPPORT_BUFFER__H__
|
||||||
|
|
||||||
/*
|
|
||||||
* $Log $
|
|
||||||
*
|
|
||||||
* $Id $
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|||||||
Reference in New Issue
Block a user