SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
Settings.h
Go to the documentation of this file.
1 /*
2  * SWC-DB© Copyright since 2019 Alex Kashirin <kashirin.alex@gmail.com>
3  * License details at <https://github.com/kashirin-alex/swc-db/#license>
4  */
5 
6 #ifndef swcdb_core_config_Config_h
7 #define swcdb_core_config_Config_h
8 
9 #include "swcdb/core/Exception.h"
12 
13 
14 namespace SWC {
15 
16 
22 namespace Config {
23 
24 
25 class Settings final : public Properties {
26 
27  public:
28 
29  typedef std::shared_ptr<Settings> Ptr;
30  typedef void init_option_t(Settings*);
31 
34 
35  std::string install_path;
36  std::string executable;
37 
38  Settings();
39 
40  Settings(Settings&&) = delete;
41  Settings(const Settings&) = delete;
42  Settings& operator=(Settings&&) = delete;
43  Settings& operator=(const Settings&) = delete;
44 
45  ~Settings() noexcept;
46 
47  void init(int argc, char *argv[],
48  init_option_t app, init_option_t post_cmd_args);
49 
50  void init_options();
51 
52  void parse_args(int argc, char *argv[]);
53 
54  void load_files_by(const char* fileprop, bool allow_unregistered);
55 
56  void parse_file(const std::string& fname, const char* onchg);
57 
58  void init_process(bool with_pid_file, const char* port_cfg = nullptr);
59 
60  std::string usage_str(const char *usage = nullptr);
61 
62  void check_dynamic_files() noexcept;
63 
64  private:
65 
66  Parser::Options m_cmd_args;
67 
68  struct DynFile {
69  const std::string filename;
70  time_t modified;
72  DynFile(std::string&& a_filename) noexcept
73  : filename(std::move(a_filename)), modified(0) {
74  }
75  DynFile(DynFile&& other) noexcept
76  : filename(std::move(other.filename)),
77  modified(other.modified) {
78  }
79  DynFile(const DynFile&) = delete;
80  DynFile& operator=(DynFile&&) = delete;
81  DynFile& operator=(const DynFile&) = delete;
83  ~DynFile() noexcept { }
85  bool operator==(const DynFile& other) const noexcept {
86  return other == filename;
87  }
89  bool operator==(const std::string& other) const noexcept {
90  return Condition::str_eq(filename, other);
91  }
92  };
94 };
95 
96 
97 }
98 
99 
101 namespace Env {
102 
103 class Config final {
104 
105  public:
106 
107  typedef std::shared_ptr<Config> Ptr;
108 
109  SWC_SHOULD_NOT_INLINE
110  static void init(
111  int argc,
112  char** argv,
115  get()->m_settings->init(argc, argv, init_app_options, init_post_cmd_args);
116  }
117 
118  static void set(Ptr env) noexcept {
119  m_env = env;
120  }
121 
122  static Ptr& get() {
123  if(!m_env)
124  m_env.reset(new Config());
125  return m_env;
126  }
127 
129  //SWC_ASSERT(m_env);
130  return m_env->m_settings;
131  }
132 
133  static void reset() noexcept {
134  m_env = nullptr;
135  }
136 
137  Config() : m_settings(new SWC::Config::Settings()) { }
138 
139  ~Config() noexcept { }
140 
141  private:
143  inline static Ptr m_env = nullptr;
144 
145 };
146 }
147 
148 }
149 
150 #ifdef SWC_IMPL_SOURCE
152 #endif
153 
154 #endif // swcdb_core_config_Config_h
SWC::Config::Parser
Definition: PropertiesParser.h:168
SWC::Config::Settings::m_cmd_args
Parser::Options m_cmd_args
Definition: Settings.h:66
SWC::Env::Config::reset
static void reset() noexcept
Definition: Settings.h:133
SWC::Config::Settings::init_process
void init_process(bool with_pid_file, const char *port_cfg=nullptr)
Definition: Settings.cc:340
SWC::Config::Settings::Ptr
std::shared_ptr< Settings > Ptr
Definition: Settings.h:29
SWC::Config::Settings::executable
std::string executable
Definition: Settings.h:36
SWC::Config::Settings::operator=
Settings & operator=(const Settings &)=delete
SWC::Env::Config::settings
static SWC::Config::Settings::Ptr & settings()
Definition: Settings.h:128
SWC::Config::init_app_options
void init_app_options(Settings *settings)
Definition: load_generator.cc:166
SWC::Config::Settings::m_dyn_files
Core::Vector< DynFile > m_dyn_files
Definition: Settings.h:93
SWC::Config::Settings::DynFile::operator==
SWC_CAN_INLINE bool operator==(const std::string &other) const noexcept
Definition: Settings.h:89
Properties.h
SWC::Env::Config::init
static SWC_SHOULD_NOT_INLINE void init(int argc, char **argv, SWC::Config::Settings::init_option_t init_app_options, SWC::Config::Settings::init_option_t init_post_cmd_args)
Definition: Settings.h:110
SWC::Config::Settings::DynFile::filename
const std::string filename
Definition: Settings.h:69
SWC::Config::Settings::operator=
Settings & operator=(Settings &&)=delete
SWC::Config::Settings::cmdline_desc
ParserConfig cmdline_desc
Definition: Settings.h:32
SWC::Config::Settings::DynFile::~DynFile
SWC_CAN_INLINE ~DynFile() noexcept
Definition: Settings.h:83
SWC::Env::Config::Ptr
std::shared_ptr< Config > Ptr
Definition: Settings.h:107
SWC::Env::Config
Definition: Settings.h:103
SWC::Config::Settings::DynFile::DynFile
SWC_CAN_INLINE DynFile(std::string &&a_filename) noexcept
Definition: Settings.h:72
SWC::Config::Settings::parse_file
void parse_file(const std::string &fname, const char *onchg)
Definition: Settings.cc:177
SWC::Condition::str_eq
bool str_eq(const char *s1, const char *s2) noexcept SWC_ATTRIBS((SWC_ATTRIB_O3))
Definition: Comparators_basic.h:237
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
Exception.h
SWC::Env::Config::m_settings
SWC::Config::Settings::Ptr m_settings
Definition: Settings.h:142
SWC::Env::Config::Config
Config()
Definition: Settings.h:137
SWC::Config::Settings::usage_str
std::string usage_str(const char *usage=nullptr)
Definition: Settings.cc:371
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::Config::Settings::Settings
Settings(const Settings &)=delete
SWC::Env::Config::get
static Ptr & get()
Definition: Settings.h:122
SWC::Config::Settings::file_desc
ParserConfig file_desc
Definition: Settings.h:33
SWC::Config::Settings::init_options
void init_options()
Definition: Settings.cc:103
SWC::Config::Settings::Settings
Settings(Settings &&)=delete
SWC::Config::ParserConfig
Definition: PropertiesParser.h:64
SWC::Config::Settings
Definition: Settings.h:25
Settings.cc
SWC::Config::Settings::DynFile::operator==
SWC_CAN_INLINE bool operator==(const DynFile &other) const noexcept
Definition: Settings.h:85
SWC::Config::Settings::DynFile::operator=
DynFile & operator=(DynFile &&)=delete
SWC::Env::Config::set
static void set(Ptr env) noexcept
Definition: Settings.h:118
SWC::Core::Vector
Definition: Vector.h:14
SWC::Config::Settings::DynFile::DynFile
DynFile(DynFile &&other) noexcept
Definition: Settings.h:75
SWC::Config::Settings::init
void init(int argc, char *argv[], init_option_t app, init_option_t post_cmd_args)
Definition: Settings.cc:50
SWC::Env::Config::~Config
~Config() noexcept
Definition: Settings.h:139
SWC::Config::init_post_cmd_args
void init_post_cmd_args(Settings *settings)
Definition: Settings.h:64
SWC::Config::Settings::DynFile::modified
time_t modified
Definition: Settings.h:70
SWC::Config::Properties
Definition: Properties.h:19
SWC::Env::Config::m_env
static Ptr m_env
Definition: Settings.h:143
SWC::Config::Settings::DynFile
Definition: Settings.h:68
SWC::Config::Settings::parse_args
void parse_args(int argc, char *argv[])
Definition: Settings.cc:143
SWC::Config::Settings::load_files_by
void load_files_by(const char *fileprop, bool allow_unregistered)
Definition: Settings.cc:196
SWC::Config::Settings::DynFile::DynFile
DynFile(const DynFile &)=delete
SWC::Config::Settings::init_option_t
void init_option_t(Settings *)
Definition: Settings.h:30
SWC::Config::Settings::Settings
Settings()
Definition: Settings.cc:37
SWC::Config::Settings::DynFile::operator=
DynFile & operator=(const DynFile &)=delete
SWC::Config::Settings::install_path
std::string install_path
Definition: Settings.h:35
SWC::Config::Settings::check_dynamic_files
void check_dynamic_files() noexcept
Definition: Settings.cc:400
SWC::Config::Settings::~Settings
~Settings() noexcept
Definition: Settings.cc:47
PropertiesParser.h