Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-24 08:18:06

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   //! Default constructor
0038   NCollection_BasePointerVector() {}
0039 
0040   //! Copy data from another vector
0041   Standard_EXPORT NCollection_BasePointerVector(const NCollection_BasePointerVector& theOther);
0042 
0043   //! Move data from another vector
0044   Standard_EXPORT NCollection_BasePointerVector(NCollection_BasePointerVector&& theOther) noexcept;
0045 
0046   //! Destroy container
0047   ~NCollection_BasePointerVector() { clear(); }
0048 
0049   //! Checks for an empty status
0050   bool IsEmpty() const { return mySize == 0; }
0051 
0052   //! Gets used size
0053   size_t Size() const { return mySize; }
0054 
0055   //! Gets available capacity
0056   size_t Capacity() const { return myCapacity; }
0057 
0058   //! Erases last element, decrements size.
0059   void RemoveLast() { mySize--; }
0060 
0061   //! Resets the size
0062   void Clear(const bool theReleaseMemory = false)
0063   {
0064     if (theReleaseMemory)
0065       clear();
0066     mySize = 0;
0067   }
0068 
0069 public:
0070   //! Gets array, can be null
0071   void** GetArray() const { return myArray; }
0072 
0073   //! Gets value by index, no access validation
0074   void* Value(const size_t theInd) const { return myArray[theInd]; }
0075 
0076 public:
0077   //! Inserts new element at the end, increase size,
0078   //! if capacity is not enough, call resize.
0079   Standard_EXPORT void Append(const void* thePnt);
0080 
0081   //! Updates value of existed element,
0082   //! If index more then size, increase size of container,
0083   //! in this case capacity can be updated.
0084   Standard_EXPORT void SetValue(const size_t theInd, const void* thePnt);
0085 
0086   //! Copy vector
0087   Standard_EXPORT NCollection_BasePointerVector& operator=(
0088     const NCollection_BasePointerVector& theOther);
0089 
0090   //! Move vector
0091   Standard_EXPORT NCollection_BasePointerVector& operator=(
0092     NCollection_BasePointerVector&& theOther) noexcept;
0093 
0094 private:
0095   //! Deallocate array
0096   Standard_EXPORT void clear();
0097 
0098 private:
0099   size_t                       mySize     = 0;       //!< Used length of vector
0100   size_t                       myCapacity = 0;       //!< Allocated vector size
0101   void**                       myArray    = nullptr; //! Array of pointers
0102   NCollection_Allocator<void*> myAllocator;
0103 };
0104 
0105 #endif