CatapultServer  v0.5.0.1 (Elephant)
ConfigurationFileLoader.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "PeersConfiguration.h"
24 #include <boost/filesystem.hpp>
25 #include <iostream>
26 
27 namespace catapult { namespace config {
28 
30  template<
31  typename TConfigurationLoader,
32  typename TConfiguration = std::invoke_result_t<TConfigurationLoader, const std::string&>
33  >
34  TConfiguration LoadConfiguration(const boost::filesystem::path& path, TConfigurationLoader loader) {
35  if (!boost::filesystem::exists(path)) {
36  auto message = "aborting load due to missing configuration file";
37  CATAPULT_LOG(fatal) << message << ": " << path;
39  }
40 
41  std::cout << "loading configuration from " << path << std::endl;
42  return loader(path.generic_string());
43  }
44 
46  template<typename TConfiguration>
47  TConfiguration LoadIniConfiguration(const boost::filesystem::path& path) {
48  return LoadConfiguration(path, [](const auto& filePath) {
49  return TConfiguration::LoadFromBag(utils::ConfigurationBag::FromPath(filePath));
50  });
51  }
52 
54  inline std::vector<ionet::Node> LoadPeersConfiguration(
55  const boost::filesystem::path& path,
56  model::NetworkIdentifier networkIdentifier) {
57  return LoadConfiguration(path, [networkIdentifier](const auto& filePath) {
58  return LoadPeersFromPath(filePath, networkIdentifier);
59  });
60  }
61 }}
CATAPULT_THROW_EXCEPTION
#define CATAPULT_THROW_EXCEPTION(EXCEPTION)
Macro used to throw a catapult exception.
Definition: exceptions.h:142
catapult::config::LoadIniConfiguration
TConfiguration LoadIniConfiguration(const boost::filesystem::path &path)
Loads ini configuration from path.
Definition: ConfigurationFileLoader.h:47
CATAPULT_LOG
#define CATAPULT_LOG(SEV)
Writes a log entry to the default logger with SEV severity.
Definition: Logging.h:340
catapult::config::LoadPeersConfiguration
std::vector< ionet::Node > LoadPeersConfiguration(const boost::filesystem::path &path, model::NetworkIdentifier networkIdentifier)
Loads peers configuration from path for network networkIdentifier.
Definition: ConfigurationFileLoader.h:54
PeersConfiguration.h
catapult::catapult_runtime_error
catapult_error< std::runtime_error > catapult_runtime_error
Definition: exceptions.h:87
catapult::utils::ConfigurationBag::FromPath
static ConfigurationBag FromPath(const std::string &path)
Loads a configuration bag from the specified path.
Definition: ConfigurationBag.cpp:45
catapult::model::NetworkIdentifier
NetworkIdentifier
Possible network identifiers.
Definition: NetworkInfo.h:45
ConfigurationBag.h
catapult::config::LoadPeersFromPath
std::vector< ionet::Node > LoadPeersFromPath(const std::string &path, model::NetworkIdentifier networkIdentifier)
Loads peers from the specified path for the network identified by networkIdentifier.
Definition: PeersConfiguration.cpp:106
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::config::LoadConfiguration
TConfiguration LoadConfiguration(const boost::filesystem::path &path, TConfigurationLoader loader)
Loads configuration from path using loader.
Definition: ConfigurationFileLoader.h:34