michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* A handy class that will allocate data for size*T objects on the stack and michael@0: * otherwise allocate them on the heap. It is similar in purpose to nsAutoTArray */ michael@0: michael@0: template michael@0: class StackArray michael@0: { michael@0: public: michael@0: StackArray(size_t count) { michael@0: if (count > size) { michael@0: mData = new T[count]; michael@0: } else { michael@0: mData = mStackData; michael@0: } michael@0: } michael@0: ~StackArray() { michael@0: if (mData != mStackData) { michael@0: delete[] mData; michael@0: } michael@0: } michael@0: T& operator[](size_t n) { return mData[n]; } michael@0: const T& operator[](size_t n) const { return mData[n]; } michael@0: T* data() { return mData; }; michael@0: private: michael@0: T mStackData[size]; michael@0: T* mData; michael@0: };