Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Copyright (c) 2023 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef NCollection_BasePointerVector_HeaderFile
0015 #define NCollection_BasePointerVector_HeaderFile
0016 
0017 #include <Standard.hxx>
0018 
0019 #include <NCollection_Allocator.hxx>
0020 #include <NCollection_DefineAlloc.hxx>
0021 
0022 //! Simplified class for vector of pointers of void.
0023 //! Offers basic functionality to scalable inserts,
0024 //! resizes and erasing last.
0025 //!
0026 //! Control of processing values of pointers out-of-scope
0027 //! and should be controlled externally.
0028 //! Especially, copy operation should post-process elements of pointers to make deep copy.
0029 class NCollection_BasePointerVector 
0030 {
0031 public:
0032   //! Memory allocation
0033   DEFINE_STANDARD_ALLOC
0034   DEFINE_NCOLLECTION_ALLOC
0035 
0036 public:
0037 
0038   //! Default constructor
0039   NCollection_BasePointerVector() {}
0040 
0041   //! Copy data from another vector
0042   Standard_EXPORT NCollection_BasePointerVector(const NCollection_BasePointerVector& theOther);
0043 
0044   //! Move data from another vector
0045   Standard_EXPORT NCollection_BasePointerVector(NCollection_BasePointerVector&& theOther) noexcept;
0046 
0047   //! Destroy container
0048   ~NCollection_BasePointerVector() { clear(); }
0049 
0050   //! Checks for an empty status
0051   bool IsEmpty() const { return mySize == 0; }
0052 
0053   //! Gets used size
0054   size_t Size() const { return mySize; }
0055 
0056   //! Gets available capacity
0057   size_t Capacity() const { return myCapacity; }
0058 
0059   //! Erases last element, decrements size.
0060   void RemoveLast() { mySize--; }
0061 
0062   //! Resets the size
0063   void Clear(const bool theReleaseMemory = false)
0064   {
0065     if (theReleaseMemory)
0066       clear(); 
0067     mySize = 0;
0068   }
0069 
0070 public:
0071 
0072   //! Gets array, can be null
0073   void** GetArray() const { return myArray; }
0074 
0075   //! Gets value by index, no acess validation
0076   void* Value (const size_t theInd) const { return myArray[theInd]; }
0077 
0078 public:
0079 
0080   //! Inserts new element at the end, increase size,
0081   //! if capacity is not enough, call resize.
0082   Standard_EXPORT void Append (const void* thePnt);
0083 
0084   //! Updates value of existed element,
0085   //! If index more then size, increase size of container,
0086   //! in this case capacity can be updated.
0087   Standard_EXPORT void SetValue (const size_t theInd, const void* thePnt);
0088 
0089   //! Copy vector
0090   Standard_EXPORT NCollection_BasePointerVector& operator= (const NCollection_BasePointerVector& theOther);
0091 
0092   //! Move vector
0093   Standard_EXPORT NCollection_BasePointerVector& operator= (NCollection_BasePointerVector&& theOther) noexcept;
0094 
0095 private:
0096 
0097   //! Deallocate array
0098   Standard_EXPORT void clear();
0099 
0100 private:
0101   size_t mySize = 0; //!< Used length of vector
0102   size_t myCapacity = 0; //!< Allocated vector size
0103   void** myArray = nullptr; //! Array of pointers
0104   NCollection_Allocator<void*> myAllocator;
0105 };
0106 
0107 #endif