0030416: Incorrect implementation of the method Bnd_OBB::SquareExtent
[occt.git] / src / MeshVS / MeshVS_Buffer.hxx
CommitLineData
b311480e 1// Created on: 2007-03-07
2// Created by: msv@EUCLIDEX
973c2be1 3// Copyright (c) 2007-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
16#ifndef MeshVS_Buffer_HeaderFile
17#define MeshVS_Buffer_HeaderFile
18
19#include <Standard.hxx>
114b7bf1 20#include <gp_Pnt.hxx>
7fd59977 21
22/**
23 * General purpose buffer that is allocated on the stack with a
24 * constant size MeshVS_BufSize, or is allocated dynamically if the requested
25 * size exceeds the standard one.
26 * It is useful when an allocation of an array of unknown size is needed,
27 * and most often the array is small enough to allocate as automatic C array.
28 */
29
30//! define the constant to the size of 10 points
31#define MeshVS_BufSize 10*3*sizeof(double)
32
33class MeshVS_Buffer
34{
35public:
36 //! Constructor of the buffer of the requested size
37 MeshVS_Buffer (const Standard_Size theSize)
38 : myDynData (0)
39 {
40 if (theSize > MeshVS_BufSize)
41 myDynData = Standard::Allocate (theSize);
42 }
43
44 //! Destructor
45 ~MeshVS_Buffer()
46 {
47 if (myDynData)
48 {
49 Standard::Free (myDynData);
50 myDynData = 0;
51 }
52 }
53
54 //! Cast the buffer to the void pointer
55 operator void* ()
56 {
57 return myDynData ? myDynData : (void*) myAutoData;
58 }
59
60 //! Interpret the buffer as a reference to double
61 operator Standard_Real& ()
62 {
63 return * (myDynData ? (Standard_Real*) myDynData : (Standard_Real*) myAutoData);
64 }
65
66 //! Interpret the buffer as a reference to int
67 operator Standard_Integer& ()
68 {
69 return * (myDynData ? (Standard_Integer*) myDynData : (Standard_Integer*) myAutoData);
70 }
71
114b7bf1 72 //! Interpret the buffer as a reference to gp_Pnt
73 operator gp_Pnt& ()
74 {
75 return * (myDynData ? (gp_Pnt*) myDynData : (gp_Pnt*) myAutoData);
76 }
77
7fd59977 78private:
79 //! Deprecate copy constructor
80 MeshVS_Buffer(const MeshVS_Buffer&) {}
81
82 //! Deprecate copy operation
83 MeshVS_Buffer& operator=(const MeshVS_Buffer&) {return *this;}
84
85 char myAutoData[ MeshVS_BufSize ];
86 void* myDynData;
87};
88
89#endif