0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Init.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Hypertable. If not, see <http://www.gnu.org/licenses/>
18  */
19 
27 #ifndef Common_Init_h
28 #define Common_Init_h
29 
30 #include <Common/Config.h>
31 #include <Common/System.h>
32 
33 namespace Hypertable { namespace Config {
34 
52  template <class PolicyT>
53  inline void init_with_policy(int argc, char *argv[], const Desc *desc = 0) {
54  try {
56 
57  std::lock_guard<std::recursive_mutex> lock(rec_mutex);
58  properties = std::make_shared<Properties>();
59 
60  if (desc)
61  cmdline_desc(*desc);
62 
63  PolicyT::init_options();
64  parse_args(argc, argv);
65  PolicyT::init();
66  sync_aliases(); // init can generate more aliases
67 
68  if (get_bool("verbose"))
69  properties->print(std::cout);
70  }
71  catch (Exception &e) {
72  PolicyT::on_init_error(e);
73  }
74  }
75 
83  template <class PolicyListT>
84  inline void init_with_policies(int argc, char *argv[], const Desc *desc = 0) {
85  typedef typename Join<PolicyListT>::type Combined;
86  init_with_policy<Combined>(argc, argv, desc);
87  }
88 
95  inline void init(int argc, char *argv[], const Desc *desc = NULL) {
96  init_with_policy<DefaultPolicy>(argc, argv, desc);
97  }
98 
101 }}
102 
103 #endif /* Common_Init_h */
Retrieves system information (hardware, installation directory, etc)
PropertiesPtr properties
This singleton map stores all options.
Definition: Config.cc:47
void init(int argc, char *argv[], const Desc *desc=NULL)
Initialize with default policy.
Definition: Init.h:95
static void initialize(const String &install_directory=String())
Initializes the static class members; checks header version vs.
Definition: System.h:72
PropertiesDesc Desc
Definition: Config.h:44
Desc & cmdline_desc(const char *usage)
A macro which definds global functions like get_bool(), get_str(), get_i16() etc. ...
Definition: Config.cc:72
void init_with_policies(int argc, char *argv[], const Desc *desc=0)
Convenience function (more of a demo) to init with a list of polices.
Definition: Init.h:84
void parse_args(int argc, char *argv[])
Initialization helper; parses the argc/argv parameters into properties, reads the configuration file...
Definition: Config.cc:567
Hypertable definitions
void sync_aliases()
Sync alias values.
Definition: Config.cc:611
std::recursive_mutex rec_mutex
A global (recursive) configuration mutex.
Definition: Config.cc:46
This is a generic exception class for Hypertable.
Definition: Error.h:314
Configuration settings.
Meta::fold< PolicyListT, NullPolicy, Cons< Meta::_1, Meta::_2 > >::type type
Definition: Config.h:208
void init_with_policy(int argc, char *argv[], const Desc *desc=0)
Init with policy (with init_options (called before parse_args) and init (called after parse_args) met...
Definition: Init.h:53