Added asserting copy constructors and assignment operators to volumes.

This commit is contained in:
unknown 2012-11-02 14:41:56 +01:00
parent 2566f3a7d2
commit b5414381ec
8 changed files with 150 additions and 31 deletions

View File

@ -141,13 +141,17 @@ namespace PolyVox
protected: protected:
/// Constructor for creating a fixed size volume. /// Constructor for creating a fixed size volume.
BaseVolume BaseVolume(const Region& regValid);
(
const Region& regValid /// Copy constructor
); BaseVolume(const BaseVolume& rhs);
/// Destructor /// Destructor
~BaseVolume(); ~BaseVolume();
/// Assignment operator
BaseVolume& operator=(const BaseVolume& rhs);
//The size of the volume //The size of the volume
Region m_regValidRegion; Region m_regValidRegion;

View File

@ -23,15 +23,30 @@ freely, subject to the following restrictions:
namespace PolyVox namespace PolyVox
{ {
////////////////////////////////////////////////////////////////////////////////
/// This is protected because you should never create a BaseVolume directly, you should instead use one of the derived classes.
///
/// \sa RawVolume, SimpleVolume, LargeVolume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType> template <typename VoxelType>
BaseVolume<VoxelType>::BaseVolume BaseVolume<VoxelType>::BaseVolume(const Region& regValid)
(
const Region& regValid
)
:m_regValidRegion(regValid) :m_regValidRegion(regValid)
{ {
} }
////////////////////////////////////////////////////////////////////////////////
/// This function should never be called. Copying volumes by value would be expensive, and we want to prevent users from doing
/// it by accident (such as when passing them as paramenters to functions). That said, there are times when you really do want to
/// make a copy of a volume and in this case you should look at the Volumeresampler.
///
/// \sa VolumeResampler
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
BaseVolume<VoxelType>::BaseVolume(const BaseVolume<VoxelType>& rhs)
{
assert(false); // See function comment above.
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// Destroys the volume /// Destroys the volume
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -40,6 +55,19 @@ namespace PolyVox
{ {
} }
////////////////////////////////////////////////////////////////////////////////
/// This function should never be called. Copying volumes by value would be expensive, and we want to prevent users from doing
/// it by accident (such as when passing them as paramenters to functions). That said, there are times when you really do want to
/// make a copy of a volume and in this case you should look at the Volumeresampler.
///
/// \sa VolumeResampler
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
BaseVolume<VoxelType>& BaseVolume<VoxelType>::operator=(const BaseVolume<VoxelType>& rhs)
{
assert(false); // See function comment above.
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// The border value is returned whenever an attempt is made to read a voxel which /// The border value is returned whenever an attempt is made to read a voxel which
/// is outside the extents of the volume. /// is outside the extents of the volume.

View File

@ -297,7 +297,14 @@ namespace PolyVox
/// Calculates approximatly how many bytes of memory the volume is currently using. /// Calculates approximatly how many bytes of memory the volume is currently using.
uint32_t calculateSizeInBytes(void); uint32_t calculateSizeInBytes(void);
private: protected:
/// Copy constructor
LargeVolume(const LargeVolume& rhs);
/// Assignment operator
LargeVolume& operator=(const LargeVolume& rhs);
private:
void initialise(const Region& regValidRegion, uint16_t uBlockSideLength); void initialise(const Region& regValidRegion, uint16_t uBlockSideLength);
/// gets called when a new region is allocated and needs to be filled /// gets called when a new region is allocated and needs to be filled

View File

@ -75,6 +75,19 @@ namespace PolyVox
initialise(regValid,uBlockSideLength); initialise(regValid,uBlockSideLength);
} }
////////////////////////////////////////////////////////////////////////////////
/// This function should never be called. Copying volumes by value would be expensive, and we want to prevent users from doing
/// it by accident (such as when passing them as paramenters to functions). That said, there are times when you really do want to
/// make a copy of a volume and in this case you should look at the Volumeresampler.
///
/// \sa VolumeResampler
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
LargeVolume<VoxelType>::LargeVolume(const LargeVolume<VoxelType>& rhs)
{
assert(false); // See function comment above.
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// Destroys the volume The destructor will call flushAll() to ensure that a paging volume has the chance to save it's data via the dataOverflowHandler() if desired. /// Destroys the volume The destructor will call flushAll() to ensure that a paging volume has the chance to save it's data via the dataOverflowHandler() if desired.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -85,6 +98,19 @@ namespace PolyVox
delete[] m_pUncompressedBorderData; delete[] m_pUncompressedBorderData;
} }
////////////////////////////////////////////////////////////////////////////////
/// This function should never be called. Copying volumes by value would be expensive, and we want to prevent users from doing
/// it by accident (such as when passing them as paramenters to functions). That said, there are times when you really do want to
/// make a copy of a volume and in this case you should look at the Volumeresampler.
///
/// \sa VolumeResampler
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
LargeVolume<VoxelType>& LargeVolume<VoxelType>::operator=(const LargeVolume<VoxelType>& rhs)
{
assert(false); // See function comment above.
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// The border value is returned whenever an atempt is made to read a voxel which /// The border value is returned whenever an atempt is made to read a voxel which
/// is outside the extents of the volume. /// is outside the extents of the volume.

View File

@ -117,10 +117,8 @@ namespace PolyVox
public: public:
/// Constructor for creating a fixed size volume. /// Constructor for creating a fixed size volume.
RawVolume RawVolume(const Region& regValid);
(
const Region& regValid
);
/// Destructor /// Destructor
~RawVolume(); ~RawVolume();
@ -141,7 +139,14 @@ namespace PolyVox
/// Calculates approximatly how many bytes of memory the volume is currently using. /// Calculates approximatly how many bytes of memory the volume is currently using.
uint32_t calculateSizeInBytes(void); uint32_t calculateSizeInBytes(void);
private: protected:
/// Copy constructor
RawVolume(const RawVolume& rhs);
/// Assignment operator
RawVolume& operator=(const RawVolume& rhs);
private:
void initialise(const Region& regValidRegion); void initialise(const Region& regValidRegion);
//The block data //The block data

View File

@ -28,11 +28,8 @@ namespace PolyVox
/// \param regValid Specifies the minimum and maximum valid voxel positions. /// \param regValid Specifies the minimum and maximum valid voxel positions.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType> template <typename VoxelType>
RawVolume<VoxelType>::RawVolume RawVolume<VoxelType>::RawVolume(const Region& regValid)
( :BaseVolume<VoxelType>(regValid)
const Region& regValid
)
:BaseVolume<VoxelType>(regValid)
{ {
setBorderValue(VoxelType()); setBorderValue(VoxelType());
@ -40,6 +37,19 @@ namespace PolyVox
initialise(regValid); initialise(regValid);
} }
////////////////////////////////////////////////////////////////////////////////
/// This function should never be called. Copying volumes by value would be expensive, and we want to prevent users from doing
/// it by accident (such as when passing them as paramenters to functions). That said, there are times when you really do want to
/// make a copy of a volume and in this case you should look at the Volumeresampler.
///
/// \sa VolumeResampler
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
RawVolume<VoxelType>::RawVolume(const RawVolume<VoxelType>& rhs)
{
assert(false); // See function comment above.
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// Destroys the volume /// Destroys the volume
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -50,6 +60,19 @@ namespace PolyVox
m_pData = 0; m_pData = 0;
} }
////////////////////////////////////////////////////////////////////////////////
/// This function should never be called. Copying volumes by value would be expensive, and we want to prevent users from doing
/// it by accident (such as when passing them as paramenters to functions). That said, there are times when you really do want to
/// make a copy of a volume and in this case you should look at the Volumeresampler.
///
/// \sa VolumeResampler
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
RawVolume<VoxelType>& RawVolume<VoxelType>::operator=(const RawVolume<VoxelType>& rhs)
{
assert(false); // See function comment above.
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// The border value is returned whenever an attempt is made to read a voxel which /// The border value is returned whenever an attempt is made to read a voxel which
/// is outside the extents of the volume. /// is outside the extents of the volume.

View File

@ -152,11 +152,8 @@ namespace PolyVox
public: public:
/// Constructor for creating a fixed size volume. /// Constructor for creating a fixed size volume.
SimpleVolume SimpleVolume(const Region& regValid, uint16_t uBlockSideLength = 32);
(
const Region& regValid,
uint16_t uBlockSideLength = 32
);
/// Destructor /// Destructor
~SimpleVolume(); ~SimpleVolume();
@ -177,7 +174,14 @@ namespace PolyVox
/// Calculates approximatly how many bytes of memory the volume is currently using. /// Calculates approximatly how many bytes of memory the volume is currently using.
uint32_t calculateSizeInBytes(void); uint32_t calculateSizeInBytes(void);
private: protected:
/// Copy constructor
SimpleVolume(const SimpleVolume& rhs);
/// Assignment operator
SimpleVolume& operator=(const SimpleVolume& rhs);
private:
void initialise(const Region& regValidRegion, uint16_t uBlockSideLength); void initialise(const Region& regValidRegion, uint16_t uBlockSideLength);
Block* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const; Block* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const;

View File

@ -29,17 +29,26 @@ namespace PolyVox
/// \param uBlockSideLength The size of the block to use within the volume /// \param uBlockSideLength The size of the block to use within the volume
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType> template <typename VoxelType>
SimpleVolume<VoxelType>::SimpleVolume SimpleVolume<VoxelType>::SimpleVolume(const Region& regValid, uint16_t uBlockSideLength)
( :BaseVolume<VoxelType>(regValid)
const Region& regValid,
uint16_t uBlockSideLength
)
:BaseVolume<VoxelType>(regValid)
{ {
//Create a volume of the right size. //Create a volume of the right size.
initialise(regValid,uBlockSideLength); initialise(regValid,uBlockSideLength);
} }
////////////////////////////////////////////////////////////////////////////////
/// This function should never be called. Copying volumes by value would be expensive, and we want to prevent users from doing
/// it by accident (such as when passing them as paramenters to functions). That said, there are times when you really do want to
/// make a copy of a volume and in this case you should look at the Volumeresampler.
///
/// \sa VolumeResampler
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
SimpleVolume<VoxelType>::SimpleVolume(const SimpleVolume<VoxelType>& rhs)
{
assert(false); // See function comment above.
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// Destroys the volume /// Destroys the volume
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -50,6 +59,19 @@ namespace PolyVox
delete[] m_pUncompressedBorderData; delete[] m_pUncompressedBorderData;
} }
////////////////////////////////////////////////////////////////////////////////
/// This function should never be called. Copying volumes by value would be expensive, and we want to prevent users from doing
/// it by accident (such as when passing them as paramenters to functions). That said, there are times when you really do want to
/// make a copy of a volume and in this case you should look at the Volumeresampler.
///
/// \sa VolumeResampler
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
SimpleVolume<VoxelType>& SimpleVolume<VoxelType>::operator=(const SimpleVolume<VoxelType>& rhs)
{
assert(false); // See function comment above.
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// The border value is returned whenever an attempt is made to read a voxel which /// The border value is returned whenever an attempt is made to read a voxel which
/// is outside the extents of the volume. /// is outside the extents of the volume.