Skip to content

Commit

Permalink
more info in manually thrown exceptions, fixed exception handling in …
Browse files Browse the repository at this point in the history
…gcc, refactoring
  • Loading branch information
alabuzhev committed May 12, 2016
1 parent 9df0dfb commit d1a526b
Show file tree
Hide file tree
Showing 55 changed files with 327 additions and 305 deletions.
2 changes: 1 addition & 1 deletion far/PluginA.cpp
Expand Up @@ -112,7 +112,7 @@ class oem_plugin_factory: public native_plugin_factory
oem_plugin_factory(PluginManager* Owner):
native_plugin_factory(Owner)
{
static const plugin_factory::export_name ExportsNames[] =
static const export_name ExportsNames[] =
{
WA(""), // GetGlobalInfo not used
WA("SetStartupInfo"),
Expand Down
4 changes: 2 additions & 2 deletions far/TPreRedrawFunc.hpp
Expand Up @@ -41,7 +41,7 @@ struct PreRedrawItem: noncopyable
typedef std::function<void()> handler_type;

PreRedrawItem(const handler_type& PreRedrawFunc) : m_PreRedrawFunc(PreRedrawFunc) {}
virtual ~PreRedrawItem(){}
virtual ~PreRedrawItem() = default;

handler_type m_PreRedrawFunc;
};
Expand All @@ -57,7 +57,7 @@ class TPreRedrawFunc: noncopyable
private:
friend TPreRedrawFunc& PreRedrawStack();

TPreRedrawFunc() {}
TPreRedrawFunc() = default;
std::stack<std::unique_ptr<PreRedrawItem>> Items;
};

Expand Down
10 changes: 9 additions & 1 deletion far/changelog
@@ -1,4 +1,12 @@
drkns 11.05.2016 23:59:21 +0200 - build 4670
drkns 13.05.2016 00:33:18 +0200 - build 4671

1. Уточнение обработки исключений для gcc.

2. Дополнительная информация в исключениях, брошенных вручную (function, file, line).

3. Рефакторинг.

drkns 11.05.2016 23:59:21 +0200 - build 4670

1. Уточнение обработки DM_GETDIALOGINFО.

Expand Down
72 changes: 36 additions & 36 deletions far/clipboard.cpp
Expand Up @@ -51,16 +51,16 @@ default_clipboard_mode::mode default_clipboard_mode::get()
}

//-----------------------------------------------------------------------------
enum FAR_CLIPBOARD_FORMAT: int
enum class Clipboard::clipboard_format: unsigned
{
FCF_VERTICALBLOCK_OEM,
FCF_VERTICALBLOCK_UNICODE,
FCF_CFSTR_PREFERREDDROPEFFECT,
FCF_MSDEVCOLUMNSELECT,
FCF_BORLANDIDEVBLOCK,
FCF_NOTEPADPLUSPLUS_BINARYTEXTLENGTH,

FCF_COUNT
vertical_block_oem,
vertical_block_unicode,
preferred_drop_effect,
ms_dev_column_select,
borland_ide_dev_block,
notepad_plusplus_binary_text_length,

count
};

//-----------------------------------------------------------------------------
Expand All @@ -75,7 +75,7 @@ class system_clipboard: noncopyable, public Clipboard

virtual ~system_clipboard()
{
Close();
system_clipboard::Close();
}

virtual bool Open() override
Expand Down Expand Up @@ -113,16 +113,16 @@ class system_clipboard: noncopyable, public Clipboard
}

private:
system_clipboard() {}
system_clipboard() = default;

virtual HANDLE GetData(UINT uFormat) const override
virtual HANDLE GetData(unsigned uFormat) const override
{
assert(m_Opened);

return GetClipboardData(uFormat);
}

virtual bool SetData(UINT uFormat, os::memory::global::ptr&& hMem) override
virtual bool SetData(unsigned uFormat, os::memory::global::ptr&& hMem) override
{
assert(m_Opened);

Expand All @@ -142,7 +142,7 @@ class system_clipboard: noncopyable, public Clipboard
return false;
}

virtual UINT RegisterFormat(FAR_CLIPBOARD_FORMAT Format) const override
virtual unsigned RegisterFormat(clipboard_format Format) const override
{
static const wchar_t* FormatNames[] =
{
Expand All @@ -154,12 +154,12 @@ class system_clipboard: noncopyable, public Clipboard
L"Notepad++ binary text length",
};

static_assert(std::size(FormatNames) == FCF_COUNT, "Wrong size of FormatNames");
assert(Format < FCF_COUNT);
return RegisterClipboardFormat(FormatNames[Format]);
static_assert(std::size(FormatNames) == static_cast<unsigned>(clipboard_format::count), "Wrong size of FormatNames");
assert(Format < clipboard_format::count);
return RegisterClipboardFormat(FormatNames[static_cast<unsigned>(Format)]);
}

virtual bool IsFormatAvailable(UINT Format) const override
virtual bool IsFormatAvailable(unsigned Format) const override
{
return IsClipboardFormatAvailable(Format) != FALSE;
}
Expand All @@ -177,7 +177,7 @@ class internal_clipboard: noncopyable, public Clipboard

virtual ~internal_clipboard()
{
Close();
internal_clipboard::Close();
}

virtual bool Open() override
Expand Down Expand Up @@ -212,9 +212,9 @@ class internal_clipboard: noncopyable, public Clipboard
}

private:
internal_clipboard() {}
internal_clipboard() = default;

virtual HANDLE GetData(UINT uFormat) const override
virtual HANDLE GetData(unsigned uFormat) const override
{
assert(m_Opened);

Expand All @@ -227,7 +227,7 @@ class internal_clipboard: noncopyable, public Clipboard
return nullptr;
}

virtual bool SetData(UINT uFormat, os::memory::global::ptr&& hMem) override
virtual bool SetData(unsigned uFormat, os::memory::global::ptr&& hMem) override
{
assert(m_Opened);

Expand All @@ -239,17 +239,17 @@ class internal_clipboard: noncopyable, public Clipboard
return false;
}

virtual UINT RegisterFormat(FAR_CLIPBOARD_FORMAT Format) const override
virtual unsigned RegisterFormat(clipboard_format Format) const override
{
return Format + 0xFC; // magic number stands for "Far Clipboard"
return static_cast<unsigned>(Format) + 0xFC; // magic number stands for "Far Clipboard"
}

virtual bool IsFormatAvailable(UINT Format) const override
virtual bool IsFormatAvailable(unsigned Format) const override
{
return Format && m_InternalData.count(Format);
}

std::unordered_map<UINT, os::memory::global::ptr> m_InternalData;
std::unordered_map<unsigned, os::memory::global::ptr> m_InternalData;
};

//-----------------------------------------------------------------------------
Expand All @@ -270,7 +270,7 @@ bool Clipboard::SetText(const wchar_t *Data, size_t Size)
{
// 'Notepad++ binary text length'
auto binary_length = static_cast<uint32_t>(Size);
SetData(RegisterFormat(FCF_NOTEPADPLUSPLUS_BINARYTEXTLENGTH), os::memory::global::copy(binary_length));
SetData(RegisterFormat(clipboard_format::notepad_plusplus_binary_text_length), os::memory::global::copy(binary_length));
}
}
else
Expand All @@ -287,7 +287,7 @@ bool Clipboard::SetVText(const wchar_t *Data, size_t Size)

if (Result && Data)
{
const auto FarVerticalBlock = RegisterFormat(FCF_VERTICALBLOCK_UNICODE);
const auto FarVerticalBlock = RegisterFormat(clipboard_format::vertical_block_unicode);

if (!FarVerticalBlock)
return false;
Expand All @@ -296,9 +296,9 @@ bool Clipboard::SetVText(const wchar_t *Data, size_t Size)

// 'Borland IDE Block Type'
char Cx02 = '\x02';
SetData(RegisterFormat(FCF_BORLANDIDEVBLOCK), os::memory::global::copy(Cx02));
SetData(RegisterFormat(clipboard_format::borland_ide_dev_block), os::memory::global::copy(Cx02));
// 'MSDEVColumnSelect'
SetData(RegisterFormat(FCF_MSDEVCOLUMNSELECT), nullptr);
SetData(RegisterFormat(clipboard_format::ms_dev_column_select), nullptr);
}
return Result;
}
Expand Down Expand Up @@ -326,7 +326,7 @@ bool Clipboard::SetHDROP(const string& NamesData, bool bMoved)
{
if (auto hMemoryMove = os::memory::global::copy<DWORD>(DROPEFFECT_MOVE))
{
if(SetData(RegisterFormat(FCF_CFSTR_PREFERREDDROPEFFECT), std::move(hMemoryMove)))
if(SetData(RegisterFormat(clipboard_format::preferred_drop_effect), std::move(hMemoryMove)))
{
Result = true;
}
Expand All @@ -352,7 +352,7 @@ bool Clipboard::GetText(string& data) const
Result = true;
data = ClipAddr.get();
size_t len = string::npos;
if (auto hClipDataLen = GetData(RegisterFormat(FCF_NOTEPADPLUSPLUS_BINARYTEXTLENGTH)))
if (auto hClipDataLen = GetData(RegisterFormat(clipboard_format::notepad_plusplus_binary_text_length)))
{
if (const auto ClipLength = os::memory::global::lock<const uint32_t*>(hClipDataLen))
len = static_cast<size_t>(ClipLength.get()[0]);
Expand Down Expand Up @@ -405,16 +405,16 @@ bool Clipboard::GetVText(string& data) const
{
bool Result = false;

bool ColumnSelect = IsFormatAvailable(RegisterFormat(FCF_VERTICALBLOCK_UNICODE));
bool ColumnSelect = IsFormatAvailable(RegisterFormat(clipboard_format::vertical_block_unicode));

if (!ColumnSelect)
{
ColumnSelect = IsFormatAvailable(RegisterFormat(FCF_MSDEVCOLUMNSELECT));
ColumnSelect = IsFormatAvailable(RegisterFormat(clipboard_format::ms_dev_column_select));
}

if (!ColumnSelect)
{
if (const auto hClipData = GetData(RegisterFormat(FCF_BORLANDIDEVBLOCK)))
if (const auto hClipData = GetData(RegisterFormat(clipboard_format::borland_ide_dev_block)))
if (const auto ClipAddr = os::memory::global::lock<const char*>(hClipData))
ColumnSelect = *ClipAddr == 0x02;
}
Expand All @@ -425,7 +425,7 @@ bool Clipboard::GetVText(string& data) const
}
else
{
const auto Far1xVerticalBlock = RegisterFormat(FCF_VERTICALBLOCK_OEM);
const auto Far1xVerticalBlock = RegisterFormat(clipboard_format::vertical_block_oem);
if (const auto hClipData = GetData(Far1xVerticalBlock))
{
if (const auto OemData = os::memory::global::lock<const char*>(hClipData))
Expand Down
16 changes: 7 additions & 9 deletions far/clipboard.hpp
Expand Up @@ -46,13 +46,11 @@ class default_clipboard_mode
static mode m_Mode;
};

enum FAR_CLIPBOARD_FORMAT: int;

class Clipboard
{
public:
static Clipboard& GetInstance(default_clipboard_mode::mode Mode);
virtual ~Clipboard() {}
virtual ~Clipboard() = default;

virtual bool Open() = 0;
virtual bool Close() = 0;
Expand All @@ -72,15 +70,15 @@ class Clipboard
bool GetVText(string& data) const;

protected:
Clipboard(): m_Opened() {}
enum class clipboard_format: unsigned;

bool m_Opened;
bool m_Opened {};

private:
virtual bool SetData(UINT uFormat, os::memory::global::ptr&& hMem) = 0;
virtual HANDLE GetData(UINT uFormat) const = 0;
virtual UINT RegisterFormat(FAR_CLIPBOARD_FORMAT Format) const = 0;
virtual bool IsFormatAvailable(UINT Format) const = 0;
virtual bool SetData(unsigned uFormat, os::memory::global::ptr&& hMem) = 0;
virtual HANDLE GetData(unsigned uFormat) const = 0;
virtual unsigned RegisterFormat(clipboard_format Format) const = 0;
virtual bool IsFormatAvailable(unsigned Format) const = 0;

bool GetHDROPAsText(string& data) const;
};
Expand Down
3 changes: 2 additions & 1 deletion far/common.hpp
Expand Up @@ -39,6 +39,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "common/compiler.hpp"
#include "common/preprocessor.hpp"
#include "common/exception.hpp"
#include "common/noncopyable.hpp"
#include "common/swapable.hpp"
#include "common/rel_ops.hpp"
Expand Down Expand Up @@ -199,7 +200,7 @@ class writable_blob: public blob
if (m_Data)
{
if (size() != rhs.size())
throw std::runtime_error("incorrect blob size");
throw MAKE_FAR_EXCEPTION("incorrect blob size");
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions far/common/any.hpp
Expand Up @@ -37,7 +37,7 @@ namespace detail
class any_base
{
public:
virtual ~any_base() {}
virtual ~any_base() = default;
virtual std::unique_ptr<any_base> clone() const = 0;
};

Expand Down Expand Up @@ -82,7 +82,7 @@ class any

any& operator=(const any& rhs)
{
any Tmp(rhs);
auto Tmp(rhs);
using std::swap;
swap(*this, Tmp);
return *this;
Expand Down Expand Up @@ -137,7 +137,7 @@ T& any_cast(any& Any)
const auto Result = any_cast<T>(&Any);
if (!Result)
{
throw std::bad_cast();
throw MAKE_FAR_EXCEPTION("bad any_cast");
}
return *Result;
}
Expand Down
6 changes: 3 additions & 3 deletions far/common/enum_substrings.hpp
Expand Up @@ -60,15 +60,15 @@ class enum_substrings_t: public enumerator<enum_substrings_t<provider>, range<de
NONCOPYABLE(enum_substrings_t);
TRIVIALLY_MOVABLE(enum_substrings_t);

enum_substrings_t(const provider& Provider): m_Provider(&Provider), m_Offset() {}
explicit enum_substrings_t(const provider& Provider): m_Provider(&Provider), m_Offset() {}

bool get(size_t Index, typename enum_substrings_t<provider>::value_type& Value)
{
const auto Begin = detail::Begin(*m_Provider) + (Index? m_Offset : 0);
auto End = Begin;
bool IsEnd;
for (; (IsEnd = detail::IsEnd(*m_Provider, End)) == false && *End; ++End);

for (; (IsEnd = detail::IsEnd(*m_Provider, End)) == false && *End; ++End)
;
if (End != Begin)
{
const auto Ptr = &*Begin;
Expand Down
10 changes: 5 additions & 5 deletions far/common/enumerator.hpp
Expand Up @@ -41,9 +41,10 @@ class enumerator
class const_iterator: public std::iterator<std::forward_iterator_tag, T>
{
public:
typedef const T value_type;
using value_type = const T;

const_iterator(Derived* collection = nullptr, size_t index = -1): m_collection(collection), m_index(index), m_value() {}
const_iterator(Derived* collection, size_t index): m_collection(collection), m_index(index), m_value() {}
const_iterator(): const_iterator(nullptr, -1) {}
const_iterator(const const_iterator& rhs): m_collection(rhs.m_collection), m_index(rhs.m_index), m_value(rhs.m_value) {}
const_iterator& operator =(const const_iterator& rhs) { m_collection = rhs.m_collection; m_index = rhs.m_index; m_value = rhs.m_value; return *this;}
value_type* operator ->() const { return &m_value; }
Expand All @@ -63,10 +64,9 @@ class enumerator
class iterator: public const_iterator
{
public:
typedef T value_type;
using value_type = T;
using const_iterator::const_iterator;

iterator(Derived* collection = nullptr, size_t index = -1): const_iterator(collection, index) {}
iterator(const iterator& rhs): const_iterator(rhs) {}
value_type* operator ->() { return const_cast<T*>(const_iterator::operator->()); }
value_type& operator *() { return const_cast<T&>(const_iterator::operator*()); }
iterator& operator ++() { const_iterator::operator++(); return *this; }
Expand Down

0 comments on commit d1a526b

Please sign in to comment.