Skip to content

Commit

Permalink
fix 4603: no '?' for empty owner, minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Mar 31, 2016
1 parent 842c3de commit fd29461
Show file tree
Hide file tree
Showing 18 changed files with 65 additions and 60 deletions.
8 changes: 7 additions & 1 deletion far/changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
drkns 29.03.2016 19:15:04 +0200 - build 4607
drkns 31.03.2016 10:00:26 +0200 - build 4608

1. Уточнение 4603. Не показываем "?" если владелец не определён.

2. Прочий мелкий рефакторинг.

drkns 29.03.2016 19:15:04 +0200 - build 4607

1. Уточнение 4603. Возвращаем плагинам перечисленное только если оно уже считано.

Expand Down
2 changes: 1 addition & 1 deletion far/codepage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

namespace unicode
{
#define NOT_PTR(T) typename T, std::enable_if_t<!std::is_pointer<T>::value>* = nullptr
#define NOT_PTR(T) typename T, ENABLE_IF(!std::is_pointer<T>::value)

size_t to(uintptr_t Codepage, const wchar_t* Data, size_t Size, char* Buffer, size_t BufferSize, bool* UsedDefaultChar = nullptr);
template<NOT_PTR(T)>
Expand Down
16 changes: 8 additions & 8 deletions far/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,23 @@ inline std::wostream& operator <<(std::wostream& stream, const write_exact& p)
}

template<class T>
inline void resize_nomove(T& container, size_t size)
void resize_nomove(T& container, size_t size)
{
T Tmp(size);
using std::swap;
swap(container, Tmp);
}

template<class T>
inline void clear_and_shrink(T& container)
void clear_and_shrink(T& container)
{
T Tmp;
using std::swap;
swap(container, Tmp);
}

template<class T>
inline void node_swap(T& Container, const typename T::const_iterator& a, const typename T::const_iterator& b)
void node_swap(T& Container, const typename T::const_iterator& a, const typename T::const_iterator& b)
{
const auto NextA = std::next(a), NextB = std::next(b);
Container.splice(NextA, Container, b);
Expand All @@ -108,27 +108,27 @@ template <typename T>
bool CheckStructSize(const T* s) {return s && (s->StructSize >= sizeof(T));}

template<typename T>
inline void ClearStruct(T& s) noexcept
void ClearStruct(T& s) noexcept
{
static_assert(!std::is_pointer<T>::value, "This template requires a reference to an object");
static_assert(std::is_pod<T>::value, "This template requires a POD type");
memset(&s, 0, sizeof(s));
}

template<typename T, size_t N>
inline void ClearArray(T(&a)[N]) noexcept
void ClearArray(T(&a)[N]) noexcept
{
static_assert(std::is_pod<T>::value, "This template requires a POD type");
memset(a, 0, sizeof(a));
}

template<class T>
inline auto NullToEmpty(const T* Str) { static const T empty {}; return Str? Str : &empty; }
auto NullToEmpty(const T* Str) { static const T empty {}; return Str? Str : &empty; }
template<class T>
inline auto EmptyToNull(const T* Str) { return (Str && !*Str)? nullptr : Str; }
auto EmptyToNull(const T* Str) { return (Str && !*Str)? nullptr : Str; }

template<class T>
inline size_t make_hash(const T& value)
size_t make_hash(const T& value)
{
return std::hash<T>()(value);
}
Expand Down
4 changes: 2 additions & 2 deletions far/common/any.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ class any
}

private:
template<class T>
static std::enable_if_t<!std::is_same<std::decay_t<T>, any>::value, std::unique_ptr<detail::any_base>> construct(T&& rhs)
template<class T, ENABLE_IF(!std::is_same<std::decay_t<T>, any>::value)>
static std::unique_ptr<detail::any_base> construct(T&& rhs)
{
return std::make_unique<detail::any_impl<std::decay_t<T>>>(std::forward<T>(rhs));
}
Expand Down
6 changes: 3 additions & 3 deletions far/common/iterator_range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class range
};

template<class iterator_type>
inline range<iterator_type> make_range(iterator_type i_begin, iterator_type i_end)
auto make_range(iterator_type i_begin, iterator_type i_end)
{
return range<iterator_type>(i_begin, i_end);
}
Expand Down Expand Up @@ -108,13 +108,13 @@ class i_iterator: public std::iterator<std::random_access_iterator_tag, T>, publ
};

template<class T>
inline range<i_iterator<T>> make_irange(T i_begin, T i_end)
auto make_irange(T i_begin, T i_end)
{
return range<i_iterator<T>>(i_begin, i_end);
}

template<class T>
inline range<i_iterator<T>> make_irange(T i_end)
auto make_irange(T i_end)
{
return range<i_iterator<T>>(0, i_end);
}
Expand Down
2 changes: 2 additions & 0 deletions far/common/preprocessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,6 @@ const RAII_type ANONYMOUS_VARIABLE(scoped_object_)
#define STR(x) #x
#define WSTR(x) L###x

#define ENABLE_IF(...) std::enable_if_t<__VA_ARGS__>* = nullptr

#endif // PREPROCESSOR_HPP_35FF3F1D_40F4_4741_9366_6A0723C14CBB
15 changes: 9 additions & 6 deletions far/common/smart_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,18 @@ class unique_ptr_with_ondestroy: public conditional<unique_ptr_with_ondestroy<T>
std::unique_ptr<T> ptr;
};

struct file_closer
namespace detail
{
void operator()(FILE* Object) const
struct file_closer
{
fclose(Object);
}
};
void operator()(FILE* Object) const
{
fclose(Object);
}
};
}

typedef std::unique_ptr<FILE, file_closer> file_ptr;
typedef std::unique_ptr<FILE, detail::file_closer> file_ptr;

namespace detail
{
Expand Down
15 changes: 6 additions & 9 deletions far/configdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ class GeneralConfig: public representable, virtual public transactional
virtual bool SetValue(const string& Key, const string& Name, const wchar_t* Value) = 0;
virtual bool SetValue(const string& Key, const string& Name, unsigned __int64 Value) = 0;
virtual bool SetValue(const string& Key, const string& Name, const blob& Value) = 0;
template<class T>
std::enable_if_t<!std::is_pointer<T>::value && !std::is_integral<T>::value, bool>
SetValue(const string& Key, const string& Name, const T& Value)
template<class T, ENABLE_IF(!std::is_pointer<T>::value && !std::is_integral<T>::value)>
bool SetValue(const string& Key, const string& Name, const T& Value)
{
static_assert(std::is_pod<T>::value, "This template requires a POD type");
return SetValue(Key, Name, &Value, sizeof(Value));
Expand Down Expand Up @@ -129,9 +128,8 @@ class HierarchicalConfig: public representable, virtual public transactional, pu
virtual bool SetValue(const key& Root, const string& Name, const wchar_t* Value) = 0;
virtual bool SetValue(const key& Root, const string& Name, unsigned long long Value) = 0;
virtual bool SetValue(const key& Root, const string& Name, const blob& Value) = 0;
template<class T>
std::enable_if_t<!std::is_pointer<T>::value && !std::is_integral<T>::value, bool>
SetValue(const key& Root, const string& Name, const T& Value)
template<class T, ENABLE_IF(!std::is_pointer<T>::value && !std::is_integral<T>::value)>
bool SetValue(const key& Root, const string& Name, const T& Value)
{
static_assert(std::is_pod<T>::value, "This template requires a POD type");
return SetValue(Root, Name, blob(&Value, sizeof(Value)));
Expand All @@ -140,9 +138,8 @@ class HierarchicalConfig: public representable, virtual public transactional, pu
virtual bool GetValue(const key& Root, const string& Name, unsigned long long& Value) = 0;
virtual bool GetValue(const key& Root, const string& Name, string &strValue) = 0;
virtual bool GetValue(const key& Root, const string& Name, writable_blob& Value) = 0;
template<class T>
std::enable_if_t<!std::is_pointer<T>::value && !std::is_integral<T>::value, bool>
GetValue(const key& Root, const string& Name, T& Value)
template<class T, ENABLE_IF(!std::is_pointer<T>::value && !std::is_integral<T>::value)>
bool GetValue(const key& Root, const string& Name, T& Value)
{
static_assert(std::is_pod<T>::value, "This template requires a POD type");
writable_blob Blob(&Value, sizeof(Value));
Expand Down
2 changes: 1 addition & 1 deletion far/dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ bool IsKeyHighlighted(const string& Str, int Key, int Translate, int AmpPos = -1
void ItemToItemEx(const FarDialogItem *Data, DialogItemEx *Item, size_t Count, bool Short = false);

template<size_t N>
std::vector<DialogItemEx> MakeDialogItemsEx(const FarDialogItem (&InitData)[N])
auto MakeDialogItemsEx(const FarDialogItem (&InitData)[N])
{
std::vector<DialogItemEx> Items(N);
ItemToItemEx(InitData, Items.data(), N);
Expand Down
8 changes: 4 additions & 4 deletions far/elevation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ bool elevation::Write(const void* Data,size_t DataSize) const
}

template<typename T>
inline bool elevation::Read(T& Data) const
bool elevation::Read(T& Data) const
{
return pipe::Read(m_pipe.native_handle(), Data);
}

template<typename T>
inline bool elevation::Write(const T& Data) const
bool elevation::Write(const T& Data) const
{
return pipe::Write(m_pipe.native_handle(), Data);
}
Expand Down Expand Up @@ -941,13 +941,13 @@ class elevated:noncopyable
}

template<typename T>
inline bool Read(T& Data) const
bool Read(T& Data) const
{
return pipe::Read(m_Pipe.native_handle(), Data);
}

template<typename T>
inline bool Write(const T& Data) const
bool Write(const T& Data) const
{
return pipe::Write(m_Pipe.native_handle(), Data);
}
Expand Down
4 changes: 2 additions & 2 deletions far/elevation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ class elevation: noncopyable
private:
bool Write(const void* Data, size_t DataSize) const;
template<typename T>
inline bool Read(T& Data) const;
bool Read(T& Data) const;
template<typename T>
inline bool Write(const T& Data) const;
bool Write(const T& Data) const;
bool SendCommand(ELEVATION_COMMAND Command);
bool ReceiveLastError() const;
bool Initialize();
Expand Down
12 changes: 6 additions & 6 deletions far/farwinapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ namespace os
bool get_variable(const wchar_t* Name, string& strBuffer);
inline bool get_variable(const string& Name, string& strBuffer) { return get_variable(Name.data(), strBuffer); }
template<class T>
inline string get_variable(const T& Name) { string Result; get_variable(Name, Result); return Result; }
string get_variable(const T& Name) { string Result; get_variable(Name, Result); return Result; }

bool set_variable(const wchar_t* Name, const wchar_t* Value);
inline bool set_variable(const wchar_t* Name, const string& Value) { return set_variable(Name, Value.data()); }
Expand Down Expand Up @@ -565,10 +565,10 @@ namespace os
using lock_t = std::unique_ptr<std::remove_pointer_t<T>, detail::unlocker>;

template<class T>
lock_t<T> lock(HGLOBAL Ptr) { return lock_t<T>(static_cast<T>(GlobalLock(Ptr))); }
auto lock(HGLOBAL Ptr) { return lock_t<T>(static_cast<T>(GlobalLock(Ptr))); }

template<class T>
lock_t<T> lock(const ptr& Ptr) { return lock<T>(Ptr.get()); }
auto lock(const ptr& Ptr) { return lock<T>(Ptr.get()); }

template<class T>
ptr copy(const T& Object)
Expand Down Expand Up @@ -612,10 +612,10 @@ namespace os
using ptr_t = std::unique_ptr<T, detail::deleter>;

template<class T>
inline ptr_t<T> ptr(T* Pointer) { return ptr_t<T>(Pointer); }
auto ptr(T* Pointer) { return ptr_t<T>(Pointer); }

template<class T>
inline ptr_t<T> alloc(UINT Flags, size_t size) { return ptr(static_cast<T*>(LocalAlloc(Flags, size))); }
auto alloc(UINT Flags, size_t size) { return ptr(static_cast<T*>(LocalAlloc(Flags, size))); }
};

bool is_pointer(const void* Address);
Expand All @@ -632,7 +632,7 @@ namespace os
using ptr_t = std::unique_ptr<T, detail::deleter<T>>;

template<class T>
ptr_t<T> ptr(T* RawPtr) { return ptr_t<T>(RawPtr); }
auto ptr(T* RawPtr) { return ptr_t<T>(RawPtr); }
}
}

Expand Down
21 changes: 9 additions & 12 deletions far/filelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8678,38 +8678,35 @@ void FileList::ShowList(int ShowStatus,int StartColumn)

case OWNER_COLUMN:
{
auto Owner = m_ListData[ListPos].Owner(this).data();
const auto& Owner = m_ListData[ListPos].Owner(this);
size_t Offset = 0;

if (!*Owner)
if (!(Columns[K].type & COLUMN_FULLOWNER) && m_PanelMode != panel_mode::PLUGIN_PANEL)
{
Owner = L"?";
}
else if (!(Columns[K].type & COLUMN_FULLOWNER) && m_PanelMode != panel_mode::PLUGIN_PANEL)
{
const auto SlashPos = FindSlash(m_ListData[ListPos].Owner(this));
const auto SlashPos = FindSlash(Owner);
if (SlashPos != string::npos)
{
Owner += SlashPos + 1;
Offset = SlashPos + 1;
}
}
else if(IsSlash(*Owner))
else if(!Owner.empty() && IsSlash(Owner.front()))
{
Owner++;
Offset = 1;
}

int CurLeftPos=0;

if (!ShowStatus && LeftPos>0)
{
int Length=StrLength(Owner);
int Length = static_cast<int>(Owner.size() - Offset);
if (Length>ColumnWidth)
{
CurLeftPos = std::min(LeftPos, Length-ColumnWidth);
MaxLeftPos = std::max(MaxLeftPos, CurLeftPos);
}
}

Global->FS << fmt::LeftAlign()<<fmt::ExactWidth(ColumnWidth)<<Owner+CurLeftPos;
Global->FS << fmt::LeftAlign()<<fmt::ExactWidth(ColumnWidth)<< Owner.data() + Offset + CurLeftPos;
break;
}

Expand Down
2 changes: 1 addition & 1 deletion far/strmix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ S BlobToHexStringT(const void* Blob, size_t Size, C Separator)
}

template<class C>
std::vector<char> HexStringToBlobT(const C* Hex, size_t Size, C Separator)
auto HexStringToBlobT(const C* Hex, size_t Size, C Separator)
{
std::vector<char> Blob;
Blob.reserve((Size + 1) / 3);
Expand Down
2 changes: 1 addition & 1 deletion far/strmix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ inline std::string narrow(const wchar_t *str, uintptr_t codepage = CP_OEMCP) { r
inline std::string narrow(const string& str, uintptr_t codepage = CP_OEMCP) { return narrow_n(str.data(), str.size(), codepage); }

template<class T>
inline std::string Utf8String(const T& Str) { return narrow(Str, CP_UTF8); }
std::string Utf8String(const T& Str) { return narrow(Str, CP_UTF8); }

string str_printf(const wchar_t * format, ...);
string str_vprintf(const wchar_t * format, va_list argptr);
Expand Down
2 changes: 1 addition & 1 deletion far/synchro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ template<class T> class lock_guard: noncopyable
typedef lock_guard<CriticalSection> CriticalSectionLock;

template<class T, class S>
inline string make_name(const S& HashPart, const S& TextPart)
string make_name(const S& HashPart, const S& TextPart)
{
auto Str = T::GetNamespace() + std::to_wstring(make_hash(HashPart)) + L"_" + TextPart;
ReplaceBackslashToSlash(Str);
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
Original file line number Diff line number Diff line change
@@ -1 +1 @@
m4_define(BUILD,4607)m4_dnl
m4_define(BUILD,4608)m4_dnl
2 changes: 1 addition & 1 deletion far/vc_crt_fix_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endif // END FAR_USE_INTERNALS

template<typename T>
inline T GetFunctionPointer(const wchar_t* ModuleName, const char* FunctionName, T Replacement)
T GetFunctionPointer(const wchar_t* ModuleName, const char* FunctionName, T Replacement)
{
const auto Address = GetProcAddress(GetModuleHandleW(ModuleName), FunctionName);
return Address? reinterpret_cast<T>(Address) : Replacement;
Expand Down

0 comments on commit fd29461

Please sign in to comment.