From a2fab5626d1dfed8391d7923a7b29a0b7a2b531a Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Thu, 4 Nov 2004 08:53:46 +0000 Subject: [PATCH] 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 --- .../private/interface/TextViewSupportBuffer.h | 46 +++++++++---------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/headers/private/interface/TextViewSupportBuffer.h b/headers/private/interface/TextViewSupportBuffer.h index 58575336ce..52cd0cfb5c 100644 --- a/headers/private/interface/TextViewSupportBuffer.h +++ b/headers/private/interface/TextViewSupportBuffer.h @@ -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 // copy of this software and associated documentation files (the "Software"), @@ -20,7 +20,8 @@ // DEALINGS IN THE SOFTWARE. // // File Name: TextViewSupportBuffer.h -// Author: Marc Flerackers (mflerackers@androme.be) +// Authors Marc Flerackers (mflerackers@androme.be) +// Stefano Ceccherini (burton666@libero.it) // Description: Template class used to implement the various BTextView // buffer classes. //------------------------------------------------------------------------------ @@ -28,20 +29,12 @@ #ifndef __TEXT_VIEW_SUPPORT_BUFFER__H__ #define __TEXT_VIEW_SUPPORT_BUFFER__H__ -// Standard Includes ----------------------------------------------------------- #include #include -// System Includes ------------------------------------------------------------- +#include #include -// Project Includes ------------------------------------------------------------ - -// Local Includes -------------------------------------------------------------- - -// Local Defines --------------------------------------------------------------- - -// Globals --------------------------------------------------------------------- // _BTextViewSupportBuffer_ class ---------------------------------------------- template @@ -62,7 +55,8 @@ protected: int32 fBufferCount; T* fBuffer; }; -//------------------------------------------------------------------------------ + + template _BTextViewSupportBuffer_::_BTextViewSupportBuffer_(int32 inExtraCount, int32 inCount) @@ -73,15 +67,18 @@ _BTextViewSupportBuffer_::_BTextViewSupportBuffer_(int32 inExtraCount, { fBuffer = (T *)calloc(fExtraCount + fItemCount, sizeof(T)); } -//------------------------------------------------------------------------------ + + template _BTextViewSupportBuffer_::~_BTextViewSupportBuffer_() { free(fBuffer); } -//------------------------------------------------------------------------------ + + template -void _BTextViewSupportBuffer_::InsertItemsAt(int32 inNumItems, +void +_BTextViewSupportBuffer_::InsertItemsAt(int32 inNumItems, int32 inAtIndex, const T *inItem) { @@ -96,6 +93,8 @@ void _BTextViewSupportBuffer_::InsertItemsAt(int32 inNumItems, if ((logSize + delta) >= fBufferCount) { fBufferCount = logSize + delta + (fExtraCount * sizeof(T)); fBuffer = (T *)realloc(fBuffer, fBufferCount); + if (fBuffer == NULL) + debugger("InsertItemsAt(): reallocation failed"); } T *loc = fBuffer + inAtIndex; @@ -104,7 +103,8 @@ void _BTextViewSupportBuffer_::InsertItemsAt(int32 inNumItems, fItemCount += inNumItems; } -//------------------------------------------------------------------------------ + + template void _BTextViewSupportBuffer_::RemoveItemsAt(int32 inNumItems, @@ -126,24 +126,20 @@ _BTextViewSupportBuffer_::RemoveItemsAt(int32 inNumItems, if (extraSize > (fExtraCount * sizeof(T))) { fBufferCount = (logSize - delta) + (fExtraCount * sizeof(T)); fBuffer = (T *)realloc(fBuffer, fBufferCount); + if (fBuffer == NULL) + debugger("RemoveItemsAt(): reallocation failed"); } fItemCount -= inNumItems; } -//------------------------------------------------------------------------------ + + template inline int32 _BTextViewSupportBuffer_::ItemCount() const { return fItemCount; } -//------------------------------------------------------------------------------ + #endif // __TEXT_VIEW_SUPPORT_BUFFER__H__ - -/* - * $Log $ - * - * $Id $ - * - */