executionEnvironment.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file executionEnvironment.h
  10. * @author drose
  11. * @date 2000-05-15
  12. */
  13. #ifndef EXECUTIONENVIRONMENT_H
  14. #define EXECUTIONENVIRONMENT_H
  15. #include "dtoolbase.h"
  16. #include "vector_string.h"
  17. #include "filename.h"
  18. #include <map>
  19. /**
  20. * Encapsulates access to the environment variables and command-line arguments
  21. * at the time of execution. This is encapsulated to support accessing these
  22. * things during static init time, which seems to be risky at best.
  23. */
  24. class EXPCL_DTOOL ExecutionEnvironment {
  25. private:
  26. ExecutionEnvironment();
  27. PUBLISHED:
  28. INLINE static bool has_environment_variable(const string &var);
  29. INLINE static string get_environment_variable(const string &var);
  30. INLINE static void set_environment_variable(const string &var, const string &value);
  31. INLINE static void shadow_environment_variable(const string &var, const string &value);
  32. INLINE static void clear_shadow(const string &var);
  33. static string expand_string(const string &str);
  34. INLINE static size_t get_num_args();
  35. INLINE static string get_arg(size_t n);
  36. INLINE static string get_binary_name();
  37. INLINE static string get_dtool_name();
  38. INLINE static void set_binary_name(const string &name);
  39. INLINE static void set_dtool_name(const string &name);
  40. static Filename get_cwd();
  41. PUBLISHED:
  42. MAKE_MAP_PROPERTY(environment_variables, has_environment_variable,
  43. get_environment_variable, set_environment_variable);
  44. MAKE_SEQ_PROPERTY(args, get_num_args, get_arg);
  45. MAKE_PROPERTY(binary_name, get_binary_name, set_binary_name);
  46. MAKE_PROPERTY(dtool_name, get_dtool_name, set_dtool_name);
  47. MAKE_PROPERTY(cwd, get_cwd);
  48. private:
  49. bool ns_has_environment_variable(const string &var) const;
  50. string ns_get_environment_variable(const string &var) const;
  51. void ns_set_environment_variable(const string &var, const string &value);
  52. void ns_shadow_environment_variable(const string &var, const string &value);
  53. void ns_clear_shadow(const string &var);
  54. size_t ns_get_num_args() const;
  55. string ns_get_arg(size_t n) const;
  56. string ns_get_binary_name() const;
  57. string ns_get_dtool_name() const;
  58. static ExecutionEnvironment *get_ptr();
  59. void read_environment_variables();
  60. void read_args();
  61. private:
  62. typedef map<string, string> EnvironmentVariables;
  63. EnvironmentVariables _variables;
  64. typedef vector_string CommandArguments;
  65. CommandArguments _args;
  66. string _binary_name;
  67. string _dtool_name;
  68. static ExecutionEnvironment *_global_ptr;
  69. };
  70. #include "executionEnvironment.I"
  71. #endif