IMediaAlbumSRef getAlbum();
private:
- friend class ucl::RefCountObj<Gallery>;
+ friend class ucl::ReffedObj<Gallery>;
Gallery();
ucl::Result prepare();
ucl::Result saveToDevice();
protected:
- friend class ucl::RefCountObj<MediaItem>;
+ friend class ucl::ReffedObj<MediaItem>;
MediaItem(int flags, MediaType type);
ucl::Result prepare(media_info_h media);
void delMediaVolumeChangeHandler(const NotiHandler &handler);
private:
- friend class ucl::RefCountObj<SoundManager>;
+ friend class ucl::ReffedObj<SoundManager>;
SoundManager();
~SoundManager();
virtual bool isDisposed() const final override;
private:
- friend class ucl::RefCountObj<AlertDialog>;
- AlertDialog(ucl::RefCountObjBase &rc,
+ friend class ucl::ReffedObj<AlertDialog>;
+ AlertDialog(ucl::IRefCountObj &rc,
const EventHandler &handler);
virtual ~AlertDialog();
void registerWidget(ucl::ElmWidget &widget);
private:
- friend class ucl::RefCountObj<AtspiHighlightHelper>;
- AtspiHighlightHelper(ucl::RefCountObjBase &rc);
+ friend class ucl::ReffedObj<AtspiHighlightHelper>;
+ AtspiHighlightHelper(ucl::IRefCountObj &rc);
virtual ~AtspiHighlightHelper();
ucl::Result prepare(ucl::ElmWidget &rootWidget);
public ucl::IInstance,
public ucl::IInstanceAppControlExt {
public:
- Instance(ucl::RefCountObjBase &rc,
+ Instance(ucl::IRefCountObj &rc,
ucl::SysEventProvider &sysEventProvider);
virtual ~Instance();
using MoreOptionsCSRef = ucl::SharedRef<const MoreOptions>;
private:
- friend class ucl::RefCountObj<MoreOptionsPresenter>;
- MoreOptionsPresenter(ucl::RefCountObjBase &rc,
+ friend class ucl::ReffedObj<MoreOptionsPresenter>;
+ MoreOptionsPresenter(ucl::IRefCountObj &rc,
const MoreOptionsCSRef &options);
virtual ~MoreOptionsPresenter();
};
private:
- friend class ucl::RefCountObj<NoContentPage>;
- NoContentPage(ucl::RefCountObjBase &rc, const ucl::NaviframeSRef &navi,
+ friend class ucl::ReffedObj<NoContentPage>;
+ NoContentPage(ucl::IRefCountObj &rc, const ucl::NaviframeSRef &navi,
const ExitRequestHandler &onExitRequest);
virtual ~NoContentPage();
ucl::NaviItem insertBefore(ARGS &&...args);
protected:
- Page(ucl::RefCountObjBase &rc, const ucl::NaviframeSRef &navi,
+ Page(ucl::IRefCountObj &rc, const ucl::NaviframeSRef &navi,
const ExitRequestHandler &onExitRequest);
virtual ~Page();
void deactivateBy(void *deactivator);
protected:
- Presenter(ucl::RefCountObjBase &rc);
+ Presenter(ucl::IRefCountObj &rc);
virtual ~Presenter();
ucl::Result prepare(ucl::ElmWidget &widget);
int getCurrentItemIndex() const;
private:
- friend class ucl::RefCountObj<PreviewPage>;
- PreviewPage(ucl::RefCountObjBase &rc, const ucl::NaviframeSRef &navi,
+ friend class ucl::ReffedObj<PreviewPage>;
+ PreviewPage(ucl::IRefCountObj &rc, const ucl::NaviframeSRef &navi,
const ExitRequestHandler &onExitRequest,
const IMediaAlbumSRef &album, bool selectModeStartup);
virtual ~PreviewPage();
void setDismissHandler(const DismissHandler &handler);
private:
- friend class ucl::RefCountObj<ProcessingPresenter>;
- ProcessingPresenter(ucl::RefCountObjBase &rc);
+ friend class ucl::ReffedObj<ProcessingPresenter>;
+ ProcessingPresenter(ucl::IRefCountObj &rc);
virtual ~ProcessingPresenter();
ucl::Result prepare(ucl::ElmWidget &parent,
void update(int selectCount, int totalCount = -1);
private:
- friend class ucl::RefCountObj<SelectModePresenter>;
- SelectModePresenter(ucl::RefCountObjBase &rc,
+ friend class ucl::ReffedObj<SelectModePresenter>;
+ SelectModePresenter(ucl::IRefCountObj &rc,
PageContent &content, int flags);
virtual ~SelectModePresenter();
};
private:
- friend class ucl::RefCountObj<ThumbnailPage>;
- ThumbnailPage(ucl::RefCountObjBase &rc, const ucl::NaviframeSRef &navi,
+ friend class ucl::ReffedObj<ThumbnailPage>;
+ ThumbnailPage(ucl::IRefCountObj &rc, const ucl::NaviframeSRef &navi,
const ExitRequestHandler &onExitRequest,
const IMediaAlbumSRef &album);
virtual ~ThumbnailPage();
};
private:
- friend class ucl::RefCountObj<VideoPlayerPage>;
- VideoPlayerPage(ucl::RefCountObjBase &rc,
+ friend class ucl::ReffedObj<VideoPlayerPage>;
+ VideoPlayerPage(ucl::IRefCountObj &rc,
const ucl::NaviframeSRef &navi,
const ExitRequestHandler &onExitRequest,
const MediaItemSRef &media);
const std::string &getMediaId() const;
private:
- friend class ucl::RefCountObj<ViewerPage>;
- ViewerPage(ucl::RefCountObjBase &rc, const ucl::NaviframeSRef &navi,
+ friend class ucl::ReffedObj<ViewerPage>;
+ ViewerPage(ucl::IRefCountObj &rc, const ucl::NaviframeSRef &navi,
const ExitRequestHandler &onExitRequest,
const MediaItemSRef &media, bool exitOnZoomOut);
virtual ~ViewerPage();
struct LinearInfo;
private:
- friend class ucl::RefCountObj<ImageGrid>;
- ImageGrid(ucl::RefCountObjBase *rc, Evas_Object *scroller,
+ friend class ucl::ReffedObj<ImageGrid>;
+ ImageGrid(ucl::IRefCountObj *rc, Evas_Object *scroller,
Type type, bool selectModeStartup);
virtual ~ImageGrid();
private:
const Info &m_info;
- ucl::StyledWidgetWRef m_scroller;
+ ucl::StyledWidget *m_scroller;
ucl::ElmWidget m_box;
ucl::Widget m_rect1;
ucl::Widget m_rect2;
bool isZoomedOut() const;
private:
- friend class ucl::RefCountObj<ImageViewer>;
- ImageViewer(ucl::RefCountObjBase &rc, Evas_Object *scroller,
+ friend class ucl::ReffedObj<ImageViewer>;
+ ImageViewer(ucl::IRefCountObj &rc, Evas_Object *scroller,
const std::string &highResPath, int loadSize, bool forceLoad);
virtual ~ImageViewer();
};
private:
- ucl::StyledWidgetWRef m_scroller;
+ ucl::StyledWidget *m_scroller;
ucl::Layout m_layout;
ucl::Widget m_grid;
ucl::Widget m_lowResImage;
ucl::Result setMoreOptionsVisible(bool visible);
private:
- friend class ucl::RefCountObj<PageContent>;
- PageContent(ucl::RefCountObjBase &rc,
+ friend class ucl::ReffedObj<PageContent>;
+ PageContent(ucl::IRefCountObj &rc,
const ucl::LayoutSRef &layout, int flags);
virtual ~PageContent();
ucl::Layout *getTopLayout() const;
private:
- ucl::LayoutWRef m_moreOptions;
+ ucl::Layout *m_mainLayout;
ucl::LayoutSRef m_selectMode;
ucl::LayoutSRef m_bottomButton;
};
using TapHandler = ucl::WeakDelegate<void(int x, int y)>;
private:
- friend class ucl::RefCountObj<TouchParser>;
- TouchParser(ucl::RefCountObjBase &rc, ucl::Widget &eventSource);
+ friend class ucl::ReffedObj<TouchParser>;
+ TouchParser(ucl::IRefCountObj &rc, ucl::Widget &eventSource);
virtual ~TouchParser();
public:
using ucl::isNotEmpty;
using ucl::toEina;
- using ucl::RefCountObj;
- using ucl::RefCountObjBase;
+ using ucl::ReffedObj;
+ using ucl::IRefCountObj;
using ucl::SharedRef;
using ucl::WeakRef;
virtual void defragment() final override;
private:
- friend class ucl::RefCountObj<GalleryAlbum>;
+ friend class ucl::ReffedObj<GalleryAlbum>;
GalleryAlbum();
ucl::Result prepare();
if (!(m_flags & FLAG_REMOVE)) {
LOG_RETURN(RES_NOT_SUPPORTED, "Operation not supported!");
}
- if (!ecore_file_can_write(m_filePath.c_str())) {
+
+ const bool exists = ecore_file_exists(m_filePath.c_str());
+
+ if (exists && !ecore_file_can_write(m_filePath.c_str())) {
LOG_RETURN(RES_FAIL, "File can't be removed!");
}
m_isValid = false;
}
- if (!ecore_file_remove(m_filePath.c_str())) {
+ if (exists && !ecore_file_remove(m_filePath.c_str())) {
FLOG("ecore_file_remove() failed! Attempting to rescan....");
MutexLock lock(getMediaMutex());
const int ret = media_content_scan_file(m_filePath.c_str());
// AlertDialog //
- AlertDialog::AlertDialog(RefCountObjBase &rc,
+ AlertDialog::AlertDialog(IRefCountObj &rc,
const EventHandler &handler) :
Presenter(rc),
m_handler(handler),
Result AlertDialog::createLayout(const LayoutTheme theme)
{
- m_layout = Layout::Builder().
+ const auto layout = Layout::Builder().
setTheme(theme).
build(*m_popup);
- if (!m_layout) {
+ if (!layout) {
LOG_RETURN(RES_FAIL, "Layout::build() failed!");
}
- m_popup->setContent(*m_layout);
+ m_popup->setContent(*layout);
+
+ m_layout = layout;
return RES_OK;
}
void AlertDialog::setTitle(const TString &title)
{
- if (m_layout) {
- m_layout->setText(title, PART_TITLE);
+ if (const auto layout = m_layout.lock()) {
+ layout->setText(title, PART_TITLE);
}
}
void AlertDialog::setText(const TString &text)
{
- if (m_layout) {
- m_layout->setText(text);
+ if (const auto layout = m_layout.lock()) {
+ layout->setText(text);
}
}
void AlertDialog::handleEvent(const Event event)
{
- const auto keepAliver = asShared(*this);
if (dispatchEvent(event)) {
dismiss();
}
return result;
}
- AtspiHighlightHelper::AtspiHighlightHelper(RefCountObjBase &rc) :
+ AtspiHighlightHelper::AtspiHighlightHelper(IRefCountObj &rc) :
Presenter(rc)
{
}
using ucl::Theme;
using ucl::Naviframe;
- Instance::Instance(RefCountObjBase &rc,
+ Instance::Instance(IRefCountObj &rc,
SysEventProvider &sysEventProvider) :
RefCountAware(&rc),
m_sysEventProvider(sysEventProvider),
Instance::~Instance()
{
stopMediaContentScan();
- if (m_page) {
- m_page->exitNoTransition();
+ if (const auto page = m_page.lock()) {
+ page->exitNoTransition();
}
}
{
FAIL_RETURN(ensureGalleryModel(), "ensureGalleryModel() failed!");
- if (!m_page) {
- if (isEmpty(m_gallery->getAlbum())) {
- createNoContentPage();
- } else {
- createThumbnailPage();
+ if (const auto page = m_page.lock()) {
+ if (operation == APP_CONTROL_OPERATION_MAIN) {
+ page->deleteTo();
}
- } else if (operation == APP_CONTROL_OPERATION_MAIN) {
- m_page->deleteTo();
+ } else if (isEmpty(m_gallery->getAlbum())) {
+ createNoContentPage();
+ } else {
+ createThumbnailPage();
}
return RES_OK;
void Instance::onAlbumChanged()
{
if (isEmpty(m_gallery->getAlbum())) {
- if (dynamic_cast<ThumbnailPage *>(m_page.get())) {
- m_page->exitNoTransition();
+ if (auto page = dynamicRefCast<ThumbnailPage>(m_page).lock()) {
+ page->exitNoTransition();
createNoContentPage();
}
} else {
- if (dynamic_cast<NoContentPage *>(m_page.get())) {
- m_page->exitNoTransition();
+ if (auto page = dynamicRefCast<NoContentPage>(m_page).lock()) {
+ page->exitNoTransition();
createThumbnailPage();
}
}
// MoreOptionsPresenter //
- MoreOptionsPresenter::MoreOptionsPresenter(RefCountObjBase &rc,
+ MoreOptionsPresenter::MoreOptionsPresenter(IRefCountObj &rc,
const MoreOptionsCSRef &options) :
Presenter(rc),
m_options(options),
void MoreOptionsPresenter::onOpened(Widget &widget, void *eventInfo)
{
stopTimer();
- const auto keepAliver = asShared(*this);
sendDeactivateBy(*m_widget, this);
activateBy(m_widget.get());
- if (m_listener) {
- m_listener->onMoreOptionsOpened(*this);
+ if (const auto listener = m_listener.lock()) {
+ listener->onMoreOptionsOpened(*this);
}
if (!isActive()) {
setOpened(false);
void MoreOptionsPresenter::onClosed(Widget &widget, void *eventInfo)
{
stopTimer();
- const auto keepAliver = asShared(*this);
deactivateBy(m_widget.get());
sendActivateBy(*m_widget, this);
- if (m_listener) {
- m_listener->onMoreOptionsClosed(*this);
+ if (const auto listener = m_listener.lock()) {
+ listener->onMoreOptionsClosed(*this);
}
}
void MoreOptionsPresenter::onItemClicked(Widget &widget, void *eventInfo)
{
- if (m_listener && isActive() && isOpened()) {
+ if (!isActive() || !isOpened()) {
+ return;
+ }
+ if (const auto listener = m_listener.lock()) {
const auto item = m_map.get(eventInfo);
if (item) {
- m_listener->onMoreOptionClicked(*this, *item);
+ listener->onMoreOptionClicked(*this, *item);
} else {
ELOG("Invalid eventInfo!");
}
void MoreOptionsPresenter::onItemSelected(Widget &widget, void *eventInfo)
{
- if (m_listener) {
+ if (const auto listener = m_listener.lock()) {
const auto item = m_map.get(eventInfo);
if (item) {
- m_listener->onMoreOptionSelected(*this, *item);
+ listener->onMoreOptionSelected(*this, *item);
} else {
ELOG("Invalid eventInfo!");
}
// NoContentPage //
- NoContentPage::NoContentPage(RefCountObjBase &rc,
+ NoContentPage::NoContentPage(IRefCountObj &rc,
const NaviframeSRef &navi,
const ExitRequestHandler &onExitRequest) :
Page(rc, navi, onExitRequest)
using ucl::NAVI_TRANSITION_STARTED;
using ucl::NAVI_TRANSITION_FINISHED;
- Page::Page(RefCountObjBase &rc, const NaviframeSRef &navi,
+ Page::Page(IRefCountObj &rc, const NaviframeSRef &navi,
const ExitRequestHandler &onExitRequest) :
Presenter(rc),
m_navi(navi),
using ucl::Window;
- Presenter::Presenter(RefCountObjBase &rc) :
+ Presenter::Presenter(IRefCountObj &rc) :
RefCountAware(&rc),
m_isPrepared(false)
{
class PreviewPage::Item : public RefCountAware {
public:
- Item(RefCountObjBase &rc, MediaItemSRef &&media,
+ Item(IRefCountObj &rc, MediaItemSRef &&media,
ImageGrid &imageGrid, const int itemIndex) :
RefCountAware(&rc),
m_media(std::move(media)),
// PreviewPage //
- PreviewPage::PreviewPage(RefCountObjBase &rc,
+ PreviewPage::PreviewPage(IRefCountObj &rc,
const NaviframeSRef &navi,
const ExitRequestHandler &onExitRequest,
const IMediaAlbumSRef &album,
PreviewPage::~PreviewPage()
{
+ if (m_album) {
+ m_album->delChangeHandler(WEAK_DELEGATE(
+ PreviewPage::onAlbumChanged, asWeak(*this)));
+ }
closeTempViews();
- if (m_page) {
- m_page->exitNoTransition();
+ if (const auto page = m_page.lock()) {
+ page->exitNoTransition();
}
if (m_imageGrid) {
m_imageGrid->setListener(nullptr);
void PreviewPage::checkViewerPage()
{
- if (const ViewerPageSRef viewerPage =
- dynamicRefCast<ViewerPage>(m_page)) {
- const auto mediaId = viewerPage->getMediaId();
+ if (const auto page = dynamicRefCast<ViewerPage>(m_page).lock()) {
+ const auto mediaId = page->getMediaId();
const auto it = std::find_if(m_items.begin(), m_items.end(),
[&mediaId](const ItemSRef &item)
{
void PreviewPage::closeTempViews()
{
- if (m_alert) {
- m_alert->dispose();
+ if (const auto alert = m_alert.lock()) {
+ alert->dispose();
}
if (m_more) {
m_more->setOpened(false);
// ProcessingPresenter //
- ProcessingPresenter::ProcessingPresenter(RefCountObjBase &rc) :
+ ProcessingPresenter::ProcessingPresenter(IRefCountObj &rc) :
Presenter(rc),
m_iconType(IconType::NONE),
m_timer(nullptr),
Result ProcessingPresenter::createIcon()
{
- m_icon = Layout::Builder().
+ const auto icon = Layout::Builder().
setTheme(impl::LAYOUT_POPUP_ICON).
build(*m_popup);
- if (!m_icon) {
+ if (!icon) {
LOG_RETURN(RES_FAIL, "Layout::build() failed!");
}
- m_popup->setContent(*m_icon, impl::PART_TOAST_ICON);
+ m_popup->setContent(*icon, impl::PART_TOAST_ICON);
+
+ m_icon = icon;
return RES_OK;
}
void ProcessingPresenter::animateIcon()
{
- if (m_icon) {
+ if (const auto icon = m_icon.lock()) {
if (m_iconType == IconType::CHECK) {
- m_icon->emit(impl::SIGNAL_ANIMATE_CHECK);
+ icon->emit(impl::SIGNAL_ANIMATE_CHECK);
}
}
}
void ProcessingPresenter::onPopupDismissed(Widget &widget, void *eventInfo)
{
- const auto keepAliver = asShared(*this);
if (m_dismissHandler) {
m_dismissHandler();
}
// SelectModePresenter //
- SelectModePresenter::SelectModePresenter(RefCountObjBase &rc,
+ SelectModePresenter::SelectModePresenter(IRefCountObj &rc,
PageContent &content, const int flags) :
Presenter(rc),
m_content(asShared(content)),
void SelectModePresenter::dispatchEvent(const Event event)
{
- if (m_listener) {
- m_listener->onSelectModeEvent(event);
+ if (const auto listener = m_listener.lock()) {
+ listener->onSelectModeEvent(event);
}
}
class ThumbnailPage::RealizedItem : public RefCountAware {
public:
- RealizedItem(RefCountObjBase &rc,
+ RealizedItem(IRefCountObj &rc,
ThumbnailPage &parent, const int index) :
RefCountAware(&rc),
m_parent(parent),
// ThumbnailPage //
- ThumbnailPage::ThumbnailPage(RefCountObjBase &rc,
+ ThumbnailPage::ThumbnailPage(IRefCountObj &rc,
const NaviframeSRef &navi,
const ExitRequestHandler &onExitRequest,
const IMediaAlbumSRef &album) :
ThumbnailPage::~ThumbnailPage()
{
+ if (m_album) {
+ m_album->delChangeHandler(WEAK_DELEGATE(
+ ThumbnailPage::onAlbumChanged, asWeak(*this)));
+ }
if (m_more) {
m_more->setOpened(false);
}
- if (m_page) {
- m_page->exitNoTransition();
+ if (const auto page = m_page.lock()) {
+ page->exitNoTransition();
}
if (m_imageGrid) {
m_imageGrid->setListener(nullptr);
void ThumbnailPage::onPageExitRequest(Page &page)
{
- if (const PreviewPageSRef previewPage =
- dynamicRefCast<PreviewPage>(m_page)) {
+ if (const auto page = dynamicRefCast<PreviewPage>(m_page).lock()) {
m_imageGrid->scrollToItem(getSafeItemIndex(
- previewPage->getCurrentItemIndex()));
+ page->getCurrentItemIndex()));
}
m_page.reset();
popTo();
// VideoPlayerPage //
- VideoPlayerPage::VideoPlayerPage(RefCountObjBase &rc,
+ VideoPlayerPage::VideoPlayerPage(IRefCountObj &rc,
const NaviframeSRef &navi,
const ExitRequestHandler &onExitRequest,
const MediaItemSRef &media) :
VideoPlayerPage::~VideoPlayerPage()
{
+ if (m_soundMgr) {
+ m_soundMgr->delMediaDeviceStateChangeHandler(WEAK_DELEGATE(
+ VideoPlayerPage::onMediaDeviceStateChanged, asWeak(*this)));
+ m_soundMgr->delMediaVolumeChangeHandler(WEAK_DELEGATE(
+ VideoPlayerPage::onMediaVolumeChanged, asWeak(*this)));
+ }
+
if (isWindowReady()) {
setScreenAlwaysOn(false);
}
// ViewerPage //
- ViewerPage::ViewerPage(RefCountObjBase &rc,
+ ViewerPage::ViewerPage(IRefCountObj &rc,
const NaviframeSRef &navi,
const ExitRequestHandler &onExitRequest,
const MediaItemSRef &media,
private:
class Item : public RefCountAware {
public:
- friend class RefCountObj<Item>;
- Item(RefCountObjBase &rc,
+ friend class ReffedObj<Item>;
+ Item(IRefCountObj &rc,
ImageGrid &imageGrid, ElmWidget &parent) :
RefCountAware(&rc),
m_imageGrid(imageGrid),
if (itemIndex < m_imageGrid.m_itemCount) {
m_realizeIndex = itemIndex;
- if (m_imageGrid.m_listener) {
- m_imageGrid.m_listener->onItemRealized(itemIndex);
+ if (const auto listener = m_imageGrid.m_listener.lock()) {
+ listener->onItemRealized(itemIndex);
}
}
const int itemIndex = m_realizeIndex;
m_realizeIndex = -1;
- if (m_imageGrid.m_listener) {
- m_imageGrid.m_listener->onItemUnrealized(itemIndex);
+ if (const auto listener = m_imageGrid.m_listener.lock()) {
+ listener->onItemUnrealized(itemIndex);
}
}
// ImageGrid //
- ImageGrid::ImageGrid(RefCountObjBase *const rc, Evas_Object *const scroller,
+ ImageGrid::ImageGrid(IRefCountObj *const rc, Evas_Object *const scroller,
const Type type, const bool selectModeStartup) :
ElmWidget(rc, scroller, true),
m_info(getInfo(type)),
- m_scroller(makeShared<StyledWidget>(scroller)),
+ m_scroller(makeShared<StyledWidget>(scroller).get()),
m_box(elm_box_add(*m_scroller)),
m_rect1(evas_object_rectangle_add(m_box.getEvas())),
m_rect2(evas_object_rectangle_add(m_box.getEvas())),
eext_rotary_object_event_activated_set(m_circleScroller, EINA_TRUE);
}
- if (m_listener) {
- m_listener->onTransitionFinished();
+ if (const auto listener = m_listener.lock()) {
+ listener->onTransitionFinished();
}
}
void ImageGrid::handleItemEvent(const int itemIndex,
const ItemEvent event, const int x, const int y) const
{
- if (m_listener) {
- m_listener->onItemEvent(itemIndex, event, x, y);
+ if (const auto listener = m_listener.lock()) {
+ listener->onItemEvent(itemIndex, event, x, y);
}
}
Elm_Interface_Atspi_Accessible *ImageGrid::requestAtspi(const int itemIndex)
{
if ((itemIndex < 0) || (itemIndex >= m_itemCount)) {
- if (m_listener) {
- return m_listener->onAccessObjectRequest(
+ if (const auto listener = m_listener.lock()) {
+ return listener->onAccessObjectRequest(
(itemIndex >= m_itemCount));
}
return nullptr;
// ImageViewer //
- ImageViewer::ImageViewer(RefCountObjBase &rc, Evas_Object *const scroller,
+ ImageViewer::ImageViewer(IRefCountObj &rc, Evas_Object *const scroller,
const std::string &highResPath, const int loadSize,
const bool forceLoad) :
ElmWidget(&rc, scroller, true),
- m_scroller(makeShared<StyledWidget>(scroller)),
+ m_scroller(makeShared<StyledWidget>(scroller).get()),
m_layout(elm_layout_add(*m_scroller)),
m_grid(evas_object_grid_add(m_layout.getEvas())),
m_lowResImage(evas_object_image_filled_add(m_grid.getEvas())),
// PageContent //
- PageContent::PageContent(RefCountObjBase &rc,
+ PageContent::PageContent(IRefCountObj &rc,
const LayoutSRef &layout, const int flags) :
ElmWidget(&rc, *layout, true),
- m_moreOptions(layout)
+ m_mainLayout(layout.get())
{
prepare(flags);
}
void PageContent::prepare(const int flags)
{
- m_moreOptions->setIsOwner(false);
+ m_mainLayout->setIsOwner(false);
- LayoutSRef parent = m_moreOptions;
+ Layout *parent = m_mainLayout;
if (flags & FLAG_SELECT_BUTTON) {
m_selectMode = Layout::Builder().
setTheme(impl::LAYOUT_SELECT_MODE).
build(*parent);
parent->setContent(*m_selectMode);
- parent = m_selectMode;
+ parent = m_selectMode.get();
}
if (flags & FLAG_BOTTOM_BUTTON) {
setTheme(impl::LAYOUT_BOTTOM_BUTTON).
build(*parent);
parent->setContent(*m_bottomButton);
- parent = m_bottomButton;
+ parent = m_bottomButton.get();
}
}
Result PageContent::setMoreOptionsVisible(const bool visible)
{
- if (!m_moreOptions) {
- LOG_RETURN(RES_FAIL, "More options is not supported!");
- }
- const auto content = m_moreOptions->getContent(impl::PART_MORE_OPTIONS);
+ const auto content = m_mainLayout->getContent(impl::PART_MORE_OPTIONS);
if (!content) {
LOG_RETURN(RES_FAIL, "More option is not created!");
}
case Part::DEFAULT:
return impl::callSafe(getTopLayout(), func, PART_CONTENT);
case Part::OVERLAY:
- return impl::callSafe(m_moreOptions.get(), func,
- impl::PART_OVERLAY);
+ func(*m_mainLayout, impl::PART_OVERLAY);
+ return RES_OK;
case Part::MORE_OPTIONS:
- return impl::callSafe(m_moreOptions.get(), func,
- impl::PART_MORE_OPTIONS);
+ func(*m_mainLayout, impl::PART_MORE_OPTIONS);
+ return RES_OK;
case Part::SELECT_BUTTON:
return impl::callSafe(m_selectMode.get(), func, PART_ICON);
case Part::BOTTOM_BUTTON:
if (m_selectMode) {
return m_selectMode.get();
}
- return m_moreOptions.get();
+ return m_mainLayout;
}
}
namespace gallery {
- TouchParser::TouchParser(RefCountObjBase &rc, Widget &eventSource) :
+ TouchParser::TouchParser(IRefCountObj &rc, Widget &eventSource) :
RefCountAware(&rc),
m_holdTimer(nullptr),
m_downTime(0),
EdjeSignalSrc(""));
protected:
- EdjeWidget(RefCountObjBase *rc, Evas_Object *eo, bool isOwner = false);
+ EdjeWidget(IRefCountObj *rc, Evas_Object *eo, bool isOwner = false);
};
}
namespace ucl {
- inline EdjeWidget::EdjeWidget(RefCountObjBase *const rc,
+ inline EdjeWidget::EdjeWidget(IRefCountObj *const rc,
Evas_Object *const eo, const bool isOwner) :
ElmWidget(rc, eo, isOwner)
{
Window *getWindow() const;
protected:
- friend class RefCountObj<ElmWidget>;
- ElmWidget(RefCountObjBase *rc, Evas_Object *eo, bool isOwner = false);
+ friend class ReffedObj<ElmWidget>;
+ ElmWidget(IRefCountObj *rc, Evas_Object *eo, bool isOwner = false);
virtual void setFocusedImpl(bool value) final override;
virtual bool isFocusedImpl() const final override;
};
public:
- friend class RefCountObj<Layout>;
+ friend class ReffedObj<Layout>;
using EdjeWidget::EdjeWidget;
explicit Layout(Evas_Object *eo, bool isOwner = false);
std::vector<NaviItem> getItems() const;
private:
- friend class RefCountObj<Naviframe>;
- Naviframe(RefCountObjBase &rc, Evas_Object *eo);
+ friend class ReffedObj<Naviframe>;
+ Naviframe(IRefCountObj &rc, Evas_Object *eo);
void onTransitionFinished(Widget &widget, void *eventInfo);
class StyledWidget : public EdjeWidget {
public:
- friend class RefCountObj<StyledWidget>;
+ friend class ReffedObj<StyledWidget>;
using EdjeWidget::EdjeWidget;
explicit StyledWidget(Evas_Object *eo, bool isOwner = false);
bool isFocused() const;
protected:
- friend class RefCountObj<Widget>;
- Widget(RefCountObjBase *rc, Evas_Object *eo, bool isOwner = false);
+ friend class ReffedObj<Widget>;
+ Widget(IRefCountObj *rc, Evas_Object *eo, bool isOwner = false);
virtual void setFocusedImpl(bool value);
virtual bool isFocusedImpl() const;
protected:
// This section MUST be protected!
- // Signal to RefCountObj<T> to call onUniqueChanged()
+ // Signal to RefCountObj<T, C> to call onUniqueChanged()
enum { ENABLE_ON_UNIQUE_CHANGED_DISPATCH };
void onUniqueChanged(bool isUnique);
void lower();
private:
- friend class RefCountObj<Window>;
- Window(RefCountObjBase *rc, Evas_Object *eo,
+ friend class ReffedObj<Window>;
+ Window(IRefCountObj *rc, Evas_Object *eo,
bool isOwner, Evas_Object *conform);
private:
// Window //
- inline Window::Window(RefCountObjBase *const rc, Evas_Object *const eo,
+ inline Window::Window(IRefCountObj *const rc, Evas_Object *const eo,
const bool isOwner, Evas_Object *const conform) :
ElmWidget(rc, eo, isOwner),
m_conform(conform)
template <class DELEGATE2>
void Event<DELEGATE>::operator+=(DELEGATE2 &&delegate)
{
- if (delegate && std::find(m_delegates.begin(), m_delegates.end(),
- delegate) == m_delegates.end()) {
- m_delegates.emplace_back(std::forward<DELEGATE2>(delegate));
- }
+ m_delegates.emplace_back(std::forward<DELEGATE2>(delegate));
}
template <class DELEGATE>
template <class DELEGATE>
bool Event<DELEGATE>::isEmpty() const
{
- return (isLocked() ? false : m_delegates.empty());
+ return m_delegates.empty();
}
template <class DELEGATE>
WeakRef<T> asWeakThis(T *thisAlias) const;
protected:
- RefCountAware(RefCountObjBase *rc);
+ RefCountAware(IRefCountObj *rc);
virtual ~RefCountAware() = default;
protected:
- RefCountObjBase *const m_rc;
+ enum { IS_REF_COUNT_AWARE };
+
+ protected:
+ IRefCountObj *const m_rc;
};
// Non-member functions //
namespace ucl {
- inline RefCountAware::RefCountAware(RefCountObjBase *const rc) :
+ inline RefCountAware::RefCountAware(IRefCountObj *const rc) :
m_rc(rc)
{
}
bool isExpired() const;
private:
- friend class RefCountObj<Timeout>;
+ friend class ReffedObj<Timeout>;
Timeout(const TimeoutHandler &handler);
~Timeout();
template <class FUNC_SIG>
BaseDelegate(BaseDelegate2<FUNC_SIG, DATA> &&d) noexcept;
- R operator()(ARGS ...args) const;
-
void reset() noexcept;
const DATA &getData() const noexcept;
protected:
BaseDelegate(const DATA &data, StubA stubA) noexcept;
- private:
+ protected:
DATA m_data;
StubA m_stubA;
};
{
}
- template <class R, class ...ARGS, class DATA>
- inline R BaseDelegate<R(ARGS...), DATA>::operator()(ARGS ...args) const
- {
- return m_stubA(
- static_cast<void *>(m_data), std::forward<ARGS>(args)...);
- }
-
template <class R, class ...ARGS, class DATA>
inline void BaseDelegate<R(ARGS...), DATA>::reset() noexcept
{
public:
using BaseDelegate<R(ARGS...), void *>::BaseDelegate;
+ R operator()(ARGS ...args) const;
+
template <class CLASS, R(CLASS::*METHOD)(ARGS...)>
static Delegate make(CLASS *data) noexcept;
template <class CLASS, R(CLASS::*METHOD)(ARGS...) const>
namespace ucl {
+ template <class R, class ...ARGS>
+ inline R Delegate<R(ARGS...)>::operator()(ARGS ...args) const
+ {
+ return this->m_stubA(this->m_data, std::forward<ARGS>(args)...);
+ }
+
template <class R, class ...ARGS>
template <class CLASS, R(CLASS::*METHOD)(ARGS...)>
inline Delegate<R(ARGS...)>
public:
using BaseDelegate2<R(ARGS...), void *>::BaseDelegate2;
+ R operator()(ARGS ...args) const;
+
template <class CLASS, R(CLASS::*METHOD)(ARGS...)>
static Delegate2 make(CLASS *data) noexcept;
template <class CLASS, R(CLASS::*METHOD)(ARGS...) const>
namespace ucl {
+ template <class R, class ...ARGS>
+ inline R Delegate2<R(ARGS...)>::operator()(ARGS ...args) const
+ {
+ return this->m_stubA(this->m_data, std::forward<ARGS>(args)...);
+ }
+
template <class R, class ...ARGS>
template <class CLASS, R(CLASS::*METHOD)(ARGS...)>
inline Delegate2<R(ARGS...)>
inline bool operator==(const BaseDelegate<R(ARGS...), DATA1> &lhs,
const BaseDelegate<R(ARGS...), DATA2> &rhs) noexcept
{
- return ((lhs.getStubA() == rhs.getStubA()) && (static_cast<void *>(
- lhs.getData()) == static_cast<void *>(rhs.getData())));
+ return ((lhs.getStubA() == rhs.getStubA()) && (
+ lhs.getData() == rhs.getData()));
}
template <class R, class ...ARGS, class DATA1, class DATA2>
inline bool operator!=(const BaseDelegate<R(ARGS...), DATA1> &lhs,
const BaseDelegate<R(ARGS...), DATA2> &rhs) noexcept
{
- return ((lhs.getStubA() != rhs.getStubA()) || (static_cast<void *>(
- lhs.getData()) != static_cast<void *>(rhs.getData())));
+ return ((lhs.getStubA() != rhs.getStubA()) || (
+ lhs.getData() != rhs.getData()));
}
template <class R, class ...ARGS, class DATA1, class DATA2>
const BaseDelegate<R(ARGS...), DATA2> &rhs) noexcept
{
return ((lhs.getStubA() < rhs.getStubA()) ||
- ((lhs.getStubA() == rhs.getStubA()) && (static_cast<void *>(
- lhs.getData()) < static_cast<void *>(rhs.getData()))));
+ ((lhs.getStubA() == rhs.getStubA()) && (
+ lhs.getData() < rhs.getData())));
}
template <class R, class ...ARGS, class DATA1, class DATA2>
const BaseDelegate<R(ARGS...), DATA2> &rhs) noexcept
{
return ((lhs.getStubA() < rhs.getStubA()) ||
- ((lhs.getStubA() == rhs.getStubA()) && (static_cast<void *>(
- lhs.getData()) <= static_cast<void *>(rhs.getData()))));
+ ((lhs.getStubA() == rhs.getStubA()) && (
+ lhs.getData() <= rhs.getData())));
}
template <class R, class ...ARGS, class DATA1, class DATA2>
const BaseDelegate<R(ARGS...), DATA2> &rhs) noexcept
{
return ((lhs.getStubA() > rhs.getStubA()) ||
- ((lhs.getStubA() == rhs.getStubA()) && (static_cast<void *>(
- lhs.getData()) > static_cast<void *>(rhs.getData()))));
+ ((lhs.getStubA() == rhs.getStubA()) && (
+ lhs.getData() > rhs.getData())));
}
template <class R, class ...ARGS, class DATA1, class DATA2>
const BaseDelegate<R(ARGS...), DATA2> &rhs) noexcept
{
return ((lhs.getStubA() > rhs.getStubA()) ||
- ((lhs.getStubA() == rhs.getStubA()) && (static_cast<void *>(
- lhs.getData()) >= static_cast<void *>(rhs.getData()))));
+ ((lhs.getStubA() == rhs.getStubA()) && (
+ lhs.getData() >= rhs.getData())));
}
}
#ifndef __UCL_UTIL_MEMORY_H__
#define __UCL_UTIL_MEMORY_H__
-#include "memory/RefCountObjBase.h"
#include "memory/RefCountObj.h"
#include "memory/BaseRef.h"
#ifndef __UCL_UTIL_MEMORY_BASE_REF_H__
#define __UCL_UTIL_MEMORY_BASE_REF_H__
-#include "RefCountObjBase.h"
+#include "IRefCountObj.h"
namespace ucl {
friend class WeakRef;
public:
- int getUseCount() const;
-
- T *operator->() const noexcept;
- typename std::add_lvalue_reference<T>::type operator*() const noexcept;
-
- template <class U>
- explicit operator U() const noexcept;
+ int getUseCount() const noexcept;
protected:
constexpr BaseRef() noexcept;
- BaseRef(RefCountObjBase *rc, T *ptr) noexcept;
+ BaseRef(IRefCountObj *rc, T *ptr) noexcept;
BaseRef(BaseRef<T> &&r) noexcept;
template <class U>
BaseRef(BaseRef<U> &&r) noexcept;
protected:
- RefCountObjBase *m_rc;
+ IRefCountObj *m_rc;
T *m_ptr;
};
}
template <class T>
inline BaseRef<T>::BaseRef(
- RefCountObjBase *const rc, T *const ptr) noexcept :
+ IRefCountObj *const rc, T *const ptr) noexcept :
m_rc(rc),
m_ptr(ptr)
{
}
template <class T>
- inline int BaseRef<T>::getUseCount() const
+ inline int BaseRef<T>::getUseCount() const noexcept
{
return (m_rc ? m_rc->getUseCount() : 0);
}
-
- template <class T>
- inline T *BaseRef<T>::operator->() const noexcept
- {
- return m_ptr;
- }
-
- template <class T>
- inline typename std::add_lvalue_reference<T>::type
- BaseRef<T>::operator*() const noexcept
- {
- return *m_ptr;
- }
-
- template <class T>
- template <class U>
- inline BaseRef<T>::operator U() const noexcept
- {
- return static_cast<U>(m_ptr);
- }
}
--- /dev/null
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __UCL_UTIL_MEMORY_I_REF_COUNT_OBJ_H__
+#define __UCL_UTIL_MEMORY_I_REF_COUNT_OBJ_H__
+
+#include "ucl/util/types/classTypes.h"
+
+namespace ucl {
+
+ class IRefCountObj : public Polymorphic {
+ public:
+ virtual void ref() noexcept = 0;
+ virtual void unref() noexcept = 0;
+ virtual bool refNz() noexcept = 0;
+ virtual void refWeak() noexcept = 0;
+ virtual void unrefWeak() noexcept = 0;
+ virtual unsigned getUseCount() const noexcept = 0;
+ protected:
+ virtual ~IRefCountObj() = default;
+ };
+}
+
+#endif // __UCL_UTIL_MEMORY_I_REF_COUNT_OBJ_H__
#ifndef __UCL_UTIL_MEMORY_REF_COUNT_OBJ_H__
#define __UCL_UTIL_MEMORY_REF_COUNT_OBJ_H__
-#include "RefCountObjBase.h"
+#include "IRefCountObj.h"
+#include "ReffedObj.h"
namespace ucl {
- template <class T>
- class RefCountObj : public RefCountObjBase {
+ template <class T, class C>
+ class RefCountObj final : public IRefCountObj {
public:
template <class ...ARGS>
RefCountObj(ARGS &&...args);
T *getObj() noexcept;
- protected:
- // RefCountObjBase //
- virtual void dispose() noexcept final override;
- virtual void onUniqueChanged(bool isUnique) noexcept final override;
+ // IRefCountObj //
+
+ virtual void ref() noexcept final override;
+ virtual void unref() noexcept final override;
+ virtual bool refNz() noexcept final override;
+ virtual void refWeak() noexcept final override;
+ virtual void unrefWeak() noexcept final override;
+ virtual unsigned getUseCount() const noexcept final override;
private:
- // Consume-all SFINAE functions
- template <class T2, class ...ARGS>
- void createObj(const P<0> &, ARGS &&...args);
+ template <class T2, class = char[1]>
+ struct IsRefCountAware : std::false_type {};
+ template <class T2>
+ struct IsRefCountAware<T2, char[T2::IS_REF_COUNT_AWARE * 0 + 1]> :
+ std::true_type {};
+
+ template <class T2, class = char[1]>
+ struct IsOnUniqueAware : std::false_type {};
template <class T2>
- void dispatchOnUniqueChanged(
- const P<0> &, const bool isUnique) noexcept;
+ struct IsOnUniqueAware<T2,
+ char[T2::ENABLE_ON_UNIQUE_CHANGED_DISPATCH * 0 + 1]> :
+ std::true_type {};
- // Specialized SFINAE functions
+ private:
+ virtual ~RefCountObj() = default;
+
+ template <class T2, class ...ARGS, class =
+ typename std::enable_if<!IsRefCountAware<T2>::value>::type>
+ void createObj(const P<0> &, ARGS &&...args)
+ {
+ m_obj.create(std::forward<ARGS>(args)...);
+ }
- template <class T2, class ...ARGS>
+ template <class T2, class ...ARGS, class =
+ typename std::enable_if<IsRefCountAware<T2>::value>::type>
auto createObj(const P<1> &, ARGS &&...args) -> decltype(
- (void)(new T2(this, std::forward<ARGS>(args)...)))
+ ReffedObj<T>::template check<T2>(
+ (IRefCountObj *)0, std::forward<ARGS>(args)...))
{
- new (getObj()) T(this, std::forward<ARGS>(args)...);
+ m_obj.create(static_cast<IRefCountObj *>(this),
+ std::forward<ARGS>(args)...);
}
- template <class T2, class ...ARGS>
+ template <class T2, class ...ARGS, class =
+ typename std::enable_if<IsRefCountAware<T2>::value>::type>
auto createObj(const P<2> &, ARGS &&...args) -> decltype(
- (void)(new T2(*this, std::forward<ARGS>(args)...)))
+ ReffedObj<T>::template check<T2>(
+ *(IRefCountObj *)0, std::forward<ARGS>(args)...))
+ {
+ m_obj.create(*static_cast<IRefCountObj *>(this),
+ std::forward<ARGS>(args)...);
+ }
+
+ void dispatchOnUniqueChanged(const bool isUnique)
+ {
+ dispatchOnUniqueChanged<T>(P<1>(), isUnique);
+ }
+
+ template <class T2>
+ void dispatchOnUniqueChanged(...)
{
- new (getObj()) T(*this, std::forward<ARGS>(args)...);
}
- template <class T2,
- class = char(*)[T2::ENABLE_ON_UNIQUE_CHANGED_DISPATCH * 0 + 1]>
- void dispatchOnUniqueChanged(
- const P<1> &, const bool isUnique) noexcept
+ template <class T2, class =
+ typename std::enable_if<IsOnUniqueAware<T2>::value>::type>
+ void dispatchOnUniqueChanged(const P<1> &, const bool isUnique)
{
- getObj()->onUniqueChanged(isUnique);
+ m_obj.template dispatchOnUniqueChanged<T>(isUnique);
}
private:
- // Proper-aligned storage for T
- typename std::aligned_storage<sizeof(T), alignof(T)>::type m_obj;
+ ReffedObj<T> m_obj;
+ C m_useCounter;
+ C m_weakCounter;
};
}
namespace ucl {
- template <class T>
+ template <class T, class C>
template <class ...ARGS>
- inline RefCountObj<T>::RefCountObj(ARGS &&...args)
+ inline RefCountObj<T, C>::RefCountObj(ARGS &&...args) :
+ m_useCounter(1),
+ m_weakCounter(1)
{
createObj<T>(P<2>(), std::forward<ARGS>(args)...);
}
- template <class T>
- inline T *RefCountObj<T>::getObj() noexcept
+ template <class T, class C>
+ inline T *RefCountObj<T, C>::getObj() noexcept
{
- return static_cast<T *>(static_cast<void *>(&m_obj));
+ return m_obj.get();
}
- template <class T>
- inline void RefCountObj<T>::dispose() noexcept
+ template <class T, class C>
+ inline void RefCountObj<T, C>::ref() noexcept
{
- if (!isDisposed()) {
- RefCountObjBase::dispose();
- getObj()->~T();
+ if (m_useCounter.ref() == 2) {
+ dispatchOnUniqueChanged(false);
}
}
- template <class T>
- inline void RefCountObj<T>::onUniqueChanged(const bool isUnique) noexcept
+ template <class T, class C>
+ inline void RefCountObj<T, C>::unref() noexcept
{
- dispatchOnUniqueChanged<T>(P<1>(), isUnique);
+ const auto newCount = m_useCounter.unref();
+ if (newCount == 0) {
+ m_obj.destroy();
+ unrefWeak();
+ } else if (newCount == 1) {
+ dispatchOnUniqueChanged(true);
+ }
+ }
+
+ template <class T, class C>
+ inline bool RefCountObj<T, C>::refNz() noexcept
+ {
+ const auto newCount = m_useCounter.refNz();
+ if (newCount == 0) {
+ return false;
+ }
+ if (newCount == 2) {
+ dispatchOnUniqueChanged(false);
+ }
+ return true;
}
- template <class T>
- template <class T2, class ...ARGS>
- inline void RefCountObj<T>::createObj(const P<0> &, ARGS &&...args)
+ template <class T, class C>
+ inline void RefCountObj<T, C>::refWeak() noexcept
{
- new (getObj()) T(std::forward<ARGS>(args)...);
+ m_weakCounter.ref();
+ }
+
+ template <class T, class C>
+ inline void RefCountObj<T, C>::unrefWeak() noexcept
+ {
+ if (m_weakCounter.unref() == 0) {
+ delete this;
+ }
}
- template <class T>
- template <class T2>
- inline void RefCountObj<T>::dispatchOnUniqueChanged(
- const P<0> &, const bool isUnique) noexcept
+ template <class T, class C>
+ inline unsigned RefCountObj<T, C>::getUseCount() const noexcept
{
+ return m_useCounter.get();
}
}
+++ /dev/null
-/*
- * Copyright 2017 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __UCL_UTIL_MEMORY_REF_COUNT_OBJ_BASE_H__
-#define __UCL_UTIL_MEMORY_REF_COUNT_OBJ_BASE_H__
-
-#include "ucl/util/types/classTypes.h"
-
-namespace ucl {
-
- class RefCountObjBase : public Polymorphic {
- public:
- void ref() noexcept;
- void unref() noexcept;
-
- void refWeak() noexcept;
- void unrefWeak() noexcept;
-
- int getUseCount() const noexcept;
- bool isDisposed() const noexcept;
-
- protected:
- RefCountObjBase();
- virtual ~RefCountObjBase() = default;
-
- virtual void dispose() noexcept;
- virtual void onUniqueChanged(bool isUnique) noexcept = 0;
-
- private:
- int m_useRefs;
- int m_weakRefs;
- bool m_isDisposed;
- };
-}
-
-#include "RefCountObjBase.hpp"
-
-#endif // __UCL_UTIL_MEMORY_REF_COUNT_OBJ_BASE_H__
+++ /dev/null
-/*
- * Copyright 2017 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-namespace ucl {
-
- inline RefCountObjBase::RefCountObjBase() :
- m_useRefs(0),
- m_weakRefs(1),
- m_isDisposed(false)
- {
- }
-
- inline void RefCountObjBase::ref() noexcept
- {
- ++m_useRefs;
- if (m_useRefs == 2) {
- onUniqueChanged(false);
- }
- }
-
- inline void RefCountObjBase::unref() noexcept
- {
- --m_useRefs;
- if (m_useRefs <= 1) {
- if (m_useRefs == 1) {
- onUniqueChanged(true);
- } else {
- dispose();
- unrefWeak();
- }
- }
- }
-
- inline void RefCountObjBase::refWeak() noexcept
- {
- ++m_weakRefs;
- }
-
- inline void RefCountObjBase::unrefWeak() noexcept
- {
- --m_weakRefs;
- if (m_weakRefs == 0) {
- delete this;
- }
- }
-
- inline int RefCountObjBase::getUseCount() const noexcept
- {
- return m_useRefs;
- }
-
- inline bool RefCountObjBase::isDisposed() const noexcept
- {
- return m_isDisposed;
- }
-
- inline void RefCountObjBase::dispose() noexcept
- {
- m_isDisposed = true;
- }
-}
--- /dev/null
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __UCL_UTIL_MEMORY_REF_COUNTER_MT_H__
+#define __UCL_UTIL_MEMORY_REF_COUNTER_MT_H__
+
+#include "ucl/util/types/baseTypes.h"
+
+namespace ucl {
+
+ class RefCounterMT final {
+ public:
+ explicit RefCounterMT(const UInt count = 0) noexcept;
+
+ UInt ref() noexcept;
+ UInt unref() noexcept;
+ UInt refNz() noexcept;
+
+ UInt get() const noexcept;
+
+ private:
+ std::atomic<UInt> m_counter;
+ };
+}
+
+#include "RefCounterMT.hpp"
+
+#endif // __UCL_UTIL_MEMORY_REF_COUNTER_MT_H__
--- /dev/null
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace ucl {
+
+ inline RefCounterMT::RefCounterMT(const UInt count) noexcept :
+ m_counter(count)
+ {
+ }
+
+ inline UInt RefCounterMT::ref() noexcept
+ {
+ return (m_counter.fetch_add(1, std::memory_order_acq_rel) + 1);
+ }
+
+ inline UInt RefCounterMT::unref() noexcept
+ {
+ return (m_counter.fetch_sub(1, std::memory_order_acq_rel) - 1);
+ }
+
+ inline UInt RefCounterMT::refNz() noexcept
+ {
+ auto curCount = m_counter.load(std::memory_order_relaxed);
+ for (;;) {
+ if (curCount == 0) {
+ return 0;
+ }
+ const auto newCount = (curCount + 1);
+ if (m_counter.compare_exchange_weak(curCount, newCount,
+ std::memory_order_acq_rel, std::memory_order_relaxed)) {
+ return newCount;
+ }
+ }
+ }
+
+ inline UInt RefCounterMT::get() const noexcept
+ {
+ return m_counter.load(std::memory_order_relaxed);
+ }
+}
--- /dev/null
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __UCL_UTIL_MEMORY_REF_COUNTER_ST_H__
+#define __UCL_UTIL_MEMORY_REF_COUNTER_ST_H__
+
+#include "ucl/util/types/baseTypes.h"
+
+namespace ucl {
+
+ class RefCounterST final {
+ public:
+ explicit RefCounterST(const UInt count = 0) noexcept;
+
+ UInt ref() noexcept;
+ UInt unref() noexcept;
+ UInt refNz() noexcept;
+
+ UInt get() const noexcept;
+
+ private:
+ UInt m_counter;
+ };
+}
+
+#include "RefCounterST.hpp"
+
+#endif // __UCL_UTIL_MEMORY_REF_COUNTER_ST_H__
--- /dev/null
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace ucl {
+
+ inline RefCounterST::RefCounterST(const UInt count) noexcept :
+ m_counter(count)
+ {
+ }
+
+ inline UInt RefCounterST::ref() noexcept
+ {
+ return (++m_counter);
+ }
+
+ inline UInt RefCounterST::unref() noexcept
+ {
+ return (--m_counter);
+ }
+
+ inline UInt RefCounterST::refNz() noexcept
+ {
+ if (m_counter == 0) {
+ return 0;
+ }
+ return ref();
+ }
+
+ inline UInt RefCounterST::get() const noexcept
+ {
+ return m_counter;
+ }
+}
--- /dev/null
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __UCL_UTIL_MEMORY_REFFED_OBJ_H__
+#define __UCL_UTIL_MEMORY_REFFED_OBJ_H__
+
+#include "RefCounterST.h"
+#include "RefCounterMT.h"
+
+namespace ucl {
+
+ template <class T, class C>
+ class RefCountObj;
+
+ template <class T>
+ class ReffedObj final {
+ private:
+ friend class RefCountObj<T, RefCounterST>;
+ friend class RefCountObj<T, RefCounterMT>;
+
+ template <class ...ARGS>
+ void create(ARGS &&...args);
+ void destroy() noexcept;
+
+ T *get() noexcept;
+
+ template <class T2>
+ void dispatchOnUniqueChanged(bool isUnique);
+
+ private:
+ template <class T2, class ...ARGS>
+ static constexpr auto check(ARGS &&...args) -> decltype(
+ (void)(new T2(std::forward<ARGS>(args)...)))
+ {
+ return;
+ }
+
+ private:
+ typename std::aligned_storage<sizeof(T), alignof(T)>::type m_obj;
+ };
+}
+
+#include "ReffedObj.hpp"
+
+#endif // __UCL_UTIL_MEMORY_REFFED_OBJ_H__
--- /dev/null
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace ucl {
+
+ template <class T>
+ template <class ...ARGS>
+ inline void ReffedObj<T>::create(ARGS &&...args)
+ {
+ new (get()) T(std::forward<ARGS>(args)...);
+ }
+
+ template <class T>
+ inline void ReffedObj<T>::destroy() noexcept
+ {
+ get()->~T();
+ }
+
+ template <class T>
+ inline T *ReffedObj<T>::get() noexcept
+ {
+ return static_cast<T *>(static_cast<void *>(&m_obj));
+ }
+
+ template <class T>
+ template <class T2>
+ inline void ReffedObj<T>::dispatchOnUniqueChanged(const bool isUnique)
+ {
+ get()->onUniqueChanged(isUnique);
+ }
+}
namespace ucl {
template <class T>
- class SharedRef : public BaseRef<T> {
+ class SharedRef final : public BaseRef<T> {
public:
template <class U>
friend void swap(SharedRef<U> &x, SharedRef<U> &y) noexcept;
constexpr SharedRef() noexcept;
constexpr SharedRef(std::nullptr_t) noexcept;
- SharedRef(RefCountObjBase *rc, T *ptr) noexcept;
+ SharedRef(IRefCountObj *rc, T *ptr) noexcept;
+ SharedRef(IRefCountObj *rc, T *ptr, bool noRef) noexcept;
SharedRef(const SharedRef<T> &r) noexcept;
template <class U>
- SharedRef(const BaseRef<U> &r) noexcept;
+ SharedRef(const SharedRef<U> &r) noexcept;
SharedRef(SharedRef<T> &&r) noexcept;
template <class U>
T *get() const noexcept;
operator bool() const noexcept;
+ T *operator->() const noexcept;
+ typename std::add_lvalue_reference<T>::type operator*() const noexcept;
+
template <class U, class = typename std::enable_if<
std::is_convertible<T *, U *>::value && (
std::is_same<typename std::remove_cv<U>::type, void>::value ||
template <class T, class ...ARGS>
SharedRef<T> makeShared(ARGS &&...args);
+ template <class T, class ...ARGS>
+ SharedRef<T> makeSharedMT(ARGS &&...args);
template <class T, class U>
const SharedRef<T> &constRefCast(const SharedRef<U> &r) noexcept;
* limitations under the License.
*/
-#include "RefCountObj.h"
-
namespace ucl {
template <class T>
template <class T>
inline SharedRef<T>::SharedRef(
- RefCountObjBase *const rc, T *const ptr) noexcept :
+ IRefCountObj *const rc, T *const ptr) noexcept :
BaseRef<T>(rc, ptr)
{
this->m_rc->ref();
}
+ template <class T>
+ inline SharedRef<T>::SharedRef(
+ IRefCountObj *const rc, T *const ptr, bool noRef) noexcept :
+ BaseRef<T>(rc, ptr)
+ {
+ }
+
template <class T>
inline SharedRef<T>::SharedRef(const SharedRef<T> &r) noexcept :
BaseRef<T>(r.m_rc, r.m_ptr)
template <class T>
template <class U>
- inline SharedRef<T>::SharedRef(const BaseRef<U> &r) noexcept :
+ inline SharedRef<T>::SharedRef(const SharedRef<U> &r) noexcept :
BaseRef<T>(r.m_rc, r.m_ptr)
{
if (this->m_rc) {
return !!this->m_ptr;
}
+ template <class T>
+ inline T *SharedRef<T>::operator->() const noexcept
+ {
+ return this->m_ptr;
+ }
+
+ template <class T>
+ inline typename std::add_lvalue_reference<T>::type
+ SharedRef<T>::operator*() const noexcept
+ {
+ return *this->m_ptr;
+ }
+
// Non-member functions //
template <class T, class ...ARGS>
SharedRef<T> makeShared(ARGS &&...args)
{
- const auto rc = new RefCountObj<T>(std::forward<ARGS>(args)...);
- return {rc, rc->getObj()};
+ const auto rc = new RefCountObj<T, RefCounterST>(
+ std::forward<ARGS>(args)...);
+ return {rc, rc->getObj(), true};
+ }
+
+ template <class T, class ...ARGS>
+ SharedRef<T> makeSharedMT(ARGS &&...args)
+ {
+ const auto rc = new RefCountObj<T, RefCounterMT>(
+ std::forward<ARGS>(args)...);
+ return {rc, rc->getObj(), true};
}
template <class T>
namespace ucl {
template <class T>
- class WeakRef : public BaseRef<T> {
+ class WeakRef final : public BaseRef<T> {
public:
template <class U>
friend void swap(WeakRef<U> &x, WeakRef<U> &y) noexcept;
constexpr WeakRef() noexcept;
constexpr WeakRef(std::nullptr_t) noexcept;
- WeakRef(RefCountObjBase *rc, T *ptr) noexcept;
+ WeakRef(IRefCountObj *rc, T *ptr) noexcept;
WeakRef(const WeakRef<T> &r) noexcept;
template <class U>
void reset() noexcept;
- T *get() const noexcept;
+ SharedRef<T> lock() const noexcept;
+
+ T *getUnsafePtr() const noexcept;
operator bool() const noexcept;
template <class U, class = typename std::enable_if<
template <class T>
inline WeakRef<T>::WeakRef(
- RefCountObjBase *const rc, T *const ptr) noexcept :
+ IRefCountObj *const rc, T *const ptr) noexcept :
BaseRef<T>(rc, ptr)
{
this->m_rc->refWeak();
}
template <class T>
- inline T *WeakRef<T>::get() const noexcept
+ inline SharedRef<T> WeakRef<T>::lock() const noexcept
+ {
+ if (this->m_rc && this->m_rc->refNz()) {
+ return {this->m_rc, this->m_ptr, true};
+ }
+ return {};
+ }
+
+ template <class T>
+ inline T *WeakRef<T>::getUnsafePtr() const noexcept
{
return (operator bool() ? this->m_ptr : nullptr);
}
template <class T>
inline WeakRef<T>::operator bool() const noexcept
{
- return (this->m_ptr && !this->m_rc->isDisposed());
+ return (this->m_rc && (this->m_rc->getUseCount() > 0));
}
// Non-member functions //
template <class T, class U>
inline WeakRef<T> staticRefCast(const WeakRef<U> &r) noexcept
{
- return {r.m_rc, static_cast<T *>(r.get())};
+ return {r.m_rc, static_cast<T *>(r.getUnsafePtr())};
}
template <class T, class U>
inline WeakRef<T> dynamicRefCast(const WeakRef<U> &r) noexcept
{
- const auto ptr = dynamic_cast<T *>(r.get());
+ const auto ptr = dynamic_cast<T *>(r.getUnsafePtr());
if (!ptr) {
return {};
}
// Relation operators //
+ namespace himpl {
+
+ template <class T, class = typename std::enable_if<
+ !std::is_base_of<BaseRef<typename T::Type>, T>::value>::type>
+ inline const T &getCmpPtr(const T &ptr) noexcept
+ {
+ return ptr;
+ }
+
+ template <class T>
+ inline T *getCmpPtr(const SharedRef<T> &r) noexcept
+ {
+ return r.get();
+ }
+
+ template <class T>
+ inline T *getCmpPtr(const WeakRef<T> &r) noexcept
+ {
+ return r.getUnsafePtr();
+ }
+ }
+
template <class T, class U, class = typename std::enable_if<
- std::is_base_of<BaseRef<typename T::Type>, T>::value &&
+ std::is_base_of<BaseRef<typename T::Type>, T>::value ||
std::is_base_of<BaseRef<typename U::Type>, U>::value>::type>
inline bool operator==(const T &lhs, const U &rhs) noexcept
{
- return (lhs.get() == rhs.get());
+ return (himpl::getCmpPtr(lhs) == himpl::getCmpPtr(rhs));
}
template <class T, class U, class = typename std::enable_if<
- std::is_base_of<BaseRef<typename T::Type>, T>::value &&
+ std::is_base_of<BaseRef<typename T::Type>, T>::value ||
std::is_base_of<BaseRef<typename U::Type>, U>::value>::type>
inline bool operator!=(const T &lhs, const U &rhs) noexcept
{
- return (lhs.get() != rhs.get());
+ return (himpl::getCmpPtr(lhs) != himpl::getCmpPtr(rhs));
}
template <class T, class U, class = typename std::enable_if<
- std::is_base_of<BaseRef<typename T::Type>, T>::value &&
+ std::is_base_of<BaseRef<typename T::Type>, T>::value ||
std::is_base_of<BaseRef<typename U::Type>, U>::value>::type>
inline bool operator<(const T &lhs, const U &rhs) noexcept
{
- return (lhs.get() < rhs.get());
+ return (himpl::getCmpPtr(lhs) < himpl::getCmpPtr(rhs));
}
template <class T, class U, class = typename std::enable_if<
- std::is_base_of<BaseRef<typename T::Type>, T>::value &&
+ std::is_base_of<BaseRef<typename T::Type>, T>::value ||
std::is_base_of<BaseRef<typename U::Type>, U>::value>::type>
inline bool operator<=(const T &lhs, const U &rhs) noexcept
{
- return (lhs.get() <= rhs.get());
+ return (himpl::getCmpPtr(lhs) <= himpl::getCmpPtr(rhs));
}
template <class T, class U, class = typename std::enable_if<
- std::is_base_of<BaseRef<typename T::Type>, T>::value &&
+ std::is_base_of<BaseRef<typename T::Type>, T>::value ||
std::is_base_of<BaseRef<typename U::Type>, U>::value>::type>
inline bool operator>(const T &lhs, const U &rhs) noexcept
{
- return (lhs.get() > rhs.get());
+ return (himpl::getCmpPtr(lhs) > himpl::getCmpPtr(rhs));
}
template <class T, class U, class = typename std::enable_if<
- std::is_base_of<BaseRef<typename T::Type>, T>::value &&
+ std::is_base_of<BaseRef<typename T::Type>, T>::value ||
std::is_base_of<BaseRef<typename U::Type>, U>::value>::type>
inline bool operator>=(const T &lhs, const U &rhs) noexcept
{
- return (lhs.get() >= rhs.get());
+ return (himpl::getCmpPtr(lhs) >= himpl::getCmpPtr(rhs));
}
template <class T, class = typename std::enable_if<
public:
using BaseDelegate<R(ARGS...), WeakRef<void>>::BaseDelegate;
+ R operator()(ARGS ...args) const;
+
template <class CLASS, R(CLASS::*METHOD)(ARGS...)>
static WeakDelegate make(const WeakRef<CLASS> &data) noexcept;
namespace ucl {
+ template <class R, class ...ARGS>
+ inline R WeakDelegate<R(ARGS...)>::operator()(ARGS ...args) const
+ {
+ const auto tmp = this->m_data.lock();
+ if (tmp) {
+ return this->m_stubA(tmp.get(), std::forward<ARGS>(args)...);
+ }
+ return R();
+ }
+
template <class R, class ...ARGS>
template <class CLASS, R(CLASS::*METHOD)(ARGS...)>
inline WeakDelegate<R(ARGS...)> WeakDelegate<R(ARGS...)>::make(
#include <string>
#include <memory>
+#include <atomic>
#include <functional>
#include <type_traits>
#include <utility>
namespace ucl {
- ElmWidget::ElmWidget(RefCountObjBase *rc, Evas_Object *eo, bool isOwner) :
+ ElmWidget::ElmWidget(IRefCountObj *rc, Evas_Object *eo, bool isOwner) :
Widget(rc, eo, isOwner),
m_isAtspiGestureCbSet(false)
{
// Naviframe //
- Naviframe::Naviframe(RefCountObjBase &rc, Evas_Object *eo) :
+ Naviframe::Naviframe(IRefCountObj &rc, Evas_Object *eo) :
StyledWidget(&rc, eo, true),
m_isInTransition(false)
{
// Widget //
- Widget::Widget(RefCountObjBase *const rc, Evas_Object *const eo,
+ Widget::Widget(IRefCountObj *const rc, Evas_Object *const eo,
const bool isOwner) :
RefCountAware(rc),
m_eo(eo),
void Widget::updateRefs()
{
- const auto rc = m_rc;
-
updateEoRef();
- if (rc && !rc->isDisposed()) {
+ if (m_rc) {
updateSelfRef();
}
}