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

  • From: midar-github.master <community@xxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 29 Jan 2013 03:15:45 +0100 (CET)

added 1 changeset to branch 'refs/remotes/midar-github/master'
old head: 9e7c4b1954922f7f4ff1f31ccce02afaedb424f6
new head: e14356e39d206406b766dd28aedb58e8c546450a
overview: https://github.com/Midar/haiku/compare/9e7c4b1...e14356e

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

e14356e: Add BStackOrHeapArray.

                                     [ Jonathan Schleifer <js@xxxxxxxxxxx> ]

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

Commit:      e14356e39d206406b766dd28aedb58e8c546450a
Author:      Jonathan Schleifer <js@xxxxxxxxxxx>
Date:        Tue Jan 29 00:51:04 2013 UTC

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

1 file changed, 42 insertions(+)
headers/os/support/StackOrHeapArray.h | 42 +++++++++++++++++++++++++++++++

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

diff --git a/headers/os/support/StackOrHeapArray.h 
b/headers/os/support/StackOrHeapArray.h
new file mode 100644
index 0000000..af40bf0
--- /dev/null
+++ b/headers/os/support/StackOrHeapArray.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2012, Jonathan Schleifer <js@xxxxxxxxxxx>. All Rights Reserved.
+ * Distributed under the terms of the MIT License.
+ */
+#ifndef        _SUPPORT_STACKORHEAPARRAY_H
+#define        _SUPPORT_STACKORHEAPARRAY_H
+
+#include <new>
+
+template <typename Type, int StackSize>
+class BStackOrHeapArray {
+public:
+       BStackOrHeapArray(size_t count)
+       {
+               if (count > StackSize)
+                       fData = new(std::nothrow) Type[count];
+               else
+                       fData = fStackData;
+       }
+
+       ~BStackOrHeapArray()
+       {
+               if (fData != fStackData)
+                       delete[] fData;
+       }
+
+       bool IsValid() const
+       {
+               return fData != NULL;
+       }
+
+       operator Type*()
+       {
+               return fData;
+       }
+
+private:
+       Type    fStackData[StackSize];
+       Type*   fData;
+};
+
+#endif


Other related posts: