Skip to content

Commit

Permalink
refactoring & renames
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Apr 15, 2016
1 parent b2ecaa0 commit 05f6753
Show file tree
Hide file tree
Showing 31 changed files with 497 additions and 480 deletions.
367 changes: 194 additions & 173 deletions far/PluginA.cpp

Large diffs are not rendered by default.

17 changes: 3 additions & 14 deletions far/PluginA.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,16 @@ namespace wrapper

#include "pluginold.hpp"

class OEMPluginModel : public NativePluginModel
{
public:
OEMPluginModel(PluginManager* owner);

virtual std::unique_ptr<Plugin> CreatePlugin(const string& filename) override;
const std::string& getUserName();

private:
virtual bool FindExport(const char* ExportName) override;
std::string m_userName;
};
plugin_factory_ptr CreateOemPluginFactory(PluginManager* Owner);

class file_version;

// TODO: PluginA class shouldn't be derived from Plugin.
// All exports should be provided by OEMPluginModel.
// All exports should be provided by oem_plugin_factory.
class PluginA: public Plugin
{
public:
PluginA(OEMPluginModel* model, const string& ModuleName);
PluginA(plugin_factory* Factory, const string& ModuleName);
~PluginA();

virtual bool GetGlobalInfo(GlobalInfo *Info) override;
Expand Down
2 changes: 1 addition & 1 deletion far/TaskBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void taskbar::SetProgressValue(UINT64 Completed, UINT64 Total)
}
}

TBPFLAG taskbar::GetProgressState()
TBPFLAG taskbar::GetProgressState() const
{
return State;
}
Expand Down
3 changes: 2 additions & 1 deletion far/TaskBar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class taskbar: noncopyable
{
public:
~taskbar();
TBPFLAG GetProgressState();
TBPFLAG GetProgressState() const;
void SetProgressState(TBPFLAG tbpFlags);
void SetProgressValue(UINT64 Completed, UINT64 Total);
static void Flash();
Expand All @@ -49,6 +49,7 @@ class taskbar: noncopyable
taskbar();

TBPFLAG State;

ITaskbarList3* pTaskbarList;
};

Expand Down
6 changes: 5 additions & 1 deletion far/changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
w17 14.04.2016 16:24:08 +0300 - build 4622
drkns 16.04.2016 01:21:23 +0200 - build 4623

1. Рефакторинг и переименования.

w17 14.04.2016 16:24:08 +0300 - build 4622

1. M#3183: Panel FreeInfo, TotalInfo - add options for human-readable format (e.g. "1.375 T" free space)
Ctrl-Shift-S (M#3089) теперь влияет и на показ общего размера и свободного места в файловой панели.
Expand Down
8 changes: 4 additions & 4 deletions far/clipboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ class Clipboard
class clipboard_accessor:noncopyable
{
public:
clipboard_accessor(default_clipboard_mode::mode Mode = default_clipboard_mode::get()): m_Mode(Mode) {}
Clipboard* operator->() const { return &Clipboard::GetInstance(m_Mode); }
~clipboard_accessor() { Clipboard::GetInstance(m_Mode).Close(); }
clipboard_accessor(default_clipboard_mode::mode Mode = default_clipboard_mode::get()): m_Clipboard(Clipboard::GetInstance(Mode)) {}
~clipboard_accessor() { m_Clipboard.Close(); }
Clipboard* operator->() const { return &m_Clipboard; }

private:
default_clipboard_mode::mode m_Mode;
Clipboard& m_Clipboard;
};


Expand Down
17 changes: 10 additions & 7 deletions far/codepage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,23 @@ class raw_eol
{
public:
raw_eol(): m_Cr('\r'), m_Lf('\n') {}
raw_eol(uintptr_t Codepage)
{
unicode::to(Codepage, L"\r", 1, &m_Cr, 1);
unicode::to(Codepage, L"\n", 1, &m_Lf, 1);
}
raw_eol(uintptr_t Codepage): m_Cr(to(Codepage, L'\r')), m_Lf(to(Codepage, L'\n')) {}

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

private:
char m_Cr;
char m_Lf;
static char to(uintptr_t Codepage, wchar_t WideChar)
{
char Char = WideChar;
unicode::to(Codepage, &WideChar, 1, &Char, 1);
return Char;
}

const char m_Cr;
const char m_Lf;
};

template<>
Expand Down
2 changes: 1 addition & 1 deletion far/components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace components
if (sList.empty())
{
auto& ComponentsList = GetComponentsList();
std::transform(ALL_RANGE(ComponentsList), std::inserter(sList, sList.end()), [](const auto& i)
std::transform(ALL_CONST_RANGE(ComponentsList), std::inserter(sList, sList.end()), [](const auto& i)
{
return i();
});
Expand Down
2 changes: 1 addition & 1 deletion far/components.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace components
class component
{
public:
typedef string(*get_info)();
using get_info = string(*)();

component(get_info getInfo);

Expand Down
5 changes: 3 additions & 2 deletions far/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2258,8 +2258,9 @@ bool Options::AdvancedConfig(farconfig_mode Mode)
};
auto AdvancedConfigDlg = MakeDialogItemsEx(AdvancedConfigDlgData);

std::vector<FarListItem> items(Config[CurrentConfig].size());
std::transform(ALL_RANGE(Config[CurrentConfig]), items.begin(), [](auto& i) { return i.MakeListItem(); });
std::vector<FarListItem> items;
items.reserve(Config[CurrentConfig].size());
std::transform(ALL_CONST_RANGE(Config[CurrentConfig]), std::back_inserter(items), [](auto& i) { return i.MakeListItem(); });

FarList Items={sizeof(FarList), items.size(), items.data()};

Expand Down
29 changes: 16 additions & 13 deletions far/configdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,19 +767,17 @@ class HighlightHierarchicalConfigDb: public HierarchicalConfigDb
{
if(!strcmp(Type, "color"))
{
const auto background = e.Attribute("background");
const auto foreground = e.Attribute("foreground");
const auto flags = e.Attribute("flags");
FarColor Color{};

std::vector<char> Blob;
if(background && foreground && flags)
{
Blob.resize(sizeof(FarColor));
auto& Color = *reinterpret_cast<FarColor*>(Blob.data());
if (const auto background = e.Attribute("background"))
Color.BackgroundColor = std::strtoul(background, nullptr, 16);
if (const auto foreground = e.Attribute("foreground"))
Color.ForegroundColor = std::strtoul(foreground, nullptr, 16);
if (const auto flags = e.Attribute("flags"))
Color.Flags = StringToFlags(wide(flags, CP_UTF8), ColorFlagNames);
}

std::vector<char> Blob(sizeof(FarColor));
std::memcpy(Blob.data(), &Color, sizeof(Color));
return Blob;
}
else
Expand Down Expand Up @@ -2269,10 +2267,10 @@ static const std::wregex& uuid_regex()
void config_provider::CheckDatabase(SQLiteDb *pDb)
{
string pname;
int rc = pDb->InitStatus(pname, m_Mode != default_mode);
int rc = pDb->InitStatus(pname, m_Mode != mode::m_default);
if ( rc > 0 )
{
if (m_Mode != default_mode)
if (m_Mode != mode::m_default)
{
Console().Write(L"problem with " + pname + (rc <= 1 ? L":\r\n database file is renamed to *.bad and new one is created\r\n" : L":\r\n database is opened in memory\r\n"));
Console().Commit();
Expand Down Expand Up @@ -2326,7 +2324,7 @@ std::unique_ptr<T> config_provider::CreateDatabase(const char *son)
{
auto cfg = std::make_unique<T>();
CheckDatabase(cfg.get());
if (m_Mode != import_mode && cfg->IsNew())
if (m_Mode != mode::m_import && cfg->IsNew())
{
TryImportDatabase(cfg.get(), son);
}
Expand All @@ -2340,7 +2338,7 @@ HierarchicalConfigUniquePtr config_provider::CreateHierarchicalConfig(dbcheck Db
if (!CheckedDb.Check(DbId))
{
CheckDatabase(cfg.get());
if (m_Mode != import_mode && cfg->IsNew())
if (m_Mode != mode::m_import && cfg->IsNew())
{
TryImportDatabase(cfg.get(), xmln, plugin);
}
Expand Down Expand Up @@ -2445,6 +2443,11 @@ bool config_provider::Export(const string& File)
return Representation.Save(File);
}

bool config_provider::ServiceMode(const string& Filename)
{
return m_Mode == mode::m_import? Import(Filename) : m_Mode == mode::m_export? Export(Filename) : throw std::logic_error("unexpected mode");
}

bool config_provider::Import(const string& Filename)
{
representation_source Representation(Filename);
Expand Down
9 changes: 5 additions & 4 deletions far/configdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,11 @@ enum dbcheck: int;
class config_provider: noncopyable
{
public:
enum mode { default_mode, import_mode, export_mode };
config_provider(mode Mode = default_mode);
enum class mode { m_default, m_import, m_export };
config_provider(mode Mode = mode::m_default);
~config_provider();
bool Import(const string& File);
bool Export(const string& File);
int ShowProblems();
bool ServiceMode(const string& File);

void AddThread(Thread&& thread);

Expand All @@ -336,6 +335,8 @@ class config_provider: noncopyable
private:
template<class T> HierarchicalConfigUniquePtr CreateHierarchicalConfig(dbcheck DbId, const string& dbn, const char *xmln, bool Local = false, bool plugin = false);
template<class T> std::unique_ptr<T> CreateDatabase(const char *son = nullptr);
bool Import(const string& File);
bool Export(const string& File);
void TryImportDatabase(representable *p, const char *son = nullptr, bool plugin=false);
void CheckDatabase(class SQLiteDb *pDb);

Expand Down
3 changes: 1 addition & 2 deletions far/far.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,8 @@ cl /nologo /c /Fo"$(IntDir)%(Filename)_c++.testobj" /TP api_test.c
<ClCompile Include="tvar.cpp" />
<ClCompile Include="usermenu.cpp" />
<ClCompile Include="vc_crt_fix_impl.cpp">
<ExcludedFromBuild Condition="'$(Platform)'=='x64'">true</ExcludedFromBuild>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<AdditionalOptions Condition="'$(VisualStudioVersion)' &gt;= '14.0'">/Zc:threadSafeInit- %(AdditionalOptions)</AdditionalOptions>
<AdditionalOptions>/Zc:threadSafeInit- %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<ClCompile Include="viewer.cpp" />
<ClCompile Include="vmenu.cpp" />
Expand Down
2 changes: 1 addition & 1 deletion far/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void History::AddToHistory(const string& Str, history_record_type Type, const GU
{
if (EqualType(Type,HType))
{
typedef int (*CompareFunction)(const string&, const string&);
using CompareFunction = int (*)(const string&, const string&);
CompareFunction CaseSensitive = StrCmp, CaseInsensitive = StrCmpI;
CompareFunction CmpFunction = (m_RemoveDups == 2 ? CaseInsensitive : CaseSensitive);

Expand Down
2 changes: 1 addition & 1 deletion far/interf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ static void HiTextBase(const string& Str, const std::function<void(const string&

void HiText(const string& Str,const FarColor& HiColor,int isVertText)
{
typedef void(*text_func)(const string&);
using text_func = void (*)(const string&);
const text_func fText = Text, fVText = VText; //BUGBUG
const auto TextFunc = isVertText ? fVText : fText;

Expand Down
4 changes: 2 additions & 2 deletions far/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ static bool ProcessServiceModes(const range<wchar_t**>& Args, int& ServiceResult
string strProfilePath(Args.size() > 2 ? Args[2] : L""), strLocalProfilePath(Args.size() > 3 ? Args[3] : L""), strTemplatePath(Args.size() > 4 ? Args[4] : L"");
InitTemplateProfile(strTemplatePath);
InitProfile(strProfilePath, strLocalProfilePath);
Global->m_ConfigProvider = new config_provider(Export ? config_provider::export_mode : config_provider::import_mode);
ServiceResult = !(Export ? ConfigProvider().Export(Args[1]) : ConfigProvider().Import(Args[1]));
Global->m_ConfigProvider = new config_provider(Export? config_provider::mode::m_export : config_provider::mode::m_import);
ServiceResult = !ConfigProvider().ServiceMode(Args[1]);
return true;
}
else if (InRange(size_t(1), Args.size(), size_t(3)) && isArg(Args[0], L"clearcache"))
Expand Down
2 changes: 1 addition & 1 deletion far/makefile_vc
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,13 @@ LINK_OBJS = \
"$(INTDIR)\window.obj" \
"$(INTDIR)\wm_listener.obj" \
"$(INTDIR)\xlat.obj" \
"$(INTDIR)\vc_crt_fix_impl.obj" \
!if defined(X86)
!if !defined(DISABLE_WOW64_HOOK)
"$(INTDIR)\hook_wow64.obj" \
!endif
!ifndef LINK_ULINK
"$(INTDIR)\vc_crt_fix.obj" \
"$(INTDIR)\vc_crt_fix_impl.obj" \
!else
"$(INTDIR)\vc_crt_fix_ulink.obj"
!endif
Expand Down
2 changes: 1 addition & 1 deletion far/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ int Manager::GetModalExitCode() const
*/
int Manager::CountWindowsWithName(const string& Name, BOOL IgnoreCase)
{
typedef int (*CompareFunction)(const string&, const string&);
using CompareFunction = int (*)(const string&, const string&);
CompareFunction CaseSenitive = StrCmp, CaseInsensitive = StrCmpI;
CompareFunction CmpFunction = IgnoreCase? CaseInsensitive : CaseSenitive;

Expand Down
2 changes: 1 addition & 1 deletion far/manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class Manager: noncopyable
void SubmergeCommit(window_ptr_ref Param);
int GetModalExitCode() const;

typedef void(Manager::*window_callback)(window_ptr_ref);
using window_callback = void (Manager::*)(window_ptr_ref);

void PushWindow(window_ptr_ref Param, window_callback Callback);
void CheckAndPushWindow(window_ptr_ref Param, window_callback Callback);
Expand Down
2 changes: 1 addition & 1 deletion far/matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class matrix
m_cols = cols;

// don't call vector.resize() here:
// - it's never shrink
// - it never shrinks
// - we don't care about old content
m_buffer = std::vector<T>(m_rows * m_cols);
}
Expand Down
5 changes: 3 additions & 2 deletions far/mix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,10 @@ void ReloadEnvironment()
L"USERNAME", //absent
};

std::vector<std::pair<const wchar_t*, string>> PreservedVariables(std::size(PreservedNames));
std::vector<std::pair<const wchar_t*, string>> PreservedVariables;
PreservedVariables.reserve(std::size(PreservedNames));

std::transform(ALL_CONST_RANGE(PreservedNames), PreservedVariables.begin(), [](const wchar_t* i)
std::transform(ALL_CONST_RANGE(PreservedNames), std::back_inserter(PreservedVariables), [](const wchar_t* i)
{
return std::make_pair(i, os::env::get_variable(i));
});
Expand Down
Loading

0 comments on commit 05f6753

Please sign in to comment.