From b5414381ec966c42388bd0e0f356fc2500a08fcb Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 2 Nov 2012 14:41:56 +0100 Subject: [PATCH] Added asserting copy constructors and assignment operators to volumes. --- .../include/PolyVoxCore/BaseVolume.h | 12 ++++--- .../include/PolyVoxCore/BaseVolume.inl | 36 ++++++++++++++++--- .../include/PolyVoxCore/LargeVolume.h | 9 ++++- .../include/PolyVoxCore/LargeVolume.inl | 26 ++++++++++++++ .../include/PolyVoxCore/RawVolume.h | 15 +++++--- .../include/PolyVoxCore/RawVolume.inl | 33 ++++++++++++++--- .../include/PolyVoxCore/SimpleVolume.h | 16 +++++---- .../include/PolyVoxCore/SimpleVolume.inl | 34 ++++++++++++++---- 8 files changed, 150 insertions(+), 31 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h index e1e7ab19..1b8211ae 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h @@ -141,13 +141,17 @@ namespace PolyVox protected: /// Constructor for creating a fixed size volume. - BaseVolume - ( - const Region& regValid - ); + BaseVolume(const Region& regValid); + + /// Copy constructor + BaseVolume(const BaseVolume& rhs); + /// Destructor ~BaseVolume(); + /// Assignment operator + BaseVolume& operator=(const BaseVolume& rhs); + //The size of the volume Region m_regValidRegion; diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl index c211edb9..e84b6fed 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl @@ -23,15 +23,30 @@ freely, subject to the following restrictions: 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 - BaseVolume::BaseVolume - ( - const Region& regValid - ) + BaseVolume::BaseVolume(const Region& 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 + BaseVolume::BaseVolume(const BaseVolume& rhs) + { + assert(false); // See function comment above. + } + //////////////////////////////////////////////////////////////////////////////// /// 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 + BaseVolume& BaseVolume::operator=(const BaseVolume& rhs) + { + assert(false); // See function comment above. + } + //////////////////////////////////////////////////////////////////////////////// /// The border value is returned whenever an attempt is made to read a voxel which /// is outside the extents of the volume. diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index a8f6729f..9bfbf380 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -297,7 +297,14 @@ namespace PolyVox /// Calculates approximatly how many bytes of memory the volume is currently using. 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); /// gets called when a new region is allocated and needs to be filled diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index fc1f0776..5e1c42a9 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -75,6 +75,19 @@ namespace PolyVox 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 + LargeVolume::LargeVolume(const LargeVolume& 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. //////////////////////////////////////////////////////////////////////////////// @@ -85,6 +98,19 @@ namespace PolyVox 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 + LargeVolume& LargeVolume::operator=(const LargeVolume& rhs) + { + assert(false); // See function comment above. + } + //////////////////////////////////////////////////////////////////////////////// /// The border value is returned whenever an atempt is made to read a voxel which /// is outside the extents of the volume. diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index dd799ea4..dd2bc235 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -117,10 +117,8 @@ namespace PolyVox public: /// Constructor for creating a fixed size volume. - RawVolume - ( - const Region& regValid - ); + RawVolume(const Region& regValid); + /// Destructor ~RawVolume(); @@ -141,7 +139,14 @@ namespace PolyVox /// Calculates approximatly how many bytes of memory the volume is currently using. 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); //The block data diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index b6fe2220..e1661999 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -28,11 +28,8 @@ namespace PolyVox /// \param regValid Specifies the minimum and maximum valid voxel positions. //////////////////////////////////////////////////////////////////////////////// template - RawVolume::RawVolume - ( - const Region& regValid - ) - :BaseVolume(regValid) + RawVolume::RawVolume(const Region& regValid) + :BaseVolume(regValid) { setBorderValue(VoxelType()); @@ -40,6 +37,19 @@ namespace PolyVox 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 + RawVolume::RawVolume(const RawVolume& rhs) + { + assert(false); // See function comment above. + } + //////////////////////////////////////////////////////////////////////////////// /// Destroys the volume //////////////////////////////////////////////////////////////////////////////// @@ -50,6 +60,19 @@ namespace PolyVox 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 + RawVolume& RawVolume::operator=(const RawVolume& rhs) + { + assert(false); // See function comment above. + } + //////////////////////////////////////////////////////////////////////////////// /// The border value is returned whenever an attempt is made to read a voxel which /// is outside the extents of the volume. diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h index 8902a47e..807a2a3a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h @@ -152,11 +152,8 @@ namespace PolyVox public: /// Constructor for creating a fixed size volume. - SimpleVolume - ( - const Region& regValid, - uint16_t uBlockSideLength = 32 - ); + SimpleVolume(const Region& regValid, uint16_t uBlockSideLength = 32); + /// Destructor ~SimpleVolume(); @@ -177,7 +174,14 @@ namespace PolyVox /// Calculates approximatly how many bytes of memory the volume is currently using. 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); Block* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const; diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index f5579662..054dc314 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -29,17 +29,26 @@ namespace PolyVox /// \param uBlockSideLength The size of the block to use within the volume //////////////////////////////////////////////////////////////////////////////// template - SimpleVolume::SimpleVolume - ( - const Region& regValid, - uint16_t uBlockSideLength - ) - :BaseVolume(regValid) + SimpleVolume::SimpleVolume(const Region& regValid, uint16_t uBlockSideLength) + :BaseVolume(regValid) { //Create a volume of the right size. 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 + SimpleVolume::SimpleVolume(const SimpleVolume& rhs) + { + assert(false); // See function comment above. + } + //////////////////////////////////////////////////////////////////////////////// /// Destroys the volume //////////////////////////////////////////////////////////////////////////////// @@ -50,6 +59,19 @@ namespace PolyVox 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 + SimpleVolume& SimpleVolume::operator=(const SimpleVolume& rhs) + { + assert(false); // See function comment above. + } + //////////////////////////////////////////////////////////////////////////////// /// The border value is returned whenever an attempt is made to read a voxel which /// is outside the extents of the volume.