Przeglądaj źródła

ImVector: Added assignments and = operators + comments.

omar 7 lat temu
rodzic
commit
6172e93272
1 zmienionych plików z 3 dodań i 1 usunięć
  1. 3 1
      imgui.h

+ 3 - 1
imgui.h

@@ -1005,7 +1005,7 @@ namespace ImGui
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 
 
 // Lightweight std::vector<> like class to avoid dragging dependencies (also: windows implementation of STL with debug enabled is absurdly slow, so let's bypass it so our code runs fast in debug).
 // Lightweight std::vector<> like class to avoid dragging dependencies (also: windows implementation of STL with debug enabled is absurdly slow, so let's bypass it so our code runs fast in debug).
-// Our implementation does NOT call c++ constructors because we don't use them in ImGui. Don't use this class as a straight std::vector replacement in your code!
+// Our implementation does NOT call C++ constructors/destructors. This is intentional and we do not require it. Do not use this class as a straight std::vector replacement in your code!
 template<typename T>
 template<typename T>
 class ImVector
 class ImVector
 {
 {
@@ -1020,6 +1020,8 @@ public:
 
 
     ImVector()                  { Size = Capacity = 0; Data = NULL; }
     ImVector()                  { Size = Capacity = 0; Data = NULL; }
     ~ImVector()                 { if (Data) ImGui::MemFree(Data); }
     ~ImVector()                 { if (Data) ImGui::MemFree(Data); }
+    ImVector(const ImVector<T>& rhs)                            { Size = Capacity = 0; Data = NULL; if (rhs.Size) { resize(rhs.Size); memcpy(Data, rhs.Data, (size_t)rhs.Size * sizeof(T)); } }
+    ImVector<T>& operator=(const ImVector<T>& rhs)              { resize(rhs.Size); if (rhs.Size) memcpy(Data, rhs.Data, (size_t)rhs.Size * sizeof(T)); return *this; }
 
 
     inline bool                 empty() const                   { return Size == 0; }
     inline bool                 empty() const                   { return Size == 0; }
     inline int                  size() const                    { return Size; }
     inline int                  size() const                    { return Size; }