Warning, file /include/opencascade/NCollection_LocalArray.hxx was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef _NCollection_LocalArray_HeaderFile
0016 #define _NCollection_LocalArray_HeaderFile
0017
0018 #include <Standard.hxx>
0019 #include <Standard_TypeDef.hxx>
0020
0021
0022
0023 template<class theItem, Standard_Integer MAX_ARRAY_SIZE = 1024> class NCollection_LocalArray
0024 {
0025 public:
0026
0027 explicit NCollection_LocalArray (const size_t theSize)
0028 : myPtr (myBuffer)
0029 {
0030 Allocate(theSize);
0031 }
0032
0033 NCollection_LocalArray ()
0034 : myPtr (myBuffer), mySize(0) {}
0035
0036 ~NCollection_LocalArray()
0037 {
0038 Deallocate();
0039 }
0040
0041 void Allocate (const size_t theSize)
0042 {
0043 Deallocate();
0044 if (theSize > MAX_ARRAY_SIZE)
0045 myPtr = (theItem*)Standard::Allocate (theSize * sizeof(theItem));
0046 else
0047 myPtr = myBuffer;
0048
0049 mySize = theSize;
0050 }
0051
0052 size_t Size() const
0053 {
0054 return mySize;
0055 }
0056
0057 operator theItem*() const
0058 {
0059 return myPtr;
0060 }
0061
0062 private:
0063
0064 NCollection_LocalArray (const NCollection_LocalArray& );
0065 NCollection_LocalArray& operator= (const NCollection_LocalArray& );
0066
0067 protected:
0068
0069 void Deallocate()
0070 {
0071 if (myPtr != myBuffer)
0072 Standard::Free (myPtr);
0073 }
0074
0075 protected:
0076
0077 theItem myBuffer[MAX_ARRAY_SIZE];
0078 theItem* myPtr;
0079 size_t mySize;
0080
0081 };
0082
0083 #endif