a standard experimental class any

This commit is contained in:
Jinhao
2016-01-25 23:56:05 +08:00
parent 7dbf0a5769
commit 5a960ed88c
16 changed files with 272 additions and 232 deletions

View File

@@ -1,70 +1,87 @@
#include <nana/any.hpp>
/**
* Any
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* @file nana/any.cpp
*
* @brief An implementation of experimental library any of C++ standard(http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4480.html#any)
*/
#include <nana/any.hpp>
#include <utility>
namespace nana
{
//constructors and destructor
any::any() noexcept
: content_(nullptr)
{
}
//class any
//struct super_type
any::super_type::~super_type(){}
any::super_type& any::super_type::operator=(const super_type &rhs)
{
return assign(rhs);
}
//end struct super_type
any::any(const any& other)
: content_(other.content_ ? other.content_->clone() : nullptr)
{}
any::any()
:super_(nullptr)
{}
any::any(const any& rhs)
:super_(rhs.super_ ? rhs.super_->clone() : nullptr)
{}
any::any(any && other) noexcept
: content_(other.content_)
{
other.content_ = nullptr;
}
any::any(any&& r)
:super_(r.super_)
{
r.super_ = nullptr;
}
any::~any()
{
delete super_;
}
any& any::operator=(const any& rhs)
{
if(this != &rhs)
{
delete super_;
super_ = (rhs.super_ ? rhs.super_->clone() : nullptr);
}
return *this;
}
any::~any()
{
delete content_;
}
any& any::operator=(any&& r)
{
if(this != &r)
{
delete super_;
super_ = r.super_;
r.super_ = nullptr;
}
return *this;
}
//assignments
any& any::operator=(const any& other)
{
if (this != &other)
any(other).swap(*this);
bool any::same(const any &rhs) const
return *this;
}
any& any::operator=(any&& other) noexcept
{
if (this != &other)
{
if(this != &rhs)
{
if(super_ && rhs.super_)
return super_->same(*rhs.super_);
else if(super_ || rhs.super_)
return false;
}
return true;
other.swap(*this);
other.clear();
}
//end class any
return *this;
}
//modifiers
void any::clear() noexcept
{
if (content_)
{
auto cnt = content_;
content_ = nullptr;
delete cnt;
}
}
void any::swap(any& other) noexcept
{
std::swap(content_, other.content_);
}
//observers
bool any::empty() const noexcept
{
return (nullptr == content_);
}
const std::type_info& any::type() const noexcept
{
return (content_ ? content_->type() : typeid(void));
}
}//end namespace nana

View File

@@ -1,7 +1,7 @@
/*
* Platform Specification Implementation
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com)
* Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Nana Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
@@ -36,7 +36,7 @@ namespace nana
namespace detail
{
typedef native_window_type native_window_type;
#if defined(NANA_UNICODE)
#if defined(NANA_USE_XFT)
//class conf
conf::conf(const char * file)
{
@@ -290,7 +290,7 @@ namespace detail
string.tab_length = 4;
string.tab_pixels = 0;
string.whitespace_pixels = 0;
#if defined(NANA_UNICODE)
#if defined(NANA_USE_XFT)
conv_.handle = ::iconv_open("UTF-8", "UTF-32");
conv_.code = "UTF-32";
#endif
@@ -298,7 +298,7 @@ namespace detail
drawable_impl_type::~drawable_impl_type()
{
#if defined(NANA_UNICODE)
#if defined(NANA_USE_XFT)
::iconv_close(conv_.handle);
#endif
}
@@ -366,7 +366,7 @@ namespace detail
::XSetForeground(spec.open_display(), context, col);
::XSetBackground(spec.open_display(), context, col);
#if defined(NANA_UNICODE)
#if defined(NANA_USE_XFT)
xft_fgcolor.color.red = ((0xFF0000 & col) >> 16) * 0x101;
xft_fgcolor.color.green = ((0xFF00 & col) >> 8) * 0x101;
xft_fgcolor.color.blue = (0xFF & col) * 0x101;
@@ -395,7 +395,7 @@ namespace detail
}
::XSetForeground(spec.open_display(), context, rgb);
::XSetBackground(spec.open_display(), context, rgb);
#if defined(NANA_UNICODE)
#if defined(NANA_USE_XFT)
xft_fgcolor.color.red = ((0xFF0000 & rgb) >> 16) * 0x101;
xft_fgcolor.color.green = ((0xFF00 & rgb) >> 8) * 0x101;
xft_fgcolor.color.blue = (0xFF & rgb) * 0x101;
@@ -412,7 +412,7 @@ namespace detail
if(fp && fp->handle)
{
platform_scope_guard psg;
#if defined(NANA_UNICODE)
#if defined(NANA_USE_XFT)
::XftFontClose(nana::detail::platform_spec::instance().open_display(), fp->handle);
#else
::XFreeFontSet(nana::detail::platform_spec::instance().open_display(), fp->handle);

View File

@@ -1,7 +1,7 @@
/*
* A Bedrock Implementation
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com)
* Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
@@ -993,7 +993,7 @@ namespace detail
if(input_context)
{
nana::detail::platform_scope_guard psg;
#if defined(NANA_UNICODE)
#if 1 //Utf8
len = ::Xutf8LookupString(input_context, &xevent.xkey, keybuf, 32, &keysym, &status);
if(status == XBufferOverflow)
{
@@ -1088,14 +1088,12 @@ namespace detail
if (msgwnd->flags.enabled)
{
const wchar_t* charbuf;
#if defined(NANA_UNICODE)
nana::detail::charset_conv charset("UTF-32", "UTF-8");
const std::string& str = charset.charset(std::string(keybuf, keybuf + len));
charbuf = reinterpret_cast<const wchar_t*>(str.c_str()) + 1;
len = str.size() / sizeof(wchar_t) - 1;
#else
charbuf = keybuf;
#endif
for(int i = 0; i < len; ++i)
{
arg_keyboard arg;

View File

@@ -202,8 +202,8 @@ namespace nana
ls_file_.events().mouse_down.connect_unignorable(fn_sel_file);
ls_file_.set_sort_compare(0, [](const std::string& a, nana::any* fs_a, const std::string& b, nana::any* fs_b, bool reverse) -> bool
{
int dira = fs_a->get<item_fs>()->directory ? 1 : 0;
int dirb = fs_b->get<item_fs>()->directory ? 1 : 0;
int dira = any_cast<item_fs>(fs_a)->directory ? 1 : 0;
int dirb = any_cast<item_fs>(fs_b)->directory ? 1 : 0;
if(dira != dirb)
return (reverse ? dira < dirb : dira > dirb);
@@ -256,8 +256,8 @@ namespace nana
});
ls_file_.set_sort_compare(2, [](const std::string& a, nana::any* anyptr_a, const std::string& b, nana::any* anyptr_b, bool reverse) -> bool
{
int dir1 = anyptr_a->get<item_fs>()->directory ? 1 : 0;
int dir2 = anyptr_b->get<item_fs>()->directory ? 1 : 0;
int dir1 = any_cast<item_fs>(anyptr_a)->directory ? 1 : 0;
int dir2 = any_cast<item_fs>(anyptr_b)->directory ? 1 : 0;
if(dir1 != dir2)
return (reverse ? dir1 < dir2 : dir1 > dir2);
@@ -265,8 +265,8 @@ namespace nana
});
ls_file_.set_sort_compare(3, [this](const std::string&, nana::any* anyptr_a, const std::string&, nana::any* anyptr_b, bool reverse) -> bool
{
item_fs * fsa = anyptr_a->get<item_fs>();
item_fs * fsb = anyptr_b->get<item_fs>();
item_fs * fsa = any_cast<item_fs>(anyptr_a);
item_fs * fsb = any_cast<item_fs>(anyptr_b);
return (reverse ? fsa->bytes > fsb->bytes : fsa->bytes < fsb->bytes);
});

View File

@@ -1,7 +1,7 @@
/*
* A List Box Implementation
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com)
* Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,7 +1,7 @@
/*
* Platform Implementation
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com)
* Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
@@ -137,7 +137,7 @@ namespace detail
if(::GetTextExtentPoint32(dw->context, text, static_cast<int>(len), &size))
return nana::size(size.cx, size.cy);
#elif defined(NANA_X11)
#if defined(NANA_UNICODE)
#if defined(NANA_USE_XFT)
std::string utf8str = to_utf8(std::wstring(text, len));
XGlyphInfo ext;
XftFont * fs = reinterpret_cast<XftFont*>(dw->font->handle);
@@ -179,7 +179,7 @@ namespace detail
::TextOut(dw->context, pos.x, pos.y, str, static_cast<int>(len));
#elif defined(NANA_X11)
auto disp = ::nana::detail::platform_spec::instance().open_display();
#if defined(NANA_UNICODE)
#if defined(NANA_USE_XFT)
auto fs = reinterpret_cast<XftFont*>(dw->font->handle);
//Fixed missing array declaration by dareg

View File

@@ -1,7 +1,7 @@
/*
* Paint Graphics Implementation
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com)
* Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
@@ -40,7 +40,7 @@ namespace paint
if(p)
{
Display* disp = reinterpret_cast<Display*>(nana::detail::platform_spec::instance().open_display());
#if defined(NANA_UNICODE)
#if defined(NANA_USE_XFT)
::XftDrawDestroy(p->xftdraw);
#endif
::XFreeGC(disp, p->context);
@@ -306,7 +306,7 @@ namespace paint
Window root = ::XRootWindow(disp, screen);
dw->pixmap = ::XCreatePixmap(disp, root, (sz.width ? sz.width : 1), (sz.height ? sz.height : 1), DefaultDepth(disp, screen));
dw->context = ::XCreateGC(disp, dw->pixmap, 0, 0);
#if defined(NANA_UNICODE)
#if defined(NANA_USE_XFT)
dw->xftdraw = ::XftDrawCreate(disp, dw->pixmap, spec.screen_visual(), spec.colormap());
#endif
#endif
@@ -442,7 +442,8 @@ namespace paint
pxbuf[i] = (str[i] == '\t' ? tab_pixels : dx[i] - dx[i - 1]);
}
delete [] dx;
#elif defined(NANA_X11)
#elif defined(NANA_X11) && defined(NANA_USE_XFT)
Display * disp = nana::detail::platform_spec::instance().open_display();
XftFont * xft = handle_->font->handle;
@@ -465,7 +466,6 @@ namespace paint
nana::size graphics::bidi_extent_size(const std::wstring& str) const
{
nana::size sz;
#if defined NANA_UNICODE
if(handle_ && handle_->context && str.size())
{
std::vector<unicode_bidi::entity> reordered;
@@ -479,7 +479,6 @@ namespace paint
sz.height = t.height;
}
}
#endif
return sz;
}
@@ -502,7 +501,7 @@ namespace paint
#elif defined(NANA_X11)
if(handle_->font)
{
#if defined(NANA_UNICODE)
#if defined(NANA_USE_XFT)
XftFont * fs = reinterpret_cast<XftFont*>(handle_->font->handle);
ascent = fs->ascent;
descent = fs->descent;