Rework stdext classes

Implement new classes:
* stdext::any => ligher replacement for boost::any
* stdext::packed_any => like any but optimized to use less memory
* stdext::shared_object => ligher replacement for std::shared_ptr
* stdext::shared_object_ptr => replacement for boost::intrusive_ptr
* stdext::fast_storage => for storing dynamic data
* stdext::packed_storage => same but with less memory
* stdext::packed_vector => std::vector with less memory

Compiling should be a little faster now because global boost including
is not needed anymore
This commit is contained in:
Eduardo Bart
2012-08-01 04:49:09 -03:00
parent 1dc7dc0cfc
commit 3bac3dcbb4
92 changed files with 1885 additions and 1208 deletions

View File

@@ -36,15 +36,15 @@ class UIGridLayout;
class UIAnchorLayout;
class UIParticles;
typedef boost::intrusive_ptr<UIWidget> UIWidgetPtr;
typedef boost::intrusive_ptr<UIParticles> UIParticlesPtr;
typedef boost::intrusive_ptr<UITextEdit> UITextEditPtr;
typedef boost::intrusive_ptr<UILayout> UILayoutPtr;
typedef boost::intrusive_ptr<UIBoxLayout> UIBoxLayoutPtr;
typedef boost::intrusive_ptr<UIHorizontalLayout> UIHorizontalLayoutPtr;
typedef boost::intrusive_ptr<UIVerticalLayout> UIVerticalLayoutPtr;
typedef boost::intrusive_ptr<UIGridLayout> UIGridLayoutPtr;
typedef boost::intrusive_ptr<UIAnchorLayout> UIAnchorLayoutPtr;
typedef stdext::shared_object_ptr<UIWidget> UIWidgetPtr;
typedef stdext::shared_object_ptr<UIParticles> UIParticlesPtr;
typedef stdext::shared_object_ptr<UITextEdit> UITextEditPtr;
typedef stdext::shared_object_ptr<UILayout> UILayoutPtr;
typedef stdext::shared_object_ptr<UIBoxLayout> UIBoxLayoutPtr;
typedef stdext::shared_object_ptr<UIHorizontalLayout> UIHorizontalLayoutPtr;
typedef stdext::shared_object_ptr<UIVerticalLayout> UIVerticalLayoutPtr;
typedef stdext::shared_object_ptr<UIGridLayout> UIGridLayoutPtr;
typedef stdext::shared_object_ptr<UIAnchorLayout> UIAnchorLayoutPtr;
typedef std::deque<UIWidgetPtr> UIWidgetList;

View File

@@ -63,7 +63,7 @@ void UILayout::updateLater()
if(!getParentWidget())
return;
auto self = self_cast<UILayout>();
auto self = static_self_cast<UILayout>();
g_dispatcher.addEvent([self] {
self->m_updateScheduled = false;
self->update();

View File

@@ -321,8 +321,7 @@ bool UIManager::importStyle(const std::string& file)
void UIManager::importStyleFromOTML(const OTMLNodePtr& styleNode)
{
std::string tag = styleNode->tag();
std::vector<std::string> split;
boost::split(split, tag, boost::is_any_of(std::string("<")));
std::vector<std::string> split = stdext::split(tag, "<");
if(split.size() != 2)
throw OTMLException(styleNode, "not a valid style declaration");
@@ -330,8 +329,8 @@ void UIManager::importStyleFromOTML(const OTMLNodePtr& styleNode)
std::string base = split[1];
bool unique = false;
boost::trim(name);
boost::trim(base);
stdext::trim(name);
stdext::trim(base);
if(name[0] == '#') {
name = name.substr(1);
@@ -367,7 +366,7 @@ OTMLNodePtr UIManager::getStyle(const std::string& styleName)
return m_styles[styleName];
// styles starting with UI are automatically defined
if(boost::starts_with(styleName, "UI")) {
if(stdext::starts_with(styleName, "UI")) {
OTMLNodePtr node = OTMLNode::create(styleName);
node->writeAt("__class", styleName);
m_styles[styleName] = node;

View File

@@ -278,8 +278,8 @@ void UITextEdit::appendText(std::string text)
if(m_cursorPos >= 0) {
// replace characters that are now allowed
if(!m_multiline)
boost::replace_all(text, "\n", "");
boost::replace_all(text, "\r", " ");
stdext::replace_all(text, "\n", "");
stdext::replace_all(text, "\r", " ");
if(text.length() > 0) {
// only add text if textedit can add it

View File

@@ -21,6 +21,7 @@
*/
#include "uitranslator.h"
#include <framework/stdext/string.h>
#include <boost/algorithm/string.hpp>
Fw::AlignmentFlag Fw::translateAlignment(std::string aligment)

View File

@@ -141,11 +141,11 @@ void UIWidget::addChild(const UIWidgetPtr& child)
UIWidgetPtr oldLastChild = getLastChild();
m_children.push_back(child);
child->setParent(self_cast<UIWidget>());
child->setParent(static_self_cast<UIWidget>());
// create default layout
if(!m_layout)
m_layout = UIAnchorLayoutPtr(new UIAnchorLayout(self_cast<UIWidget>()));
m_layout = UIAnchorLayoutPtr(new UIAnchorLayout(static_self_cast<UIWidget>()));
// add to layout and updates it
m_layout->addWidget(child);
@@ -184,11 +184,11 @@ void UIWidget::insertChild(int index, const UIWidgetPtr& child)
// retrieve child by index
auto it = m_children.begin() + index;
m_children.insert(it, child);
child->setParent(self_cast<UIWidget>());
child->setParent(static_self_cast<UIWidget>());
// create default layout if needed
if(!m_layout)
m_layout = UIAnchorLayoutPtr(new UIAnchorLayout(self_cast<UIWidget>()));
m_layout = UIAnchorLayoutPtr(new UIAnchorLayout(static_self_cast<UIWidget>()));
// add to layout and updates it
m_layout->addWidget(child);
@@ -218,7 +218,7 @@ void UIWidget::removeChild(UIWidgetPtr child)
m_children.erase(it);
// reset child parent
assert(child->getParent() == self_cast<UIWidget>());
assert(child->getParent() == static_self_cast<UIWidget>());
child->setParent(nullptr);
m_layout->removeWidget(child);
@@ -504,7 +504,7 @@ void UIWidget::applyStyle(const OTMLNodePtr& styleNode)
callLuaField("onStyleApply", styleNode->tag(), styleNode);
if(m_firstOnStyle) {
auto self = self_cast<UIWidget>();
auto self = static_self_cast<UIWidget>();
g_dispatcher.addEvent([self] {
self->callLuaField("onSetup");
});
@@ -525,7 +525,7 @@ void UIWidget::addAnchor(Fw::AnchorEdge anchoredEdge, const std::string& hookedW
return;
if(UIAnchorLayoutPtr anchorLayout = getAnchoredLayout())
anchorLayout->addAnchor(self_cast<UIWidget>(), anchoredEdge, hookedWidgetId, hookedEdge);
anchorLayout->addAnchor(static_self_cast<UIWidget>(), anchoredEdge, hookedWidgetId, hookedEdge);
else
g_logger.error(stdext::format("cannot add anchors to widget '%s': the parent doesn't use anchors layout", m_id));
}
@@ -541,8 +541,8 @@ void UIWidget::centerIn(const std::string& hookedWidgetId)
return;
if(UIAnchorLayoutPtr anchorLayout = getAnchoredLayout()) {
anchorLayout->addAnchor(self_cast<UIWidget>(), Fw::AnchorHorizontalCenter, hookedWidgetId, Fw::AnchorHorizontalCenter);
anchorLayout->addAnchor(self_cast<UIWidget>(), Fw::AnchorVerticalCenter, hookedWidgetId, Fw::AnchorVerticalCenter);
anchorLayout->addAnchor(static_self_cast<UIWidget>(), Fw::AnchorHorizontalCenter, hookedWidgetId, Fw::AnchorHorizontalCenter);
anchorLayout->addAnchor(static_self_cast<UIWidget>(), Fw::AnchorVerticalCenter, hookedWidgetId, Fw::AnchorVerticalCenter);
} else
g_logger.error(stdext::format("cannot add anchors to widget '%s': the parent doesn't use anchors layout", m_id));
}
@@ -553,10 +553,10 @@ void UIWidget::fill(const std::string& hookedWidgetId)
return;
if(UIAnchorLayoutPtr anchorLayout = getAnchoredLayout()) {
anchorLayout->addAnchor(self_cast<UIWidget>(), Fw::AnchorLeft, hookedWidgetId, Fw::AnchorLeft);
anchorLayout->addAnchor(self_cast<UIWidget>(), Fw::AnchorRight, hookedWidgetId, Fw::AnchorRight);
anchorLayout->addAnchor(self_cast<UIWidget>(), Fw::AnchorTop, hookedWidgetId, Fw::AnchorTop);
anchorLayout->addAnchor(self_cast<UIWidget>(), Fw::AnchorBottom, hookedWidgetId, Fw::AnchorBottom);
anchorLayout->addAnchor(static_self_cast<UIWidget>(), Fw::AnchorLeft, hookedWidgetId, Fw::AnchorLeft);
anchorLayout->addAnchor(static_self_cast<UIWidget>(), Fw::AnchorRight, hookedWidgetId, Fw::AnchorRight);
anchorLayout->addAnchor(static_self_cast<UIWidget>(), Fw::AnchorTop, hookedWidgetId, Fw::AnchorTop);
anchorLayout->addAnchor(static_self_cast<UIWidget>(), Fw::AnchorBottom, hookedWidgetId, Fw::AnchorBottom);
} else
g_logger.error(stdext::format("cannot add anchors to widget '%s': the parent doesn't use anchors layout", m_id));
}
@@ -567,7 +567,7 @@ void UIWidget::breakAnchors()
return;
if(UIAnchorLayoutPtr anchorLayout = getAnchoredLayout())
anchorLayout->removeAnchors(self_cast<UIWidget>());
anchorLayout->removeAnchors(static_self_cast<UIWidget>());
}
void UIWidget::updateParentLayout()
@@ -601,7 +601,7 @@ void UIWidget::lock()
return;
if(UIWidgetPtr parent = getParent())
parent->lockChild(self_cast<UIWidget>());
parent->lockChild(static_self_cast<UIWidget>());
}
void UIWidget::unlock()
@@ -610,7 +610,7 @@ void UIWidget::unlock()
return;
if(UIWidgetPtr parent = getParent())
parent->unlockChild(self_cast<UIWidget>());
parent->unlockChild(static_self_cast<UIWidget>());
}
void UIWidget::focus()
@@ -622,7 +622,7 @@ void UIWidget::focus()
return;
if(UIWidgetPtr parent = getParent())
parent->focusChild(self_cast<UIWidget>(), Fw::ActiveFocusReason);
parent->focusChild(static_self_cast<UIWidget>(), Fw::ActiveFocusReason);
}
void UIWidget::recursiveFocus(Fw::FocusReason reason)
@@ -632,7 +632,7 @@ void UIWidget::recursiveFocus(Fw::FocusReason reason)
if(UIWidgetPtr parent = getParent()) {
if(m_focusable)
parent->focusChild(self_cast<UIWidget>(), reason);
parent->focusChild(static_self_cast<UIWidget>(), reason);
parent->recursiveFocus(reason);
}
}
@@ -644,7 +644,7 @@ void UIWidget::lower()
UIWidgetPtr parent = getParent();
if(parent)
parent->lowerChild(self_cast<UIWidget>());
parent->lowerChild(static_self_cast<UIWidget>());
}
void UIWidget::raise()
@@ -654,7 +654,7 @@ void UIWidget::raise()
UIWidgetPtr parent = getParent();
if(parent)
parent->raiseChild(self_cast<UIWidget>());
parent->raiseChild(static_self_cast<UIWidget>());
}
void UIWidget::grabMouse()
@@ -662,12 +662,12 @@ void UIWidget::grabMouse()
if(m_destroyed)
return;
g_ui.setMouseReceiver(self_cast<UIWidget>());
g_ui.setMouseReceiver(static_self_cast<UIWidget>());
}
void UIWidget::ungrabMouse()
{
if(g_ui.getMouseReceiver() == self_cast<UIWidget>())
if(g_ui.getMouseReceiver() == static_self_cast<UIWidget>())
g_ui.resetMouseReceiver();
}
@@ -676,12 +676,12 @@ void UIWidget::grabKeyboard()
if(m_destroyed)
return;
g_ui.setKeyboardReceiver(self_cast<UIWidget>());
g_ui.setKeyboardReceiver(static_self_cast<UIWidget>());
}
void UIWidget::ungrabKeyboard()
{
if(g_ui.getKeyboardReceiver() == self_cast<UIWidget>())
if(g_ui.getKeyboardReceiver() == static_self_cast<UIWidget>())
g_ui.resetKeyboardReceiver();
}
@@ -721,7 +721,7 @@ void UIWidget::internalDestroy()
releaseLuaFieldsTable();
g_ui.onWidgetDestroy(self_cast<UIWidget>());
g_ui.onWidgetDestroy(static_self_cast<UIWidget>());
}
void UIWidget::destroy()
@@ -730,7 +730,7 @@ void UIWidget::destroy()
g_logger.warning(stdext::format("attempt to destroy widget '%s' two times", m_id));
// hold itself reference
UIWidgetPtr self = self_cast<UIWidget>();
UIWidgetPtr self = static_self_cast<UIWidget>();
m_destroyed = true;
// remove itself from parent
@@ -775,7 +775,7 @@ void UIWidget::setParent(const UIWidgetPtr& parent)
if(oldParent == parent)
return;
UIWidgetPtr self = self_cast<UIWidget>();
UIWidgetPtr self = static_self_cast<UIWidget>();
if(oldParent && oldParent->hasChild(self))
oldParent->removeChild(self);
@@ -797,7 +797,7 @@ void UIWidget::setLayout(const UILayoutPtr& layout)
if(m_layout)
m_layout->disableUpdates();
layout->setParent(self_cast<UIWidget>());
layout->setParent(static_self_cast<UIWidget>());
layout->disableUpdates();
for(const UIWidgetPtr& child : m_children) {
@@ -836,7 +836,7 @@ bool UIWidget::setRect(const Rect& rect)
// avoid massive update events
if(!m_updateEventScheduled) {
UIWidgetPtr self = self_cast<UIWidget>();
UIWidgetPtr self = static_self_cast<UIWidget>();
g_dispatcher.addEvent([self, oldRect]() {
self->m_updateEventScheduled = false;
if(oldRect != self->getRect())
@@ -896,9 +896,9 @@ void UIWidget::setVisible(bool visible)
// visibility can change the current hovered widget
if(visible)
g_ui.onWidgetAppear(self_cast<UIWidget>());
g_ui.onWidgetAppear(static_self_cast<UIWidget>());
else
g_ui.onWidgetDisappear(self_cast<UIWidget>());
g_ui.onWidgetDisappear(static_self_cast<UIWidget>());
callLuaField("onVisibilityChange", visible);
}
@@ -963,14 +963,14 @@ bool UIWidget::isVisible()
else if(UIWidgetPtr parent = getParent())
return parent->isVisible();
else
return self_cast<UIWidget>() == g_ui.getRootWidget();
return static_self_cast<UIWidget>() == g_ui.getRootWidget();
}
bool UIWidget::isAnchored()
{
if(UIWidgetPtr parent = getParent())
if(UIAnchorLayoutPtr anchorLayout = parent->getAnchoredLayout())
return anchorLayout->hasAnchors(self_cast<UIWidget>());
return anchorLayout->hasAnchors(static_self_cast<UIWidget>());
return false;
}
@@ -1046,7 +1046,7 @@ UIAnchorLayoutPtr UIWidget::getAnchoredLayout()
UILayoutPtr layout = parent->getLayout();
if(layout->isUIAnchorLayout())
return layout->self_cast<UIAnchorLayout>();
return layout->static_self_cast<UIAnchorLayout>();
return nullptr;
}
@@ -1055,7 +1055,7 @@ UIWidgetPtr UIWidget::getRootParent()
if(UIWidgetPtr parent = getParent())
return parent->getRootParent();
else
return self_cast<UIWidget>();
return static_self_cast<UIWidget>();
}
UIWidgetPtr UIWidget::getChildAfter(const UIWidgetPtr& relativeChild)
@@ -1231,7 +1231,7 @@ void UIWidget::updateState(Fw::WidgetState state)
switch(state) {
case Fw::ActiveState: {
UIWidgetPtr widget = self_cast<UIWidget>();
UIWidgetPtr widget = static_self_cast<UIWidget>();
UIWidgetPtr parent;
do {
parent = widget->getParent();
@@ -1246,24 +1246,24 @@ void UIWidget::updateState(Fw::WidgetState state)
break;
}
case Fw::FocusState: {
newStatus = (getParent() && getParent()->getFocusedChild() == self_cast<UIWidget>());
newStatus = (getParent() && getParent()->getFocusedChild() == static_self_cast<UIWidget>());
break;
}
case Fw::HoverState: {
newStatus = (g_ui.getHoveredWidget() == self_cast<UIWidget>() && isEnabled());
newStatus = (g_ui.getHoveredWidget() == static_self_cast<UIWidget>() && isEnabled());
break;
}
case Fw::PressedState: {
newStatus = (g_ui.getPressedWidget() == self_cast<UIWidget>());
newStatus = (g_ui.getPressedWidget() == static_self_cast<UIWidget>());
break;
}
case Fw::DraggingState: {
newStatus = (g_ui.getDraggingWidget() == self_cast<UIWidget>());
newStatus = (g_ui.getDraggingWidget() == static_self_cast<UIWidget>());
break;
}
case Fw::DisabledState: {
bool enabled = true;
UIWidgetPtr widget = self_cast<UIWidget>();
UIWidgetPtr widget = static_self_cast<UIWidget>();
do {
if(!widget->isExplicitlyEnabled()) {
enabled = false;
@@ -1275,19 +1275,19 @@ void UIWidget::updateState(Fw::WidgetState state)
break;
}
case Fw::FirstState: {
newStatus = (getParent() && getParent()->getFirstChild() == self_cast<UIWidget>());
newStatus = (getParent() && getParent()->getFirstChild() == static_self_cast<UIWidget>());
break;
}
case Fw::MiddleState: {
newStatus = (getParent() && getParent()->getFirstChild() != self_cast<UIWidget>() && getParent()->getLastChild() != self_cast<UIWidget>());
newStatus = (getParent() && getParent()->getFirstChild() != static_self_cast<UIWidget>() && getParent()->getLastChild() != static_self_cast<UIWidget>());
break;
}
case Fw::LastState: {
newStatus = (getParent() && getParent()->getLastChild() == self_cast<UIWidget>());
newStatus = (getParent() && getParent()->getLastChild() == static_self_cast<UIWidget>());
break;
}
case Fw::AlternateState: {
newStatus = (getParent() && (getParent()->getChildIndex(self_cast<UIWidget>()) % 2) == 1);
newStatus = (getParent() && (getParent()->getChildIndex(static_self_cast<UIWidget>()) % 2) == 1);
break;
}
default:
@@ -1337,7 +1337,7 @@ void UIWidget::updateStyle()
return;
if(m_loadingStyle && !m_updateStyleScheduled) {
UIWidgetPtr self = self_cast<UIWidget>();
UIWidgetPtr self = static_self_cast<UIWidget>();
g_dispatcher.addEvent([self] {
self->m_updateStyleScheduled = false;
self->updateStyle();
@@ -1361,10 +1361,9 @@ void UIWidget::updateStyle()
// checks for states combination
for(const OTMLNodePtr& style : m_style->children()) {
if(boost::starts_with(style->tag(), "$")) {
if(stdext::starts_with(style->tag(), "$")) {
std::string statesStr = style->tag().substr(1);
std::vector<std::string> statesSplit;
boost::split(statesSplit, statesStr, boost::is_any_of(std::string(" ")));
std::vector<std::string> statesSplit = stdext::split(statesStr, " ");
bool match = true;
for(std::string stateStr : statesSplit) {
@@ -1642,7 +1641,7 @@ bool UIWidget::propagateOnMouseEvent(const Point& mousePos, UIWidgetList& widget
}
}
widgetList.push_back(self_cast<UIWidget>());
widgetList.push_back(static_self_cast<UIWidget>());
if(!isPhantom())
ret = true;
@@ -1657,6 +1656,6 @@ bool UIWidget::propagateOnMouseMove(const Point& mousePos, const Point& mouseMov
child->propagateOnMouseMove(mousePos, mouseMoved, widgetList);
}
widgetList.push_back(self_cast<UIWidget>());
widgetList.push_back(static_self_cast<UIWidget>());
return true;
}

View File

@@ -162,8 +162,7 @@ void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
setMarginLeft(node->value<int>());
else if(node->tag() == "margin") {
std::string marginDesc = node->value();
std::vector<std::string> split;
boost::split(split, marginDesc, boost::is_any_of(std::string(" ")));
std::vector<std::string> split = stdext::split(marginDesc, " ");
if(split.size() == 4) {
setMarginTop(stdext::safe_cast<int>(split[0]));
setMarginRight(stdext::safe_cast<int>(split[1]));
@@ -202,8 +201,7 @@ void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
setPaddingLeft(node->value<int>());
else if(node->tag() == "padding") {
std::string paddingDesc = node->value();
std::vector<std::string> split;
boost::split(split, paddingDesc, boost::is_any_of(std::string(" ")));
std::vector<std::string> split = stdext::split(paddingDesc, " ");
if(split.size() == 4) {
setPaddingTop(stdext::safe_cast<int>(split[0]));
setPaddingRight(stdext::safe_cast<int>(split[1]));
@@ -243,13 +241,13 @@ void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
if(!layoutType.empty()) {
UILayoutPtr layout;
if(layoutType == "horizontalBox")
layout = UIHorizontalLayoutPtr(new UIHorizontalLayout(self_cast<UIWidget>()));
layout = UIHorizontalLayoutPtr(new UIHorizontalLayout(static_self_cast<UIWidget>()));
else if(layoutType == "verticalBox")
layout = UIVerticalLayoutPtr(new UIVerticalLayout(self_cast<UIWidget>()));
layout = UIVerticalLayoutPtr(new UIVerticalLayout(static_self_cast<UIWidget>()));
else if(layoutType == "grid")
layout = UIGridLayoutPtr(new UIGridLayout(self_cast<UIWidget>()));
layout = UIGridLayoutPtr(new UIGridLayout(static_self_cast<UIWidget>()));
else if(layoutType == "anchor")
layout = UIAnchorLayoutPtr(new UIAnchorLayout(self_cast<UIWidget>()));
layout = UIAnchorLayoutPtr(new UIAnchorLayout(static_self_cast<UIWidget>()));
else
throw OTMLException(node, "cannot determine layout type");
setLayout(layout);
@@ -259,7 +257,7 @@ void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
m_layout->applyStyle(node);
}
// anchors
else if(boost::starts_with(node->tag(), "anchors.")) {
else if(stdext::starts_with(node->tag(), "anchors.")) {
UIWidgetPtr parent = getParent();
if(!parent) {
if(m_firstOnStyle)
@@ -271,7 +269,7 @@ void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
UILayoutPtr layout = parent->getLayout();
UIAnchorLayoutPtr anchorLayout;
if(layout->isUIAnchorLayout())
anchorLayout = layout->self_cast<UIAnchorLayout>();
anchorLayout = layout->static_self_cast<UIAnchorLayout>();
if(!anchorLayout)
throw OTMLException(node, "cannot create anchor, the parent widget doesn't use anchor layout!");
@@ -304,7 +302,7 @@ void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
}
}
// lua functions
} else if(boost::starts_with(node->tag(), "@")) {
} else if(stdext::starts_with(node->tag(), "@")) {
// load once
if(m_firstOnStyle) {
std::string funcName = node->tag().substr(1);
@@ -313,7 +311,7 @@ void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
luaSetField(funcName);
}
// lua fields value
} else if(boost::starts_with(node->tag(), "&")) {
} else if(stdext::starts_with(node->tag(), "&")) {
std::string fieldName = node->tag().substr(1);
std::string fieldOrigin = "@" + node->source() + "[" + node->tag() + "]";