diff --git a/dw/layout.cc b/dw/layout.cc index 7fe101e..82b0feb 100644 --- a/dw/layout.cc +++ b/dw/layout.cc @@ -287,9 +287,6 @@ Layout::Layout (Platform *platform, bool limit) scrollIdleId = -1; scrollIdleNotInterrupted = false; - anchorsTable = - new container::typed::HashTable (true, true); - resizeIdleId = -1; textZone = new misc::ZoneAllocator (16 * 1024); @@ -339,7 +336,6 @@ Layout::~Layout () delete queueResizeList; delete platform; delete view; - delete anchorsTable; delete textZone; if (requestedAnchor) @@ -755,26 +751,24 @@ char *Layout::addAnchor (Widget *widget, const char* name) char *Layout::addAnchor (Widget *widget, const char* name, int y) { - String key (name); - if (anchorsTable->contains (&key)) + if (anchorsTable.contains (name)) return NULL; else { - Anchor *anchor = new Anchor (); - anchor->name = dStrdup (name); + auto anchor = std::make_unique< Anchor >(); + char *const rv= anchor->name = dStrdup (name); anchor->widget = widget; anchor->y = y; - anchorsTable->put (new String (name), anchor); + anchorsTable[ name ]= std::move( anchor ); updateAnchor (); - return anchor->name; + return rv; } } void Layout::changeAnchor (Widget *widget, char* name, int y) { - String key (name); - Anchor *anchor = anchorsTable->get (&key); + Anchor *const anchor = anchorsTable.at( name ).get(); assert (anchor); assert (anchor->widget == widget); anchor->y = y; @@ -783,18 +777,16 @@ void Layout::changeAnchor (Widget *widget, char* name, int y) void Layout::removeAnchor (Widget *widget, char* name) { - String key (name); - anchorsTable->remove (&key); + anchorsTable.erase( name ); } void Layout::updateAnchor () { - Anchor *anchor; - if (requestedAnchor) { - String key (requestedAnchor); - anchor = anchorsTable->get (&key); - } else - anchor = NULL; + Anchor *anchor= nullptr; + if (requestedAnchor and anchorsTable.contains( requestedAnchor ) ) + { + anchor= anchorsTable[ requestedAnchor ].get(); + } if (anchor == NULL) { /** \todo Copy comment from old docs. */ diff --git a/dw/layout.hh b/dw/layout.hh index f6ae736..8389b3a 100644 --- a/dw/layout.hh +++ b/dw/layout.hh @@ -5,6 +5,10 @@ # error Do not include this file directly, use "core.hh" instead. #endif +#include +#include +#include + namespace dw { namespace core { @@ -181,8 +185,9 @@ private: bool scrollIdleNotInterrupted; /* Anchors of the widget tree */ - lout::container::typed::HashTable - *anchorsTable; + //lout::container::typed::HashTable + //*anchorsTable; + std::unordered_map< std::string, std::unique_ptr< Anchor > > anchorsTable; SelectionState selectionState; FindtextState findtextState;