[haiku-commits] BRANCH midar-github.master - headers/os/support

  • From: midar-github.master <community@xxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 20 Nov 2012 17:00:48 +0100 (CET)

added 1 changeset to branch 'refs/remotes/midar-github/master'
old head: 679d9bd3c5621b0060b0f83bb731b9e4a14ac10b
new head: 285f1d0b9ca4f4ee9caf1823cbc25e23bea817ae
overview: https://github.com/Midar/haiku/compare/679d9bd...285f1d0

----------------------------------------------------------------------------

285f1d0: StackOrHeapArray: Style and improvements.

                                     [ Jonathan Schleifer <js@xxxxxxxxxxx> ]

----------------------------------------------------------------------------

Commit:      285f1d0b9ca4f4ee9caf1823cbc25e23bea817ae
Author:      Jonathan Schleifer <js@xxxxxxxxxxx>
Date:        Tue Nov 20 15:49:06 2012 UTC

----------------------------------------------------------------------------

1 file changed, 21 insertions(+), 19 deletions(-)
headers/os/support/StackOrHeapArray.h | 40 ++++++++++++++++---------------

----------------------------------------------------------------------------

diff --git a/headers/os/support/StackOrHeapArray.h 
b/headers/os/support/StackOrHeapArray.h
index 46917f8..a231a95 100644
--- a/headers/os/support/StackOrHeapArray.h
+++ b/headers/os/support/StackOrHeapArray.h
@@ -7,39 +7,41 @@
 
 #include <new>
 
-template <typename T, int C>
-class BStackOrHeapArray
-{
-private:
-       T stackData[C];
-       T *data;
-
+template <typename Type, int StackSize>
+class BStackOrHeapArray {
 public:
-       BStackOrHeapArray(unsigned long count)
+       BStackOrHeapArray(size_t count)
        {
-               if (count > C)
-                       data = new(std::nothrow) T[count];
+               if (count > StackSize)
+                       fData = new(std::nothrow) Type[count];
                else
-                       data = stackData;
+                       fData = fStackData;
        }
 
        ~BStackOrHeapArray()
        {
-               if (data != stackData)
-                       delete[] data;
+               if (fData != fStackData)
+                       delete[] fData;
        }
 
-       T&
-       operator [](unsigned long index)
+       bool IsValid() const
        {
-               return data[index];
+               return fData != NULL;
        }
 
-       T*
-       operator ()()
+       Type& operator[](size_t index)
        {
-               return data;
+               return fData[index];
        }
+
+       Type* operator()()
+       {
+               return fData;
+       }
+
+private:
+       Type    fStackData[StackSize];
+       Type*   fData;
 };
 
 #endif


Other related posts: