Back to home page

EIC code displayed by LXR

 
 

    


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 // Created on: 2009-09-23
0002 // Copyright (c) 2009-2014 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
0014 
0015 #ifndef _NCollection_LocalArray_HeaderFile
0016 #define _NCollection_LocalArray_HeaderFile
0017 
0018 #include <Standard.hxx>
0019 #include <Standard_TypeDef.hxx>
0020 
0021 //! Auxiliary class optimizing creation of array buffer 
0022 //! (using stack allocation for small arrays).
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 // _NCollection_LocalArray_HeaderFile