Ticket #10396: 0003-Add-BStackOrHeapArray.patch

File 0003-Add-BStackOrHeapArray.patch, 1.3 KB (added by js, 6 years ago)
  • new file headers/os/support/StackOrHeapArray.h

    From 2afa233994e5303aa7d99530fa0b18e788cdb8b1 Mon Sep 17 00:00:00 2001
    From: Jonathan Schleifer <js@webkeks.org>
    Date: Fri, 10 Jan 2014 21:06:32 +0100
    Subject: [PATCH 03/10] Add BStackOrHeapArray.
    
    ---
     headers/os/support/StackOrHeapArray.h | 42 +++++++++++++++++++++++++++++++++++
     1 file changed, 42 insertions(+)
     create mode 100644 headers/os/support/StackOrHeapArray.h
    
    diff --git a/headers/os/support/StackOrHeapArray.h b/headers/os/support/StackOrHeapArray.h
    new file mode 100644
    index 0000000..af40bf0
    - +  
     1/*
     2 * Copyright 2012, Jonathan Schleifer <js@webkeks.org>. All Rights Reserved.
     3 * Distributed under the terms of the MIT License.
     4 */
     5#ifndef _SUPPORT_STACKORHEAPARRAY_H
     6#define _SUPPORT_STACKORHEAPARRAY_H
     7
     8#include <new>
     9
     10template <typename Type, int StackSize>
     11class BStackOrHeapArray {
     12public:
     13    BStackOrHeapArray(size_t count)
     14    {
     15        if (count > StackSize)
     16            fData = new(std::nothrow) Type[count];
     17        else
     18            fData = fStackData;
     19    }
     20
     21    ~BStackOrHeapArray()
     22    {
     23        if (fData != fStackData)
     24            delete[] fData;
     25    }
     26
     27    bool IsValid() const
     28    {
     29        return fData != NULL;
     30    }
     31
     32    operator Type*()
     33    {
     34        return fData;
     35    }
     36
     37private:
     38    Type    fStackData[StackSize];
     39    Type*   fData;
     40};
     41
     42#endif