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;
|
||||
scrollIdleNotInterrupted = false;
|
||||
|
||||
anchorsTable =
|
||||
new container::typed::HashTable <object::String, Anchor> (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. */
|
||||
|
@ -5,6 +5,10 @@
|
||||
# error Do not include this file directly, use "core.hh" instead.
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace dw {
|
||||
namespace core {
|
||||
|
||||
@ -181,8 +185,9 @@ private:
|
||||
bool scrollIdleNotInterrupted;
|
||||
|
||||
/* Anchors of the widget tree */
|
||||
lout::container::typed::HashTable <lout::object::String, Anchor>
|
||||
*anchorsTable;
|
||||
//lout::container::typed::HashTable <lout::object::String, Anchor>
|
||||
//*anchorsTable;
|
||||
std::unordered_map< std::string, std::unique_ptr< Anchor > > anchorsTable;
|
||||
|
||||
SelectionState selectionState;
|
||||
FindtextState findtextState;
|
||||
|
Reference in New Issue
Block a user