Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:15

0001 // Created on: 2007-03-07
0002 // Created by: msv@EUCLIDEX
0003 // Copyright (c) 2007-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef MeshVS_Buffer_HeaderFile
0017 #define MeshVS_Buffer_HeaderFile
0018 
0019 #include <Standard.hxx>
0020 #include <gp_Pnt.hxx>
0021 
0022 /**
0023  * General purpose buffer that is allocated on the stack with a
0024  * constant size MeshVS_BufSize, or is allocated dynamically if the requested
0025  * size exceeds the standard one.
0026  * It is useful when an allocation of an array of unknown size is needed,
0027  * and most often the array is small enough to allocate as automatic C array.
0028  */
0029 
0030 //! define the constant to the size of 10 points
0031 #define MeshVS_BufSize 10*3*sizeof(double)
0032 
0033 class MeshVS_Buffer 
0034 {
0035 public:
0036   //! Constructor of the buffer of the requested size
0037   MeshVS_Buffer (const Standard_Size theSize)
0038     : myDynData (0)
0039   {
0040     if (theSize > MeshVS_BufSize)
0041       myDynData = Standard::Allocate (theSize);
0042   }
0043 
0044   //! Destructor
0045   ~MeshVS_Buffer()
0046   {
0047     if (myDynData)
0048     {
0049       Standard::Free (myDynData);
0050       myDynData = 0;
0051     }
0052   }
0053 
0054   //! Cast the buffer to the void pointer
0055   operator void* ()
0056   {
0057     return myDynData ? myDynData : (void*) myAutoData;
0058   }
0059 
0060   //! Interpret the buffer as a reference to double
0061   operator Standard_Real& ()
0062   {
0063     return * (myDynData ? (Standard_Real*) myDynData : (Standard_Real*) myAutoData);
0064   }
0065 
0066   //! Interpret the buffer as a reference to int
0067   operator Standard_Integer& ()
0068   {
0069     return * (myDynData ? (Standard_Integer*) myDynData : (Standard_Integer*) myAutoData);
0070   }
0071 
0072   //! Interpret the buffer as a reference to gp_Pnt
0073   operator gp_Pnt& ()
0074   {
0075     return * (myDynData ? (gp_Pnt*) myDynData : (gp_Pnt*) myAutoData);
0076   }
0077 
0078 private:
0079   //! Deprecate copy constructor
0080   MeshVS_Buffer(const MeshVS_Buffer&) {}
0081 
0082   //! Deprecate copy operation
0083   MeshVS_Buffer& operator=(const MeshVS_Buffer&) {return *this;}
0084 
0085   char  myAutoData[ MeshVS_BufSize ];
0086   void* myDynData;
0087 };
0088 
0089 #endif