Skip to content

Commit

Permalink
Fixed memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Htrap19 committed Aug 7, 2020
1 parent 222914c commit d43682a
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 196 deletions.
3 changes: 2 additions & 1 deletion CGUI.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "./Widgets/Dialog/Dialog.hh"
#include "./Widgets/FileChooser/FileChooser.hh"
#include "./Custom/List/List.hh"
#include "./Custom/Storage/Storage.hh"
#include "./Custom/DeleteOnQuit/DeleteOnQuit.hh"
#include "./Widgets/FileChooserDialog/FileChooserDialog.hh"
#include "./Widgets/StyleContext.hh"
#include "./Widgets/Grid/Grid.hh"
Expand Down Expand Up @@ -57,6 +57,7 @@
#include "./Widgets/SpinButton/SpinButton.hh"
#include "./Widgets/ListBox/ListBox.hh"
#include "./Widgets/FlowBox/FlowBox.hh"
#include "./Widgets/EventBox/EventBox.hh"
#include "./Pixbuf/Pixbuf.hh"
#include "./Custom/Initialize/Initialize.hh"
#include "./Widgets/Entry/EntryBuffer/EntryBuffer.hh"
Expand Down
2 changes: 1 addition & 1 deletion Converter/Convert.hh
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ namespace CGui
enum class SizeRequestMode { HEIGHT_FOR_WIDTH, WIDTH_FOR_HEIGHT, CONSTANT_SIZE };

enum class Gravity { NORTH_WEST = 1, NORTH, NORTH_EAST, WEST, CENTER, EAST, SOUTH_WEST, SOUTH, SOUTH_EAST, STATIC };

struct WindowPositionData
{
int root_x;
Expand Down
55 changes: 55 additions & 0 deletions Custom/DeleteOnQuit/DeleteOnQuit.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#pragma once

#include <iostream>
#include "../List/List.hh"

namespace CGui
{
class DeleteOnQuit
{
public:
DeleteOnQuit(const DeleteOnQuit&) = delete;
DeleteOnQuit(const DeleteOnQuit&&) = delete;
DeleteOnQuit& operator=(const DeleteOnQuit&) = delete;
DeleteOnQuit& operator=(const DeleteOnQuit&&) = delete;
DeleteOnQuit& operator==(const DeleteOnQuit&) = delete;
DeleteOnQuit& operator==(const DeleteOnQuit&&) = delete;

static DeleteOnQuit& GetInstance()
{
static DeleteOnQuit instance;
return instance;
}

void Add(void* data)
{
l_instance->Insert(data);
}

void ForEach(void(*func)(void*))
{
l_instance->ForEach(func);
}

Single::List<void*>* list()
{
return l_instance;
}

~DeleteOnQuit()
{
l_instance->ForEach([](void* data) -> void
{
delete data;
});
delete l_instance;
}

private:
DeleteOnQuit() : l_instance{ new Single::List<void*> }
{
}

Single::List<void*>* l_instance;
};
};
11 changes: 1 addition & 10 deletions Custom/Initialize/Initialize.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <gtk/gtk.h>
#include "../Storage/Storage.hh"
#include "../DeleteOnQuit/DeleteOnQuit.hh"

namespace CGui
{
Expand Down Expand Up @@ -66,15 +66,6 @@ namespace CGui
Storage::GetInstance().ForEach<const char*, KeyValue::List<Signals, std::any>*>(f4, "mainlistsignals");
Storage::GetInstance().Free<const char*, KeyValue::List<Signals, std::any>*>("mainlistsignals");*/

auto free = [](KeyValue::Node<const char*, void*> * node) -> void
{
if (std::string(node->key) == "Instance")
delete node->value;
};

Storage::GetInstance().ForEach<const char*, void*>(free, "deleteonquit");
Storage::GetInstance().Free<const char*, void*>("deleteonquit");

gtk_main_quit();
}
};
151 changes: 0 additions & 151 deletions Custom/Storage/Storage.hh

This file was deleted.

10 changes: 4 additions & 6 deletions Widgets/Container.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <gtk/gtk.h>
#include "./Widget.hh"
#include "../Custom/List/List.hh"
#include "../Custom/Storage/Storage.hh"
#include "../Custom/DeleteOnQuit/DeleteOnQuit.hh"

namespace CGui
{
Expand All @@ -14,7 +14,7 @@ namespace CGui
Container(WidgetType* w)
{
t_widget = w;
Storage::GetInstance().MakePrivate<const char*, void*>("deleteonquit");
/*Storage::GetInstance().MakePrivate<const char*, void*>("deleteonquit");*/
}

virtual ~Container()
Expand All @@ -23,7 +23,7 @@ namespace CGui
{
children.ForEach([](void* data)
{
Storage::GetInstance().Add<const char*, void*>("Instance", data, "deleteonquit");
DeleteOnQuit::GetInstance().Add(data);
});
}
}
Expand Down Expand Up @@ -96,7 +96,6 @@ namespace CGui
Container(GtkWidget* w)
{
t_widget = w;
Storage::GetInstance().MakePrivate<const char*, void*>("deleteonquit");
}

virtual ~Container()
Expand All @@ -105,7 +104,7 @@ namespace CGui
{
children.ForEach([](void* data)
{
Storage::GetInstance().Add<const char*, void*>("Instance", data, "deleteonquit");
DeleteOnQuit::GetInstance().Add(data);
});
}
}
Expand Down Expand Up @@ -167,7 +166,6 @@ namespace CGui
protected:
Container()
{
Storage::GetInstance().MakePrivate<const char*, void*>("deleteonquit");
}

GtkWidget* t_widget;
Expand Down
37 changes: 37 additions & 0 deletions Widgets/EventBox/EventBox.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "./EventBox.hh"

namespace CGui
{
EventBox::EventBox() : Container(this), Handler(this)
{
widget = gtk_event_box_new();
this->SetContext(widget);
}

EventBox::EventBox(Widget& w) : Container(this), Handler(this)
{
widget = gtk_event_box_new();
this->SetContext(widget);
this->Add(w);
}

void EventBox::VisibleWindow(bool visible)
{
gtk_event_box_set_visible_window(GTK_EVENT_BOX(widget), visible);
}

bool EventBox::VisibleWindow()
{
return gtk_event_box_get_visible_window(GTK_EVENT_BOX(widget));
}

void EventBox::AboveChild(bool above)
{
gtk_event_box_set_above_child(GTK_EVENT_BOX(widget), above);
}

bool EventBox::AboveChild()
{
return gtk_event_box_get_above_child(GTK_EVENT_BOX(widget));
}
}
19 changes: 19 additions & 0 deletions Widgets/EventBox/EventBox.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include "../Widget.hh"
#include "../Container.hh"
#include "../Handler.hh"

namespace CGui
{
class EventBox : public Widget, public Container<EventBox>, public Handler<EventBox>
{
public:
EventBox();
EventBox(Widget& w);
void VisibleWindow(bool visible);
bool VisibleWindow();
void AboveChild(bool above);
bool AboveChild();
};
}
Loading

0 comments on commit d43682a

Please sign in to comment.