mirror of
https://github.com/Dushistov/sdcv.git
synced 2025-12-16 01:41:55 +00:00
to reduce code size of binary move file to ordinary function
instead of template
This commit is contained in:
@@ -43,13 +43,14 @@ set(sdcv_SRCS
|
||||
src/utils.hpp
|
||||
|
||||
src/lib/lib.cpp
|
||||
src/lib/lib.h
|
||||
src/lib/lib.hpp
|
||||
src/lib/dictziplib.cpp
|
||||
src/lib/dictziplib.hpp
|
||||
src/lib/distance.cpp
|
||||
src/lib/distance.h
|
||||
src/lib/mapfile.hpp
|
||||
src/lib/file.hpp
|
||||
src/lib/file.cpp
|
||||
)
|
||||
|
||||
if (ENABLE_NLS)
|
||||
|
||||
43
src/lib/file.cpp
Normal file
43
src/lib/file.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "file.hpp"
|
||||
|
||||
static void __for_each_file(const std::string& dirname, const std::string& suff,
|
||||
const List& order_list, const List& disable_list,
|
||||
const std::function<void (const std::string&, bool)>& f)
|
||||
{
|
||||
GDir *dir = g_dir_open(dirname.c_str(), 0, nullptr);
|
||||
if (dir) {
|
||||
const gchar *filename;
|
||||
|
||||
while ((filename = g_dir_read_name(dir))!=nullptr) {
|
||||
const std::string fullfilename(dirname+G_DIR_SEPARATOR_S+filename);
|
||||
if (g_file_test(fullfilename.c_str(), G_FILE_TEST_IS_DIR))
|
||||
__for_each_file(fullfilename, suff, order_list, disable_list, f);
|
||||
else if (g_str_has_suffix(filename, suff.c_str()) &&
|
||||
std::find(order_list.begin(), order_list.end(),
|
||||
fullfilename)==order_list.end()) {
|
||||
const bool disable = std::find(disable_list.begin(),
|
||||
disable_list.end(),
|
||||
fullfilename)!=disable_list.end();
|
||||
f(fullfilename, disable);
|
||||
}
|
||||
}
|
||||
g_dir_close(dir);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void for_each_file(const List& dirs_list, const std::string& suff,
|
||||
const List& order_list, const List& disable_list,
|
||||
const std::function<void (const std::string&, bool)>& f)
|
||||
{
|
||||
for (const std::string & item : order_list) {
|
||||
const bool disable = std::find(disable_list.begin(), disable_list.end(), item) != disable_list.end();
|
||||
f(item, disable);
|
||||
}
|
||||
for (const std::string& item : dirs_list)
|
||||
__for_each_file(item, suff, order_list, disable_list, f);
|
||||
}
|
||||
@@ -1,53 +1,12 @@
|
||||
#ifndef _FILE_HPP_
|
||||
#define _FILE_HPP_
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <glib.h>
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
#include <functional>
|
||||
|
||||
typedef std::list<std::string> List;
|
||||
|
||||
template<typename Function>
|
||||
void __for_each_file(const std::string& dirname, const std::string& suff,
|
||||
const List& order_list, const List& disable_list,
|
||||
Function f)
|
||||
{
|
||||
GDir *dir = g_dir_open(dirname.c_str(), 0, NULL);
|
||||
if (dir) {
|
||||
const gchar *filename;
|
||||
extern void for_each_file(const List& dirs_list, const std::string& suff,
|
||||
const List& order_list, const List& disable_list,
|
||||
const std::function<void (const std::string&, bool)>& f);
|
||||
|
||||
while ((filename = g_dir_read_name(dir))!=NULL) {
|
||||
std::string fullfilename(dirname+G_DIR_SEPARATOR_S+filename);
|
||||
if (g_file_test(fullfilename.c_str(), G_FILE_TEST_IS_DIR))
|
||||
__for_each_file(fullfilename, suff, order_list, disable_list, f);
|
||||
else if (g_str_has_suffix(filename, suff.c_str()) &&
|
||||
std::find(order_list.begin(), order_list.end(),
|
||||
fullfilename)==order_list.end()) {
|
||||
bool disable=std::find(disable_list.begin(),
|
||||
disable_list.end(),
|
||||
fullfilename)!=disable_list.end();
|
||||
f(fullfilename, disable);
|
||||
}
|
||||
}
|
||||
g_dir_close(dir);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Function>
|
||||
void for_each_file(const List& dirs_list, const std::string& suff,
|
||||
const List& order_list, const List& disable_list,
|
||||
Function f)
|
||||
{
|
||||
List::const_iterator it;
|
||||
for (it=order_list.begin(); it!=order_list.end(); ++it) {
|
||||
bool disable=std::find(disable_list.begin(), disable_list.end(),
|
||||
*it)!=disable_list.end();
|
||||
f(*it, disable);
|
||||
}
|
||||
for (it=dirs_list.begin(); it!=dirs_list.end(); ++it)
|
||||
__for_each_file(*it, suff, order_list, disable_list, f);
|
||||
}
|
||||
|
||||
#endif//!_FILE_HPP_
|
||||
|
||||
Reference in New Issue
Block a user