Skip to content
Permalink
Browse files

refactoring - added some const

  • Loading branch information...
alabuzhev committed May 17, 2016
1 parent 2bd4fab commit 087cbea543f434dea8f3598a9c0679e7cf253b7e
Showing with 461 additions and 462 deletions.
  1. +1 −1 far/DlgBuilder.hpp
  2. +5 −1 far/changelog
  3. +2 −2 far/cmdline.cpp
  4. +2 −2 far/codepage.hpp
  5. +8 −8 far/codepage_selection.cpp
  6. +8 −8 far/codepage_selection.hpp
  7. +38 −34 far/common/enumerator.hpp
  8. +41 −33 far/common/iterator_range.hpp
  9. +7 −7 far/common/null_iterator.hpp
  10. +3 −3 far/common/preprocessor.hpp
  11. +1 −1 far/components.cpp
  12. +2 −2 far/components.hpp
  13. +1 −1 far/config.cpp
  14. +8 −8 far/configdb.cpp
  15. +2 −2 far/configdb.hpp
  16. +1 −1 far/console.cpp
  17. +1 −1 far/console.hpp
  18. +1 −1 far/copy.cpp
  19. +1 −1 far/copy.hpp
  20. +3 −3 far/ctrlobj.cpp
  21. +3 −3 far/ctrlobj.hpp
  22. +1 −1 far/datetime.cpp
  23. +1 −5 far/desktop.cpp
  24. +1 −1 far/desktop.hpp
  25. +1 −1 far/dialog.cpp
  26. +1 −1 far/dialog.hpp
  27. +1 −1 far/editcontrol.hpp
  28. +2 −2 far/editor.cpp
  29. +2 −2 far/editor.hpp
  30. +16 −15 far/farwinapi.cpp
  31. +25 −23 far/farwinapi.hpp
  32. +7 −7 far/fileedit.cpp
  33. +8 −8 far/fileedit.hpp
  34. +5 −4 far/filefilter.cpp
  35. +3 −3 far/filefilter.hpp
  36. +4 −4 far/filelist.cpp
  37. +2 −2 far/filelist.hpp
  38. +3 −3 far/filepanels.cpp
  39. +9 −9 far/filepanels.hpp
  40. +4 −5 far/filesystemwatcher.cpp
  41. +1 −1 far/filesystemwatcher.hpp
  42. +2 −2 far/fileview.cpp
  43. +2 −2 far/fileview.hpp
  44. +6 −6 far/findfile.cpp
  45. +4 −4 far/findfile.hpp
  46. +1 −1 far/foldtree.cpp
  47. +1 −1 far/foldtree.hpp
  48. +2 −2 far/help.cpp
  49. +2 −2 far/help.hpp
  50. +1 −1 far/history.cpp
  51. +1 −1 far/history.hpp
  52. +72 −93 far/hook_wow64.cpp
  53. +1 −1 far/hotplug.cpp
  54. +1 −1 far/infolist.cpp
  55. +1 −1 far/keybar.hpp
  56. +6 −3 far/main.cpp
  57. +1 −1 far/makefile_gcc
  58. +5 −5 far/manager.cpp
  59. +6 −6 far/manager.hpp
  60. +42 −35 far/matrix.hpp
  61. +0 −2 far/mix.cpp
  62. +1 −1 far/modal.cpp
  63. +1 −1 far/modal.hpp
  64. +3 −6 far/network.cpp
  65. +9 −9 far/panel.cpp
  66. +5 −5 far/panel.hpp
  67. +3 −3 far/panelmix.cpp
  68. +3 −3 far/panelmix.hpp
  69. +3 −3 far/plugins.cpp
  70. +3 −3 far/plugins.hpp
  71. +2 −2 far/qview.cpp
  72. +1 −1 far/qview.hpp
  73. +1 −1 far/scrbuf.cpp
  74. +0 −2 far/scrbuf.hpp
  75. +3 −1 far/scrobj.hpp
  76. +1 −1 far/shortcuts.cpp
  77. +1 −1 far/synchro.hpp
  78. +1 −1 far/treelist.cpp
  79. +1 −1 far/treelist.hpp
  80. +5 −5 far/tvar.hpp
  81. +1 −1 far/usermenu.cpp
  82. +1 −1 far/usermenu.hpp
  83. +1 −1 far/vbuild.m4
  84. +4 −4 far/viewer.cpp
  85. +4 −4 far/viewer.hpp
  86. +4 −4 far/vmenu.cpp
  87. +3 −3 far/vmenu.hpp
  88. +1 −1 far/vmenu2.hpp
  89. +1 −1 far/window.cpp
  90. +1 −1 far/window.hpp
@@ -967,7 +967,7 @@ class PluginDialogBuilder: public DialogBuilderBase<FarDialogItem>
PluginDialogBuilder(const PluginStartupInfo &aInfo, const GUID &aPluginId, const GUID &aId, int TitleMessageID, const wchar_t *aHelpTopic, FARWINDOWPROC aDlgProc=nullptr, void* aUserParam=nullptr, FARDIALOGFLAGS aFlags = FDLG_NONE)
: Info(aInfo), DialogHandle(nullptr), HelpTopic(aHelpTopic), PluginId(aPluginId), Id(aId), DlgProc(aDlgProc), UserParam(aUserParam), Flags(aFlags)
{
AddBorder(GetLangString(TitleMessageID));
AddBorder(PluginDialogBuilder::GetLangString(TitleMessageID));
}

PluginDialogBuilder(const PluginStartupInfo &aInfo, const GUID &aPluginId, const GUID &aId, const wchar_t *TitleMessage, const wchar_t *aHelpTopic, FARWINDOWPROC aDlgProc=nullptr, void* aUserParam=nullptr, FARDIALOGFLAGS aFlags = FDLG_NONE)
@@ -1,4 +1,8 @@
zg 17.05.2016 13:03:38 +0200 - build 4676
drkns 17.05.2016 20:41:13 +0200 - build 4677

1. Рефакторинг - добавим немного const.

zg 17.05.2016 13:03:38 +0200 - build 4676

1. уточнение 4673 для ECTL_SETPOSITION.

@@ -675,9 +675,9 @@ std::list<std::pair<string, FarColor>> CommandLine::GetPrompt()
{
const auto Chr = Upper(*++it);

const auto ItemIterator = std::find_if(CONST_RANGE(ChrFmt, i)
const auto ItemIterator = std::find_if(CONST_RANGE(ChrFmt, Item)
{
return i.first == Chr;
return Item.first == Chr;
});

if (ItemIterator != std::cend(ChrFmt))
@@ -162,9 +162,9 @@ class raw_eol
raw_eol(uintptr_t Codepage): m_Cr(to(Codepage, L'\r')), m_Lf(to(Codepage, L'\n')) {}

template <class T>
T cr() const;
T cr() const = delete;
template <class T>
T lf() const;
T lf() const = delete;

private:
static char to(uintptr_t Codepage, wchar_t WideChar)
@@ -96,32 +96,32 @@ codepages::~codepages()
{}

// Получаем кодовую страницу для элемента в меню
inline uintptr_t codepages::GetMenuItemCodePage(size_t Position)
inline uintptr_t codepages::GetMenuItemCodePage(size_t Position) const
{
const auto DataPtr = CodePagesMenu->GetUserDataPtr<uintptr_t>(Position);
return DataPtr? *DataPtr : 0;
}

inline size_t codepages::GetListItemCodePage(size_t Position)
inline size_t codepages::GetListItemCodePage(size_t Position) const
{
const auto DataPtr = dialog->GetListItemDataPtr<uintptr_t>(control, Position);
return DataPtr? *DataPtr : 0;
}

// Проверяем попадает или нет позиция в диапазон стандартных кодовых страниц (правильность работы для разделителей не гарантируется)
inline bool codepages::IsPositionStandard(UINT position)
inline bool codepages::IsPositionStandard(UINT position) const
{
return position <= (UINT)CodePagesMenu->size() - favoriteCodePages - (favoriteCodePages?1:0) - normalCodePages - (normalCodePages?1:0);
}

// Проверяем попадает или нет позиция в диапазон избранных кодовых страниц (правильность работы для разделителей не гарантируется)
inline bool codepages::IsPositionFavorite(UINT position)
inline bool codepages::IsPositionFavorite(UINT position) const
{
return !IsPositionStandard(position) && !IsPositionNormal(position);
}

// Проверяем попадает или нет позиция в диапазон обыкновенных кодовых страниц (правильность работы для разделителей не гарантируется)
inline bool codepages::IsPositionNormal(UINT position)
inline bool codepages::IsPositionNormal(UINT position) const
{
return position >= static_cast<UINT>(CodePagesMenu->size() - normalCodePages);
}
@@ -142,7 +142,7 @@ string codepages::FormatCodePageString(uintptr_t CodePage, const string& CodePag
}

// Добавляем таблицу символов
void codepages::AddCodePage(const string& codePageName, uintptr_t codePage, size_t position, bool enabled, bool checked, bool IsCodePageNameCustom)
void codepages::AddCodePage(const string& codePageName, uintptr_t codePage, size_t position, bool enabled, bool checked, bool IsCodePageNameCustom) const
{
if (CallbackCallSource == CodePagesFill)
{
@@ -229,7 +229,7 @@ void codepages::AddCodePage(const string& codePageName, uintptr_t codePage, size
}

// Добавляем стандартную таблицу символов
void codepages::AddStandardCodePage(const wchar_t *codePageName, uintptr_t codePage, int position, bool enabled)
void codepages::AddStandardCodePage(const wchar_t *codePageName, uintptr_t codePage, int position, bool enabled) const
{
bool checked = false;

@@ -243,7 +243,7 @@ void codepages::AddStandardCodePage(const wchar_t *codePageName, uintptr_t codeP
}

// Добавляем разделитель
void codepages::AddSeparator(LPCWSTR Label, size_t position)
void codepages::AddSeparator(LPCWSTR Label, size_t position) const
{
if (CallbackCallSource == CodePagesFill)
{
@@ -76,15 +76,15 @@ class codepages: noncopyable
codepages();

string& FormatCodePageName(uintptr_t CodePage, string& CodePageName, bool &IsCodePageNameCustom) const;
inline size_t GetMenuItemCodePage(size_t Position = -1);
inline size_t GetListItemCodePage(size_t Position);
inline bool IsPositionStandard(UINT position);
inline bool IsPositionFavorite(UINT position);
inline bool IsPositionNormal(UINT position);
inline size_t GetMenuItemCodePage(size_t Position = -1) const;
inline size_t GetListItemCodePage(size_t Position) const;
inline bool IsPositionStandard(UINT position) const;
inline bool IsPositionFavorite(UINT position) const;
inline bool IsPositionNormal(UINT position) const;
string FormatCodePageString(uintptr_t CodePage, const string& CodePageName, bool IsCodePageNameCustom) const;
void AddCodePage(const string& codePageName, uintptr_t codePage, size_t position, bool enabled, bool checked, bool IsCodePageNameCustom);
void AddStandardCodePage(const wchar_t *codePageName, uintptr_t codePage, int position = -1, bool enabled = true);
void AddSeparator(LPCWSTR Label = nullptr, size_t position = -1);
void AddCodePage(const string& codePageName, uintptr_t codePage, size_t position, bool enabled, bool checked, bool IsCodePageNameCustom) const;
void AddStandardCodePage(const wchar_t *codePageName, uintptr_t codePage, int position = -1, bool enabled = true) const;
void AddSeparator(LPCWSTR Label = nullptr, size_t position = -1) const;
size_t size() const;
size_t GetCodePageInsertPosition(uintptr_t codePage, size_t start, size_t length);
void AddCodePages(DWORD codePages);
@@ -36,51 +36,55 @@ template<typename Derived, typename T>
class enumerator
{
public:
typedef T value_type;
using value_type = T;

class const_iterator: public std::iterator<std::forward_iterator_tag, T>
template<typename item_type, typename owner>
class iterator_t: public std::iterator<std::forward_iterator_tag, item_type>
{
public:
using value_type = const T;

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; }
value_type& operator *() const { return m_value; }
const_iterator& operator ++() { if (!m_collection->get(++m_index, m_value)) m_index = size_t(-1); return *this; }
bool operator ==(const const_iterator& rhs) const { return m_index == rhs.m_index; }
bool operator !=(const const_iterator& rhs) const { return !(*this == rhs); }
using value_type = item_type;

iterator_t() = default;
iterator_t(const owner& Owner): m_Owner{ Owner }, m_Index{} {}

auto operator->() { return static_cast<value_type*>(&m_Value); }
auto operator->() const { return static_cast<value_type*>(&m_Value); }

auto& operator*() { return static_cast<value_type&>(m_Value); }
auto& operator*() const { return static_cast<value_type&>(m_Value); }

auto& operator++()
{
if (m_Index == invalid_index)
{
throw MAKE_FAR_EXCEPTION("enumerator iterator is out of range");
}
m_Index = m_Owner->get(m_Index, m_Value)? m_Index + 1 : invalid_index;
return *this;
}

bool operator==(const iterator_t& rhs) const { return m_Index == rhs.m_Index; }
bool operator!=(const iterator_t& rhs) const { return !(*this == rhs); }

private:
friend enumerator;
static const size_t invalid_index { size_t(-1) };

Derived* m_collection;
size_t m_index;
T m_value;
owner m_Owner {};
size_t m_Index { invalid_index };
std::remove_const_t<value_type> m_Value {};
};

class iterator: public const_iterator
{
public:
using value_type = T;
using const_iterator::const_iterator;
using iterator = iterator_t<T, Derived*>;
using const_iterator = iterator_t<const T, const Derived*>;

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; }
};
auto begin() { return std::next(iterator{ static_cast<Derived*>(this) }); }
auto end() { return iterator{}; }

iterator begin() { iterator result(static_cast<Derived*>(this), 0); if (!static_cast<Derived*>(this)->get(result.m_index, result.m_value)) result.m_index = size_t(-1); return result; }
iterator end() { return iterator(static_cast<Derived*>(this), size_t(-1)); }
const_iterator begin() const { return const_cast<enumerator*>(this)->begin(); }
const_iterator end() const { return const_cast<enumerator*>(this)->end(); }
const_iterator cbegin() const { return begin(); }
const_iterator cend() const { return end(); }
auto begin() const { return std::next(const_iterator{ static_cast<const Derived*>(this) }); }
auto end() const { return const_iterator{}; }

private:
friend iterator;
auto cbegin() const { return begin(); }
auto cend() const { return end(); }
};

#endif // ENUMERATOR_HPP_6BCD3B36_3A68_400C_82B5_AB3644D0A874
@@ -37,44 +37,48 @@ class range
{
public:
using iterator = iterator_type;
using value_type = typename std::iterator_traits<iterator>::value_type;
using reverse_iterator = std::reverse_iterator<iterator>;
using reference = typename std::iterator_traits<iterator>::reference;
using pointer = typename std::iterator_traits<iterator>::pointer;
using value_type = typename std::iterator_traits<iterator>::value_type;

range():
m_begin(),
m_end()
{}
range() = default;

range(iterator i_begin, iterator i_end):
m_begin(i_begin),
m_end(i_end)
{}

iterator begin() const { return m_begin; }
iterator end() const { return m_end; }
reverse_iterator rbegin() const { return reverse_iterator(m_end); }
reverse_iterator rend() const { return reverse_iterator(m_begin); }
auto begin() { return m_begin; }
auto end() { return m_end; }

auto begin() const { return m_begin; }
auto end() const { return m_end; }

auto rbegin() { return reverse_iterator(m_end); }
auto rend() { return reverse_iterator(m_begin); }

auto rbegin() const { return reverse_iterator(m_end); }
auto rend() const { return reverse_iterator(m_begin); }

reference operator[](size_t n) { return *(m_begin + n); }
reference operator[](size_t n) const { return *(m_begin + n); }
auto& operator[](size_t n) { return *(m_begin + n); }
auto& operator[](size_t n) const { return *(m_begin + n); }

reference front() { return *m_begin; }
reference front() const { return *m_begin; }
auto& front() { return *m_begin; }
auto& back() { return *std::prev(m_end); }

reference back() { return *std::prev(m_end); }
reference back() const { return *std::prev(m_end); }
auto& front() const { return *m_begin; }
auto& back() const { return *std::prev(m_end); }

pointer data() { return &*m_begin; }
pointer data() const { return &*m_begin; }
auto data() { return &*m_begin; }
auto data() const { return &*m_begin; }

bool empty() const { return m_begin == m_end; }
size_t size() const { return m_end - m_begin; }

private:
iterator m_begin;
iterator m_end;
iterator m_begin {};
iterator m_end {};
};

template<class iterator_type>
@@ -103,20 +107,24 @@ class i_iterator: public std::iterator<std::random_access_iterator_tag, T>, publ

i_iterator(const T& value): m_value(value) {}
i_iterator(const i_iterator& rhs): m_value(rhs.m_value) {}
i_iterator& operator=(const i_iterator& rhs) { m_value = rhs.m_value; return *this; }
const value_type* operator->() const { return &m_value; }
const value_type& operator*() const { return m_value; }
i_iterator& operator++() { ++m_value; return *this; }
i_iterator& operator--() { --m_value; return *this; }
i_iterator& operator+=(size_t n) { m_value += n; return *this; }
i_iterator& operator-=(size_t n) { m_value -= n; return *this; }
i_iterator operator++(int) { return m_value++; }
i_iterator operator--(int) { return m_value--; }
i_iterator operator+(size_t n) const { return m_value + n; }
i_iterator operator-(size_t n) const { return m_value - n; }
ptrdiff_t operator-(const i_iterator& rhs) const { return m_value - rhs.m_value; }
bool operator==(const i_iterator& rhs) const { return m_value == rhs.m_value; }
bool operator<(const i_iterator& rhs) const { return m_value < rhs.m_value; }

auto& operator=(const i_iterator& rhs) { m_value = rhs.m_value; return *this; }

auto operator->() const { return &m_value; }
auto& operator*() const { return m_value; }

auto& operator++() { ++m_value; return *this; }
auto& operator--() { --m_value; return *this; }

auto& operator+=(size_t n) { m_value += n; return *this; }
auto& operator-=(size_t n) { m_value -= n; return *this; }

auto operator+(size_t n) const { return i_iterator(m_value + n); }
auto operator-(size_t n) const { return i_iterator(m_value - n); }

auto operator-(const i_iterator& rhs) const { return m_value - rhs.m_value; }
auto operator==(const i_iterator& rhs) const { return m_value == rhs.m_value; }
auto operator<(const i_iterator& rhs) const { return m_value < rhs.m_value; }

private:
T m_value;
@@ -37,13 +37,13 @@ class null_iterator_t: public std::iterator<std::forward_iterator_tag, T>
{
public:
null_iterator_t(T* Data): m_Data(Data) {}
null_iterator_t& operator++() { ++m_Data; return *this; }
null_iterator_t operator++(int) { return null_iterator_t(m_Data++); }
T& operator*() { return *m_Data; }
T* operator->() noexcept { return m_Data; }
const T& operator*() const { return *m_Data; }
const T* operator->() const noexcept { return m_Data; }
static const null_iterator_t& end() { static T Empty[1] = {}; static null_iterator_t Iter(Empty); return Iter; }
auto& operator++() { ++m_Data; return *this; }
auto operator++(int) { return null_iterator_t(m_Data++); }
auto& operator*() { return *m_Data; }
auto operator->() noexcept { return m_Data; }
auto& operator*() const { return *m_Data; }
auto operator->() const noexcept { return m_Data; }
static const auto& end() { static T Empty[1] = {}; static null_iterator_t Iter(Empty); return Iter; }
bool operator==(const null_iterator_t& rhs) const { return (!*m_Data && !*rhs.m_Data) || m_Data == rhs.m_Data; }
bool operator!=(const null_iterator_t& rhs) const { return !(*this == rhs); }

@@ -96,12 +96,12 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Type(const Type&) = delete; \
Type& operator=(const Type&) = delete; \

#define COPY_AND_SWAP(Type, ...) \
Type& operator=(__VA_ARGS__ rhs) { Type Tmp(rhs); using std::swap; swap(*this, Tmp); return *this; }
#define COPY_AND_SWAP(...) \
auto& operator=(__VA_ARGS__ rhs) { std::remove_reference_t<decltype(*this)> Tmp(rhs); using std::swap; swap(*this, Tmp); return *this; }

#define TRIVIALLY_COPYABLE(Type) \
Type(const Type&) = default; \
COPY_AND_SWAP(Type, const Type&)
COPY_AND_SWAP(const Type&)

#define TRIVIALLY_MOVABLE(Type) \
Type(Type&&) = default; \
@@ -73,7 +73,7 @@ namespace components
++m_size;
}

bool components_list::get(size_t index, value_type& value)
bool components_list::get(size_t index, value_type& value) const
{
if (!index)
enum_ptr = list;
@@ -56,7 +56,7 @@ namespace components
void add(component* item);
bool empty() const { return list != nullptr; }
size_t size() const { return m_size; }
bool get(size_t index, value_type& value);
bool get(size_t index, value_type& value) const;

private:
friend components_list& GetComponentsList();
@@ -65,7 +65,7 @@ namespace components

component* list;
component* ptr;
component* enum_ptr;
mutable component* enum_ptr;
size_t m_size;
};

Oops, something went wrong.

0 comments on commit 087cbea

Please sign in to comment.
You can’t perform that action at this time.