2016-02-29 19:54:36 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2014-05-09 05:03:37 +04:00
|
|
|
/* vim: set ts=8 sts=4 et sw=4 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef HEAPCOPYOFSTACKARRAY_H_
|
|
|
|
#define HEAPCOPYOFSTACKARRAY_H_
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
2016-02-29 19:54:36 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2014-05-09 05:03:37 +04:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
// Takes a stack array and copies it into a heap buffer.
|
|
|
|
// Useful to retain the convenience of declaring static arrays, while
|
|
|
|
// avoiding passing stack pointers to the GL (see bug 1005658).
|
|
|
|
|
|
|
|
template <typename ElemType>
|
|
|
|
class HeapCopyOfStackArray
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
template<size_t N>
|
2017-07-18 05:17:41 +03:00
|
|
|
MOZ_IMPLICIT HeapCopyOfStackArray(const ElemType (&array)[N])
|
2014-05-09 05:03:37 +04:00
|
|
|
: mArrayLength(N)
|
2016-02-29 19:54:36 +03:00
|
|
|
, mArrayData(MakeUnique<ElemType[]>(N))
|
2014-05-09 05:03:37 +04:00
|
|
|
{
|
2016-02-29 19:54:36 +03:00
|
|
|
memcpy(mArrayData.get(), &array[0], N * sizeof(ElemType));
|
2014-05-09 05:03:37 +04:00
|
|
|
}
|
|
|
|
|
2016-02-29 19:54:36 +03:00
|
|
|
ElemType* Data() const { return mArrayData.get(); }
|
2014-05-09 05:03:37 +04:00
|
|
|
size_t ArrayLength() const { return mArrayLength; }
|
|
|
|
size_t ByteLength() const { return mArrayLength * sizeof(ElemType); }
|
|
|
|
|
|
|
|
private:
|
2015-01-07 02:35:02 +03:00
|
|
|
HeapCopyOfStackArray() = delete;
|
|
|
|
HeapCopyOfStackArray(const HeapCopyOfStackArray&) = delete;
|
2014-05-09 05:03:37 +04:00
|
|
|
|
|
|
|
const size_t mArrayLength;
|
2016-02-29 19:54:36 +03:00
|
|
|
UniquePtr<ElemType[]> const mArrayData;
|
2014-05-09 05:03:37 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
2014-05-09 05:03:37 +04:00
|
|
|
|
2015-07-28 04:14:42 +03:00
|
|
|
#endif // HEAPCOPYOFSTACKARRAY_H_
|