mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-08-18 15:29:48 +00:00
Move DBSettings to common lib.
This commit is contained in:
parent
0373743b61
commit
6e7176be10
8 changed files with 10 additions and 7 deletions
|
@ -16,7 +16,6 @@ add_executable(${PROJECT_NAME}
|
|||
tiger.c
|
||||
tiger.cpp
|
||||
dbbackend.cpp
|
||||
settings.cpp
|
||||
commandline.cpp
|
||||
discinfo.cpp
|
||||
mediatype.cpp
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include "dbbackend.hpp"
|
||||
#include "pq/connection.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "dindexer-common/settings.hpp"
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "pathname.hpp"
|
||||
#include "tiger.hpp"
|
||||
#include "dbbackend.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "dindexer-common/settings.hpp"
|
||||
#include "filestats.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include "dindexerConfig.h"
|
||||
#include "filesearcher.hpp"
|
||||
#include "indexer.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "dindexer-common/settings.hpp"
|
||||
#include "commandline.hpp"
|
||||
|
||||
namespace {
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
/* Copyright 2015, Michele Santullo
|
||||
* This file is part of "dindexer".
|
||||
*
|
||||
* "dindexer" is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* "dindexer" is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "settings.hpp"
|
||||
#include <yaml-cpp/yaml.h>
|
||||
#include <ciso646>
|
||||
|
||||
namespace YAML {
|
||||
template<>
|
||||
struct convert<din::DinDBSettings> {
|
||||
static Node encode (const din::DinDBSettings& parSettings) {
|
||||
Node node;
|
||||
node["address"] = parSettings.address;
|
||||
node["username"] = parSettings.username;
|
||||
node["password"] = parSettings.password;
|
||||
node["port"] = parSettings.port;
|
||||
node["dbname"] = parSettings.dbname;
|
||||
return node;
|
||||
}
|
||||
|
||||
static bool decode (const Node& parNode, din::DinDBSettings& parSettings) {
|
||||
if (not parNode.IsMap() or parNode.size() != 5) {
|
||||
return false;
|
||||
}
|
||||
|
||||
parSettings.address = parNode["address"].as<std::string>();
|
||||
parSettings.username = parNode["username"].as<std::string>();
|
||||
parSettings.password = parNode["password"].as<std::string>();
|
||||
parSettings.dbname = parNode["dbname"].as<std::string>();
|
||||
parSettings.port = parNode["port"].as<uint16_t>();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
} //namespace YAML
|
||||
|
||||
namespace din {
|
||||
bool load_settings (const std::string& parPath, DinDBSettings& parOut) {
|
||||
try {
|
||||
auto settings = YAML::LoadFile(parPath);
|
||||
|
||||
if (settings["db_settings"]) {
|
||||
parOut = settings["db_settings"].as<DinDBSettings>();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (const std::exception&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
} //namespace din
|
|
@ -1,39 +0,0 @@
|
|||
/* Copyright 2015, Michele Santullo
|
||||
* This file is part of "dindexer".
|
||||
*
|
||||
* "dindexer" is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* "dindexer" is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef idDC29E3C667BD4793BA0644AE7DC5BD3F
|
||||
#define idDC29E3C667BD4793BA0644AE7DC5BD3F
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
namespace din {
|
||||
struct DinDBSettings {
|
||||
std::string address;
|
||||
std::string username;
|
||||
std::string password;
|
||||
std::string dbname;
|
||||
uint16_t port;
|
||||
};
|
||||
|
||||
//struct DinSettings {
|
||||
//};
|
||||
|
||||
bool load_settings ( const std::string& parPath, DinDBSettings& parOut );
|
||||
} //namespace din
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue