1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-07-03 14:14:11 +00:00

Rename namespace dinbpostgres to dindb.

It's so much better!
This commit is contained in:
King_DuckZ 2016-05-24 09:42:29 +02:00
parent 45fc758915
commit 1fd51f75ba
20 changed files with 64 additions and 64 deletions

View file

@ -35,7 +35,7 @@ namespace pq {
class Connection;
} //namespace pq
namespace dinbpostgres {
namespace dindb {
using dinhelp::MaxSizedArray;
struct Settings;
@ -146,6 +146,6 @@ namespace dinbpostgres {
this->query_files_in_dir(columns, parDir, parLevel, parSetID, std::bind(pback_func, &flat_list, std::placeholders::_1));
return list;
}
} //namespace dinbpostgres
} //namespace dindb
#endif

View file

@ -24,13 +24,13 @@
#include <cstdint>
#include <map>
namespace dinbpostgres {
namespace dindb {
struct Settings;
using IDDescMap = std::map<uint32_t, std::string>;
using ConfirmDeleCallback = std::function<bool(const IDDescMap&)>;
void delete_group_from_db ( const Settings& parDB, const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf );
} //namespace dinbpostgres
} //namespace dindb
#endif

View file

@ -27,7 +27,7 @@ namespace mchlib {
struct TigerHash;
} //namespace mchlib
namespace dinbpostgres {
namespace dindb {
struct Settings;
struct LocatedItem {
@ -49,6 +49,6 @@ namespace dinbpostgres {
std::vector<LocatedItem> locate_in_db ( const Settings& parDB, const mchlib::TigerHash& parSearch, const TagList& parTags );
std::vector<LocatedSet> locate_sets_in_db ( const Settings& parDB, const std::string& parSearch, bool parCaseInsensitive );
std::vector<LocatedSet> locate_sets_in_db ( const Settings& parDB, const std::string& parSearch, const std::vector<uint32_t>& parSets, bool parCaseInsensitive );
} //namespace dinbpostgres
} //namespace dindb
#endif

View file

@ -29,11 +29,11 @@ namespace mchlib {
struct TigerHash;
} //namespace mchlib
namespace dinbpostgres {
namespace dindb {
struct Settings;;
void write_to_db ( const Settings& parDB, const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordData& parSetData, const std::string& parSignature );
bool read_from_db ( mchlib::FileRecordData& parItem, mchlib::SetRecordDataFull& parSet, const Settings& parDB, const mchlib::TigerHash& parHash );
} //namespace dinbpostgres
} //namespace dindb
#endif

View file

@ -21,7 +21,7 @@
#include <string>
#include <cstdint>
namespace dinbpostgres {
namespace dindb {
struct Settings {
std::string address;
std::string username;
@ -29,6 +29,6 @@ namespace dinbpostgres {
std::string dbname;
uint16_t port;
};
} //namespace dinbpostgres
} //namespace dindb
#endif

View file

@ -22,7 +22,7 @@
#include <boost/utility/string_ref.hpp>
#include <cstdint>
namespace dinbpostgres {
namespace dindb {
struct Settings;
struct OwnerSetInfo {
@ -37,6 +37,6 @@ namespace dinbpostgres {
void delete_tags ( const Settings& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
void delete_all_tags ( const Settings& parDB, const std::vector<uint64_t>& parFiles, OwnerSetInfo parSet );
void delete_all_tags ( const Settings& parDB, const std::vector<std::string>& parRegexes, OwnerSetInfo parSet );
} //namespace dinbpostgres
} //namespace dindb
#endif

View file

@ -23,7 +23,7 @@
namespace dinlib {
struct Settings {
dinbpostgres::Settings db;
dindb::Settings db;
};
bool load_settings ( const std::string& parPath, Settings& parOut, bool parExpand=true );

View file

@ -25,7 +25,7 @@
#include <sstream>
#include <boost/range/algorithm/copy.hpp>
namespace dinbpostgres {
namespace dindb {
namespace {
const uint32_t g_files_query_limit = 500;
@ -180,4 +180,4 @@ namespace dinbpostgres {
}
return retval;
}
} //namespace dinbpostgres
} //namespace dindb

View file

@ -27,7 +27,7 @@
#include <boost/range/algorithm/copy.hpp>
#include <boost/lexical_cast.hpp>
namespace dinbpostgres {
namespace dindb {
namespace {
IDDescMap fetch_existing_ids (pq::Connection& parConn, const std::vector<uint32_t>& parIDs) {
using boost::lexical_cast;
@ -72,4 +72,4 @@ namespace dinbpostgres {
conn.query(oss.str());
}
} //namespace dinbpostgres
} //namespace dindb

View file

@ -23,7 +23,7 @@
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
namespace dinbpostgres {
namespace dindb {
namespace {
const int g_max_results = 200;
@ -137,4 +137,4 @@ namespace dinbpostgres {
auto result = conn.query(query, parSearch, parCaseInsensitive, parSets);
return sets_result_to_vec(std::move(result));
}
} //namespace dinbpostgres
} //namespace dindb

View file

@ -28,7 +28,7 @@
#include <boost/utility/string_ref.hpp>
#include <chrono>
namespace dinbpostgres {
namespace dindb {
namespace {
} //unnamed namespace
@ -144,4 +144,4 @@ namespace dinbpostgres {
}
conn.query("COMMIT;");
}
} //namespace dinbpostgres
} //namespace dindb

View file

@ -20,7 +20,7 @@
#include "pq/connection.hpp"
#include <ciso646>
namespace dinbpostgres {
namespace dindb {
void tag_files (const Settings& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet) {
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
conn.connect();
@ -152,4 +152,4 @@ namespace dinbpostgres {
conn.query(query, parRegexes);
}
}
} //namespace dinbpostgres
} //namespace dindb

View file

@ -22,8 +22,8 @@
namespace YAML {
template<>
struct convert<dinbpostgres::Settings> {
static Node encode (const dinbpostgres::Settings& parSettings) {
struct convert<dindb::Settings> {
static Node encode (const dindb::Settings& parSettings) {
Node node;
node["address"] = parSettings.address;
node["username"] = parSettings.username;
@ -33,7 +33,7 @@ namespace YAML {
return node;
}
static bool decode (const Node& parNode, dinbpostgres::Settings& parSettings) {
static bool decode (const Node& parNode, dindb::Settings& parSettings) {
if (not parNode.IsMap() or parNode.size() != 5) {
return false;
}
@ -60,7 +60,7 @@ namespace dinlib {
auto settings = YAML::LoadFile(path);
if (settings["db_settings"]) {
parOut.db = settings["db_settings"].as<dinbpostgres::Settings>();
parOut.db = settings["db_settings"].as<dindb::Settings>();
return true;
}
}

View file

@ -26,7 +26,7 @@
#include <cstdint>
namespace {
bool confirm_delete (const dinbpostgres::IDDescMap& parMap) {
bool confirm_delete (const dindb::IDDescMap& parMap) {
for (const auto& itm : parMap) {
std::cout << "ID " << itm.first << '\t' << itm.second << '\n';
}
@ -38,7 +38,7 @@ namespace {
return (answer.empty() or "y" == answer or "Y" == answer);
}
bool always_delete (const dinbpostgres::IDDescMap&) {
bool always_delete (const dindb::IDDescMap&) {
return true;
}
} //unnamed namespace
@ -77,7 +77,7 @@ int main (int parArgc, char* parArgv[]) {
const auto ids = vm["groupid"].as<std::vector<uint32_t>>();
auto confirm_func = (vm.count("confirm") ? &always_delete : &confirm_delete);
dinbpostgres::delete_group_from_db(settings.db, ids, confirm_func);
dindb::delete_group_from_db(settings.db, ids, confirm_func);
return 0;
}

View file

@ -27,7 +27,7 @@
#include <iterator>
#include <algorithm>
namespace dinbpostgres {
namespace dindb {
std::ostream& operator<< (std::ostream& parStream, const LocatedItem& parItem) {
parStream << parItem.group_id << '\t' << parItem.id << '\t' << parItem.path;
return parStream;
@ -41,7 +41,7 @@ namespace dinbpostgres {
'\t' << parItem.files_count << '\t' << dircount;
return parStream;
}
} //namespace dinbpostgres
} //namespace dindb
namespace {
std::vector<boost::string_ref> extract_tags (const boost::program_options::variables_map& parVM) {
@ -81,22 +81,22 @@ int main (int parArgc, char* parArgv[]) {
}
if (vm.count("set")) {
const auto results = dinbpostgres::locate_sets_in_db(settings.db, vm["substring"].as<std::string>(), not not vm.count("case-insensitive"));
std::copy(results.begin(), results.end(), std::ostream_iterator<dinbpostgres::LocatedSet>(std::cout, "\n"));
const auto results = dindb::locate_sets_in_db(settings.db, vm["substring"].as<std::string>(), not not vm.count("case-insensitive"));
std::copy(results.begin(), results.end(), std::ostream_iterator<dindb::LocatedSet>(std::cout, "\n"));
}
else {
std::vector<dinbpostgres::LocatedItem> results;
std::vector<dindb::LocatedItem> results;
const std::vector<boost::string_ref> tags = extract_tags(vm);
if (vm.count("byhash")) {
const auto hash = din::hash(vm["substring"].as<std::string>());
results = dinbpostgres::locate_in_db(settings.db, hash, tags);
results = dindb::locate_in_db(settings.db, hash, tags);
}
else {
const auto search_regex = g2r::convert(vm["substring"].as<std::string>(), not vm.count("case-insensitive"));
results = dinbpostgres::locate_in_db(settings.db, search_regex, tags);
results = dindb::locate_in_db(settings.db, search_regex, tags);
}
std::copy(results.begin(), results.end(), std::ostream_iterator<dinbpostgres::LocatedItem>(std::cout, "\n"));
std::copy(results.begin(), results.end(), std::ostream_iterator<dindb::LocatedItem>(std::cout, "\n"));
}
return 0;
}

View file

@ -68,7 +68,7 @@ namespace din {
}
} //unnamed namespace
ListDirContent::ListDirContent (dinbpostgres::DBSource* parDB) :
ListDirContent::ListDirContent (dindb::DBSource* parDB) :
m_cache(g_max_cached_lists),
m_db(parDB)
{
@ -86,13 +86,13 @@ namespace din {
//Requested item is not cached, so we need to query the db now
if (parDir.points_to_group()) {
auto sets_ids = m_db->sets();
auto sets_info = m_db->set_details<dinbpostgres::SetDetail_ID, dinbpostgres::SetDetail_Desc, dinbpostgres::SetDetail_CreeationDate>(sets_ids);
auto sets_info = m_db->set_details<dindb::SetDetail_ID, dindb::SetDetail_Desc, dindb::SetDetail_CreeationDate>(sets_ids);
m_cache.push_back(std::make_pair(curr_path, db_result_to_vec(sets_info)));
}
else {
auto path_prefix = parDir.file_path();
const auto set_id = parDir.group_id();
auto files_info = m_db->file_details<dinbpostgres::FileDetail_Path>(set_id, parDir.level() + 1, path_prefix);
auto files_info = m_db->file_details<dindb::FileDetail_Path>(set_id, parDir.level() + 1, path_prefix);
m_cache.push_back(std::make_pair(curr_path, db_result_to_vec(files_info)));
}
return last_cached_item(curr_path);

View file

@ -23,9 +23,9 @@
#include <string>
#include <vector>
namespace dinbpostgres {
namespace dindb {
class DBSource;
} //namespace dinbpostgres
} //namespace dindb
namespace din {
class EntryPath;
@ -34,7 +34,7 @@ namespace din {
using ListType = std::vector<std::string>;
using CachedItemType = std::pair<std::string, ListType>;
public:
explicit ListDirContent ( dinbpostgres::DBSource* parDB );
explicit ListDirContent ( dindb::DBSource* parDB );
~ListDirContent ( void ) noexcept = default;
const ListType& ls ( const EntryPath& parDir ) const;
@ -44,7 +44,7 @@ namespace din {
const ListType& last_cached_item ( const std::string& parCurrPath ) const;
mutable boost::circular_buffer<CachedItemType> m_cache;
dinbpostgres::DBSource* m_db;
dindb::DBSource* m_db;
};
} //namespace din

View file

@ -31,7 +31,7 @@
#include <boost/range/algorithm/copy.hpp>
namespace {
void do_navigation ( dinbpostgres::DBSource& parDB );
void do_navigation ( dindb::DBSource& parDB );
bool on_exit ( void );
void on_pwd ( const din::EntryPath& parDirMan );
@ -61,7 +61,7 @@ int main (int parArgc, char* parArgv[]) {
}
}
dinbpostgres::DBSource db_source(settings.db);
dindb::DBSource db_source(settings.db);
do_navigation(db_source);
return 0;
@ -81,7 +81,7 @@ namespace {
boost::copy(ls_result, std::ostream_iterator<std::string>(std::cout, "\n"));
}
void do_navigation (dinbpostgres::DBSource& parDB) {
void do_navigation (dindb::DBSource& parDB) {
const std::string prompt;
din::ListDirContent ls(&parDB);
din::LineReader lines(&ls);
@ -92,7 +92,7 @@ namespace {
din::EntryPath dir_man;
proc.add_command("exit", &on_exit, 0);
proc.add_command("cd", std::function<void(const std::string&)>(std::bind(&din::EntryPath::push_piece, &dir_man, std::placeholders::_1)), 1);
proc.add_command("disconnect", std::function<void()>(std::bind(&dinbpostgres::DBSource::disconnect, &parDB)), 0);
proc.add_command("disconnect", std::function<void()>(std::bind(&dindb::DBSource::disconnect, &parDB)), 0);
proc.add_command("pwd", std::function<void()>(std::bind(&on_pwd, std::ref(dir_man))), 0);
proc.add_command("ls", std::function<void()>(std::bind(on_ls, std::ref(ls), std::ref(dir_man))), 0);
do {

View file

@ -41,7 +41,7 @@
#endif
namespace {
bool add_to_db ( const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordDataFull& parSet, const dinbpostgres::Settings& parDBSettings, bool parForce=false );
bool add_to_db ( const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordDataFull& parSet, const dindb::Settings& parDBSettings, bool parForce=false );
#if defined(WITH_PROGRESS_FEEDBACK)
void print_progress ( const boost::string_ref parPath, uint64_t parFileBytes, uint64_t parTotalBytes, uint32_t parFileNum, std::size_t& parClearCount );
#endif
@ -115,7 +115,7 @@ int main (int parArgc, char* parArgv[]) {
}
namespace {
bool add_to_db (const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordDataFull& parSet, const dinbpostgres::Settings& parDBSettings, bool parForce) {
bool add_to_db (const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordDataFull& parSet, const dindb::Settings& parDBSettings, bool parForce) {
using mchlib::FileRecordData;
using mchlib::SetRecordDataFull;
using mchlib::SetRecordData;
@ -124,7 +124,7 @@ namespace {
const auto& first_hash = parData.front().hash;
FileRecordData itm;
SetRecordDataFull set;
const bool already_in_db = dinbpostgres::read_from_db(itm, set, parDBSettings, first_hash);
const bool already_in_db = dindb::read_from_db(itm, set, parDBSettings, first_hash);
if (already_in_db) {
return false;
}
@ -134,7 +134,7 @@ namespace {
const auto app_signature = dinlib::dindexer_signature();
const auto lib_signature = mchlib::lib_signature();
const std::string signature = std::string(app_signature.data(), app_signature.size()) + "/" + std::string(lib_signature.data(), lib_signature.size());
dinbpostgres::write_to_db(parDBSettings, parData, set_data, signature);
dindb::write_to_db(parDBSettings, parData, set_data, signature);
return true;
}

View file

@ -47,8 +47,8 @@ namespace {
return retval;
}
dinbpostgres::OwnerSetInfo make_owner_set_info (const boost::program_options::variables_map& parVM) {
dinbpostgres::OwnerSetInfo set_info;
dindb::OwnerSetInfo make_owner_set_info (const boost::program_options::variables_map& parVM) {
dindb::OwnerSetInfo set_info;
if (parVM.count("set")) {
set_info.is_valid = true;
set_info.group_id = parVM["set"].as<uint32_t>();
@ -60,11 +60,11 @@ namespace {
return set_info;
}
int tag_files (const dinbpostgres::Settings& parDB, TaggingMode parMode, const boost::program_options::variables_map& parVM, const std::vector<boost::string_ref>& parTags) {
int tag_files (const dindb::Settings& parDB, TaggingMode parMode, const boost::program_options::variables_map& parVM, const std::vector<boost::string_ref>& parTags) {
using boost::lexical_cast;
using boost::string_ref;
const dinbpostgres::OwnerSetInfo set_info = make_owner_set_info(parVM);
const dindb::OwnerSetInfo set_info = make_owner_set_info(parVM);
switch (parMode) {
case TaggingMode::ID:
@ -73,14 +73,14 @@ namespace {
std::vector<uint64_t> ids;
ids.reserve(ids_string.size());
std::transform(ids_string.begin(), ids_string.end(), std::back_inserter(ids), &lexical_cast<uint64_t, string_ref>);
dinbpostgres::tag_files(parDB, ids, parTags, set_info);
dindb::tag_files(parDB, ids, parTags, set_info);
return 0;
}
case TaggingMode::Glob:
{
const auto regexes(globs_to_regex_list(parVM["globs"].as<std::vector<std::string>>()));
dinbpostgres::tag_files(parDB, regexes, parTags, set_info);
dindb::tag_files(parDB, regexes, parTags, set_info);
return 0;
}
@ -90,7 +90,7 @@ namespace {
}
}
int delete_tags (const dinbpostgres::Settings& parDB, TaggingMode parMode, const boost::program_options::variables_map& parVM, const std::vector<boost::string_ref>& parTags) {
int delete_tags (const dindb::Settings& parDB, TaggingMode parMode, const boost::program_options::variables_map& parVM, const std::vector<boost::string_ref>& parTags) {
using boost::lexical_cast;
using boost::string_ref;
@ -104,9 +104,9 @@ namespace {
ids.reserve(ids_string.size());
std::transform(ids_string.begin(), ids_string.end(), std::back_inserter(ids), &lexical_cast<uint64_t, string_ref>);
if (parVM.count("alltags"))
dinbpostgres::delete_all_tags(parDB, ids, make_owner_set_info(parVM));
dindb::delete_all_tags(parDB, ids, make_owner_set_info(parVM));
else
dinbpostgres::delete_tags(parDB, ids, parTags, make_owner_set_info(parVM));
dindb::delete_tags(parDB, ids, parTags, make_owner_set_info(parVM));
return 0;
}
@ -114,9 +114,9 @@ namespace {
{
const auto regexes(globs_to_regex_list(parVM["globs"].as<std::vector<std::string>>()));
if (parVM.count("alltags"))
dinbpostgres::delete_all_tags(parDB, regexes, make_owner_set_info(parVM));
dindb::delete_all_tags(parDB, regexes, make_owner_set_info(parVM));
else
dinbpostgres::delete_tags(parDB, regexes, parTags, make_owner_set_info(parVM));
dindb::delete_tags(parDB, regexes, parTags, make_owner_set_info(parVM));
return 0;
}