You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.9 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software: you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation, either version 3 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * @file env_vars.h
  21. * Functions related to environment variables, including help functions
  22. */
  23. #ifndef ENV_VARS_H
  24. #define ENV_VARS_H
  25. #include <wx/string.h>
  26. #include <vector>
  27. #include <optional>
  28. namespace ENV_VAR
  29. {
  30. using ENV_VAR_LIST = std::vector<wxString>;
  31. /**
  32. * Determine if an environment variable is "predefined", i.e. if the
  33. * name of the variable is special to KiCad, and isn't just a user-specified
  34. * substitution name.
  35. * @param aEnvVar the variable to check
  36. * @return true if predefined
  37. */
  38. bool IsEnvVarImmutable( const wxString& aEnvVar );
  39. /**
  40. * Get the list of pre-defined environment variables.
  41. */
  42. const ENV_VAR_LIST& GetPredefinedEnvVars();
  43. /**
  44. * Look up long-form help text for a given environment variable.
  45. *
  46. * This is intended for use in more verbose help resources (as opposed to
  47. * tooltip text)
  48. *
  49. * @param aEnvVar The variable to look up
  50. * @return A string with help for that variable. Empty if
  51. * no help available for this variable.
  52. */
  53. wxString LookUpEnvVarHelp( const wxString& aEnvVar );
  54. /**
  55. * Get an environment variable as a specific type, if set correctly
  56. *
  57. * @param aEnvVarName the name of the environment variable
  58. * @return an std::optional containing the value, if set and parseable, otherwise empty.
  59. */
  60. template <typename VAL_TYPE>
  61. std::optional<VAL_TYPE> GetEnvVar( const wxString& aEnvVarName );
  62. /**
  63. * Get a string environment variable, if it is set.
  64. *
  65. * @param aEnvVarName the name of the environment variable
  66. * @return an std::optional containing the value, if set, otherwise empty.
  67. */
  68. template<>
  69. std::optional<wxString> GetEnvVar( const wxString& aEnvVarName );
  70. /**
  71. * Get a double from an environment variable, if set
  72. *
  73. * @param aEnvVarName the name of the environment variable
  74. * @return an std::optional containing the value, if set and parseable as a double,
  75. * otherwise empty.
  76. */
  77. template <>
  78. std::optional<double> GetEnvVar( const wxString& aEnvVarName );
  79. };
  80. #endif /* ENV_VARS_H */