Removed some manual management.
Apparently, the layout engine is written in something resembling either Java or Google's G+. It's "C++", but there's no exceptions, manual memory management, etc. But it's also attempting to recreate a subset of the Java Collections framework in C++. It's a common pattern in both beginner and older C++. I'll completely replace all of this with standard C++ library types.
This commit is contained in:
32
dw/layout.cc
32
dw/layout.cc
@ -287,9 +287,6 @@ Layout::Layout (Platform *platform, bool limit)
|
|||||||
scrollIdleId = -1;
|
scrollIdleId = -1;
|
||||||
scrollIdleNotInterrupted = false;
|
scrollIdleNotInterrupted = false;
|
||||||
|
|
||||||
anchorsTable =
|
|
||||||
new container::typed::HashTable <object::String, Anchor> (true, true);
|
|
||||||
|
|
||||||
resizeIdleId = -1;
|
resizeIdleId = -1;
|
||||||
|
|
||||||
textZone = new misc::ZoneAllocator (16 * 1024);
|
textZone = new misc::ZoneAllocator (16 * 1024);
|
||||||
@ -339,7 +336,6 @@ Layout::~Layout ()
|
|||||||
delete queueResizeList;
|
delete queueResizeList;
|
||||||
delete platform;
|
delete platform;
|
||||||
delete view;
|
delete view;
|
||||||
delete anchorsTable;
|
|
||||||
delete textZone;
|
delete textZone;
|
||||||
|
|
||||||
if (requestedAnchor)
|
if (requestedAnchor)
|
||||||
@ -755,26 +751,24 @@ char *Layout::addAnchor (Widget *widget, const char* name)
|
|||||||
|
|
||||||
char *Layout::addAnchor (Widget *widget, const char* name, int y)
|
char *Layout::addAnchor (Widget *widget, const char* name, int y)
|
||||||
{
|
{
|
||||||
String key (name);
|
if (anchorsTable.contains (name))
|
||||||
if (anchorsTable->contains (&key))
|
|
||||||
return NULL;
|
return NULL;
|
||||||
else {
|
else {
|
||||||
Anchor *anchor = new Anchor ();
|
auto anchor = std::make_unique< Anchor >();
|
||||||
anchor->name = dStrdup (name);
|
char *const rv= anchor->name = dStrdup (name);
|
||||||
anchor->widget = widget;
|
anchor->widget = widget;
|
||||||
anchor->y = y;
|
anchor->y = y;
|
||||||
|
|
||||||
anchorsTable->put (new String (name), anchor);
|
anchorsTable[ name ]= std::move( anchor );
|
||||||
updateAnchor ();
|
updateAnchor ();
|
||||||
|
|
||||||
return anchor->name;
|
return rv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layout::changeAnchor (Widget *widget, char* name, int y)
|
void Layout::changeAnchor (Widget *widget, char* name, int y)
|
||||||
{
|
{
|
||||||
String key (name);
|
Anchor *const anchor = anchorsTable.at( name ).get();
|
||||||
Anchor *anchor = anchorsTable->get (&key);
|
|
||||||
assert (anchor);
|
assert (anchor);
|
||||||
assert (anchor->widget == widget);
|
assert (anchor->widget == widget);
|
||||||
anchor->y = y;
|
anchor->y = y;
|
||||||
@ -783,18 +777,16 @@ void Layout::changeAnchor (Widget *widget, char* name, int y)
|
|||||||
|
|
||||||
void Layout::removeAnchor (Widget *widget, char* name)
|
void Layout::removeAnchor (Widget *widget, char* name)
|
||||||
{
|
{
|
||||||
String key (name);
|
anchorsTable.erase( name );
|
||||||
anchorsTable->remove (&key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layout::updateAnchor ()
|
void Layout::updateAnchor ()
|
||||||
{
|
{
|
||||||
Anchor *anchor;
|
Anchor *anchor= nullptr;
|
||||||
if (requestedAnchor) {
|
if (requestedAnchor and anchorsTable.contains( requestedAnchor ) )
|
||||||
String key (requestedAnchor);
|
{
|
||||||
anchor = anchorsTable->get (&key);
|
anchor= anchorsTable[ requestedAnchor ].get();
|
||||||
} else
|
}
|
||||||
anchor = NULL;
|
|
||||||
|
|
||||||
if (anchor == NULL) {
|
if (anchor == NULL) {
|
||||||
/** \todo Copy comment from old docs. */
|
/** \todo Copy comment from old docs. */
|
||||||
|
@ -5,6 +5,10 @@
|
|||||||
# error Do not include this file directly, use "core.hh" instead.
|
# error Do not include this file directly, use "core.hh" instead.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace dw {
|
namespace dw {
|
||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
@ -181,8 +185,9 @@ private:
|
|||||||
bool scrollIdleNotInterrupted;
|
bool scrollIdleNotInterrupted;
|
||||||
|
|
||||||
/* Anchors of the widget tree */
|
/* Anchors of the widget tree */
|
||||||
lout::container::typed::HashTable <lout::object::String, Anchor>
|
//lout::container::typed::HashTable <lout::object::String, Anchor>
|
||||||
*anchorsTable;
|
//*anchorsTable;
|
||||||
|
std::unordered_map< std::string, std::unique_ptr< Anchor > > anchorsTable;
|
||||||
|
|
||||||
SelectionState selectionState;
|
SelectionState selectionState;
|
||||||
FindtextState findtextState;
|
FindtextState findtextState;
|
||||||
|
Reference in New Issue
Block a user