|
|
@@ -17,10 +17,7 @@
|
|
|
|
|
|
#include "dtoolbase.h"
|
|
|
|
|
|
-#include "config_setup.h"
|
|
|
#include "config_dconfig.h"
|
|
|
-#include "configTable.h"
|
|
|
-#include "executionEnvironment.h"
|
|
|
#include "configVariableString.h"
|
|
|
#include "configVariableBool.h"
|
|
|
#include "configVariableInt.h"
|
|
|
@@ -28,290 +25,56 @@
|
|
|
#include "configVariableList.h"
|
|
|
#include "configFlags.h"
|
|
|
|
|
|
-#include <vector>
|
|
|
-#include <map>
|
|
|
-#include <time.h>
|
|
|
-
|
|
|
-namespace Config {
|
|
|
-
|
|
|
-// Config is, itself, configurable. The things that can be set are:
|
|
|
-// path separator ( ': ' ) [pathsep]
|
|
|
-// filename separator ( / ) [filesep]
|
|
|
-// config filename ( Configrc ) [configname]
|
|
|
-// config file suffix ( ) [configsuffix]
|
|
|
-// config file path ( $CONFIG_PATH ) [configpath]
|
|
|
-// (can be multiple of these)
|
|
|
-// config file comment ( '#' ) [configcmt]
|
|
|
-// 'args' suffix ( _ARGS ) [argsuffix]
|
|
|
-// command arg env ( CONFIG + _____ ) [commandstub]
|
|
|
-// debugging output ( false ) [configdbg]
|
|
|
-// read commandline ( true ) [readargs]
|
|
|
-// read environment ( true ) [readenv]
|
|
|
-// all of these can be set from the one unconfigurable thing in config, the
|
|
|
-// environment variable called CONFIG_CONFIG. The format is:
|
|
|
-// separator_char{{field_id}={field_value}separator_char}*
|
|
|
-
|
|
|
-// Call these functions to get stats on how Config is spending its
|
|
|
-// time.
|
|
|
-EXPCL_DTOOLCONFIG INLINE double get_total_time_config_init();
|
|
|
-EXPCL_DTOOLCONFIG INLINE double get_total_time_external_init();
|
|
|
-EXPCL_DTOOLCONFIG INLINE double get_total_num_get();
|
|
|
-
|
|
|
-// These globals are intended for internal bookkeeping by Config to
|
|
|
-// compute the above functions' return values.
|
|
|
-EXPCL_DTOOLCONFIG extern clock_t total_time_config_init;
|
|
|
-EXPCL_DTOOLCONFIG extern clock_t total_time_external_init;
|
|
|
-EXPCL_DTOOLCONFIG extern int total_num_get;
|
|
|
-
|
|
|
-template <class GetConfig>
|
|
|
-class Config {
|
|
|
-public:
|
|
|
- Config();
|
|
|
- ~Config();
|
|
|
- static bool AmInitializing();
|
|
|
- static ConfigString Name();
|
|
|
- static bool Flag();
|
|
|
- static void Init();
|
|
|
- static bool Defined(const ConfigString& sym);
|
|
|
- static ConfigString Get(const ConfigString sym);
|
|
|
- static ConfigTable::Symbol& GetAll(const ConfigString,
|
|
|
- ConfigTable::Symbol&);
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Class : DConfig
|
|
|
+// Description : This class emulates the old dconfig-style interface
|
|
|
+// to our Panda config system. It exists only to
|
|
|
+// provide backward-compatible support, and it is used
|
|
|
+// primarily by Python code. For modern code, use the
|
|
|
+// new ConfigVariable* interface instead of this
|
|
|
+// deprecated interface.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+class EXPCL_DTOOLCONFIG DConfig {
|
|
|
PUBLISHED:
|
|
|
- static bool GetBool(const ConfigString sym, bool def = false);
|
|
|
- static int GetInt(const ConfigString sym, int def = 0);
|
|
|
- static float GetFloat(const ConfigString sym, float def = 0.);
|
|
|
- static double GetDouble(const ConfigString sym, double def = 0.);
|
|
|
- static ConfigString GetString(const ConfigString sym,
|
|
|
- const ConfigString def = "");
|
|
|
-protected:
|
|
|
- static void ConfigFunc();
|
|
|
- static void Flag(bool);
|
|
|
+ static INLINE bool GetBool(const string &sym, bool def = false);
|
|
|
+ static INLINE int GetInt(const string &sym, int def = 0);
|
|
|
+ static INLINE float GetFloat(const string &sym, float def = 0.);
|
|
|
+ static INLINE double GetDouble(const string &sym, double def = 0.);
|
|
|
+ static INLINE string GetString(const string &sym, const string &def = "");
|
|
|
};
|
|
|
|
|
|
-// Implementation follows
|
|
|
-
|
|
|
-template<class GetConfig>
|
|
|
-void Config<GetConfig>::ConfigFunc() {
|
|
|
- GetConfig::config_func();
|
|
|
-}
|
|
|
-
|
|
|
-template<class GetConfig>
|
|
|
-bool Config<GetConfig>::AmInitializing() {
|
|
|
- return false;
|
|
|
-}
|
|
|
-
|
|
|
-template<class GetConfig>
|
|
|
-ConfigString Config<GetConfig>::Name() {
|
|
|
- return GetConfig::get_name();
|
|
|
-}
|
|
|
-
|
|
|
-template<class GetConfig>
|
|
|
-bool Config<GetConfig>::Flag() {
|
|
|
- return GetConfig::_flag;
|
|
|
-}
|
|
|
-
|
|
|
-template<class GetConfig>
|
|
|
-void Config<GetConfig>::Flag(bool f) {
|
|
|
- GetConfig::_flag = f;
|
|
|
-}
|
|
|
-
|
|
|
-template<class GetConfig>
|
|
|
-void Config<GetConfig>::Init() {
|
|
|
- if (Flag())
|
|
|
- return;
|
|
|
-
|
|
|
- Flag(true);
|
|
|
-
|
|
|
- ConfigFunc();
|
|
|
-}
|
|
|
-
|
|
|
-template<class GetConfig>
|
|
|
-Config<GetConfig>::Config() {
|
|
|
- Init();
|
|
|
-}
|
|
|
-
|
|
|
-template<class GetConfig>
|
|
|
-Config<GetConfig>::~Config() {
|
|
|
-}
|
|
|
-
|
|
|
-template<class GetConfig>
|
|
|
-bool Config<GetConfig>::Defined(const ConfigString& sym)
|
|
|
-{
|
|
|
- Init();
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
-template<class GetConfig>
|
|
|
-ConfigString Config<GetConfig>::Get(ConfigString sym)
|
|
|
-{
|
|
|
- Init();
|
|
|
- ConfigVariableString var(sym);
|
|
|
- return var.get_value();
|
|
|
-}
|
|
|
-
|
|
|
-template<class GetConfig>
|
|
|
-ConfigTable::Symbol& Config<GetConfig>::GetAll(const ConfigString sym,
|
|
|
- ConfigTable::Symbol& s)
|
|
|
-{
|
|
|
- Init();
|
|
|
- ConfigVariableList var(sym, "DConfig", ConfigFlags::F_dconfig);
|
|
|
-
|
|
|
- int num_values = var.get_num_values();
|
|
|
- for (int i = 0; i < num_values; ++i) {
|
|
|
- string value = var.get_string_value(i);
|
|
|
- s.push_back(SymbolEnt(SymbolEnt::ConfigFile, value));
|
|
|
- }
|
|
|
-
|
|
|
- return s;
|
|
|
-}
|
|
|
-
|
|
|
-template<class GetConfig>
|
|
|
-bool Config<GetConfig>::GetBool(const ConfigString sym, bool def)
|
|
|
-{
|
|
|
- Init();
|
|
|
- ConfigVariableBool var(sym, def, "DConfig", ConfigFlags::F_dconfig);
|
|
|
- return var.get_value();
|
|
|
-}
|
|
|
-
|
|
|
-template<class GetConfig>
|
|
|
-int Config<GetConfig>::GetInt(const ConfigString sym, int def)
|
|
|
-{
|
|
|
- Init();
|
|
|
- ConfigVariableInt var(sym, def, "DConfig", ConfigFlags::F_dconfig);
|
|
|
- return var.get_value();
|
|
|
-}
|
|
|
-
|
|
|
-template<class GetConfig>
|
|
|
-float Config<GetConfig>::GetFloat(const ConfigString sym, float def)
|
|
|
-{
|
|
|
- Init();
|
|
|
- ConfigVariableDouble var(sym, def, "DConfig", ConfigFlags::F_dconfig);
|
|
|
- return var.get_value();
|
|
|
-}
|
|
|
-
|
|
|
-template<class GetConfig>
|
|
|
-double Config<GetConfig>::GetDouble(const ConfigString sym, double def)
|
|
|
-{
|
|
|
- Init();
|
|
|
- ConfigVariableDouble var(sym, def, "DConfig", ConfigFlags::F_dconfig);
|
|
|
- return var.get_value();
|
|
|
-}
|
|
|
-
|
|
|
-template<class GetConfig>
|
|
|
-ConfigString Config<GetConfig>::GetString(const ConfigString sym,
|
|
|
- const ConfigString def)
|
|
|
-{
|
|
|
- Init();
|
|
|
- ConfigVariableString var(sym, def, "DConfig", ConfigFlags::F_dconfig);
|
|
|
- return var.get_value();
|
|
|
-}
|
|
|
-
|
|
|
#include "dconfig.I"
|
|
|
|
|
|
-} // close Config namespace
|
|
|
|
|
|
+// These macros are used in each directory to call an initialization
|
|
|
+// function at static-init time. These macros may eventually be
|
|
|
+// phased out in favor of a simpler interface that does not require
|
|
|
+// static init.
|
|
|
|
|
|
-// Finally, here is a set of handy macros to define and reference a
|
|
|
-// Configure object in each package.
|
|
|
+// This macro should appear in the config_*.h file.
|
|
|
|
|
|
-// This macro defines an external reference to a suitable Configure
|
|
|
-// object; it should appear in the config_*.h file. The config object
|
|
|
-// will be named name.
|
|
|
+#define ConfigureDecl(name, expcl, exptp)
|
|
|
|
|
|
-#if defined(WIN32_VC) && !defined(CPPPARSER)
|
|
|
+// This macro defines the actual declaration of the object defined
|
|
|
+// above; it should appear in the config_*.cxx file.
|
|
|
|
|
|
-#define ConfigureDecl(name, expcl, exptp) \
|
|
|
- class expcl ConfigureGetConfig_ ## name { \
|
|
|
- public: \
|
|
|
- static const char *get_name(); \
|
|
|
- static void config_func(); \
|
|
|
- static bool _flag; \
|
|
|
- }; \
|
|
|
- exptp template class expcl Config::Config<ConfigureGetConfig_ ## name>; \
|
|
|
- extern expcl Config::Config<ConfigureGetConfig_ ## name> name;
|
|
|
-
|
|
|
-#else // WIN32_VC
|
|
|
-
|
|
|
-#define ConfigureDecl(name, expcl, exptp) \
|
|
|
- class expcl ConfigureGetConfig_ ## name { \
|
|
|
+#define ConfigureDef(name) \
|
|
|
+ class StaticInitializer_ ## name { \
|
|
|
public: \
|
|
|
- static const char *get_name(); \
|
|
|
- static void config_func(); \
|
|
|
- static bool _flag; \
|
|
|
+ StaticInitializer_ ## name(); \
|
|
|
}; \
|
|
|
- extern expcl Config::Config<ConfigureGetConfig_ ## name> name;
|
|
|
-
|
|
|
-#endif // WIN32_VC
|
|
|
-
|
|
|
-// This macro defines the actual declaration of the Configure object
|
|
|
-// defined above; it should appear in the config_*.C file.
|
|
|
-
|
|
|
-#if defined(PENV_OSX)
|
|
|
-#define ConfigureDef(name) \
|
|
|
- Config::Config<ConfigureGetConfig_ ## name> name; \
|
|
|
- bool ConfigureGetConfig_ ## name::_flag = false; \
|
|
|
- int FILE_SYM_NAME = 0; \
|
|
|
- const char *ConfigureGetConfig_ ## name:: \
|
|
|
- get_name() { \
|
|
|
- return #name; \
|
|
|
- }
|
|
|
-#else /* PENV_OSX */
|
|
|
-#define ConfigureDef(name) \
|
|
|
- Config::Config<ConfigureGetConfig_ ## name> name; \
|
|
|
- bool ConfigureGetConfig_ ## name::_flag = false; \
|
|
|
- const char *ConfigureGetConfig_ ## name:: \
|
|
|
- get_name() { \
|
|
|
- return #name; \
|
|
|
- }
|
|
|
-#endif /* PENV_OSX */
|
|
|
+ static StaticInitializer_ ## name name;
|
|
|
|
|
|
// This macro can be used in lieu of the above two when the Configure
|
|
|
// object does not need to be visible outside of the current C file.
|
|
|
|
|
|
-#if defined(PENV_OSX)
|
|
|
-#define Configure(name) \
|
|
|
- class ConfigureGetConfig_ ## name { \
|
|
|
- public: \
|
|
|
- static const char *get_name(); \
|
|
|
- static void config_func(); \
|
|
|
- static bool _flag; \
|
|
|
- }; \
|
|
|
- static Config::Config<ConfigureGetConfig_ ## name> name; \
|
|
|
- bool ConfigureGetConfig_ ## name::_flag = false; \
|
|
|
- int FILE_SYM_NAME = 0; \
|
|
|
- const char *ConfigureGetConfig_ ## name:: \
|
|
|
- get_name() { \
|
|
|
- return #name; \
|
|
|
- }
|
|
|
-#else /* PENV_OSX */
|
|
|
-#define Configure(name) \
|
|
|
- class ConfigureGetConfig_ ## name { \
|
|
|
- public: \
|
|
|
- static const char *get_name(); \
|
|
|
- static void config_func(); \
|
|
|
- static bool _flag; \
|
|
|
- }; \
|
|
|
- static Config::Config<ConfigureGetConfig_ ## name> name; \
|
|
|
- bool ConfigureGetConfig_ ## name::_flag = false; \
|
|
|
- const char *ConfigureGetConfig_ ## name:: \
|
|
|
- get_name() { \
|
|
|
- return #name; \
|
|
|
- }
|
|
|
-#endif /* PENV_OSX */
|
|
|
+#define Configure(name) ConfigureDef(name)
|
|
|
|
|
|
// This one defines a block of code that will be executed at static
|
|
|
// init time. It must always be defined (in the C file), even if no
|
|
|
// code is to be executed.
|
|
|
|
|
|
#define ConfigureFn(name) \
|
|
|
- void ConfigureGetConfig_ ## name::config_func()
|
|
|
-
|
|
|
-#if defined(PENV_OSX)
|
|
|
-// This is a hack to provide a unique locatable symbol in each lib.
|
|
|
-#define ConfigureLibSym \
|
|
|
- char LIB_SYMBOL_NAME[] = ALL_FILE_SYMS_NAME ;
|
|
|
-#else
|
|
|
-#define ConfigureLibSym
|
|
|
-#endif /* PENV_OSX */
|
|
|
+ StaticInitializer_ ## name::StaticInitializer_ ## name()
|
|
|
|
|
|
#endif /* __CONFIG_H__ */
|