cmDefinitions.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmDefinitions_h
  11. #define cmDefinitions_h
  12. #include "cmStandardIncludes.h"
  13. #if defined(CMAKE_BUILD_WITH_CMAKE)
  14. #ifdef CMake_HAVE_CXX11_UNORDERED_MAP
  15. #include <unordered_map>
  16. #else
  17. #include "cmsys/hash_map.hxx"
  18. #endif
  19. #endif
  20. #include <list>
  21. /** \class cmDefinitions
  22. * \brief Store a scope of variable definitions for CMake language.
  23. *
  24. * This stores the state of variable definitions (set or unset) for
  25. * one scope. Sets are always local. Gets search parent scopes
  26. * transitively and save results locally.
  27. */
  28. class cmDefinitions
  29. {
  30. public:
  31. /** Get the value associated with a key; null if none.
  32. Store the result locally if it came from a parent. */
  33. static const char* Get(const std::string& key,
  34. std::list<cmDefinitions>::reverse_iterator rbegin,
  35. std::list<cmDefinitions>::reverse_iterator rend);
  36. /** Set (or unset if null) a value associated with a key. */
  37. void Set(const std::string& key, const char* value);
  38. void Erase(const std::string& key);
  39. /** Get the set of all local keys. */
  40. std::vector<std::string> LocalKeys() const;
  41. std::vector<std::string>
  42. ClosureKeys(std::set<std::string>& bound) const;
  43. static cmDefinitions MakeClosure(
  44. std::list<cmDefinitions>::const_reverse_iterator rbegin,
  45. std::list<cmDefinitions>::const_reverse_iterator rend);
  46. private:
  47. // String with existence boolean.
  48. struct Def: public std::string
  49. {
  50. private:
  51. typedef std::string std_string;
  52. public:
  53. Def(): std_string(), Exists(false) {}
  54. Def(const char* v): std_string(v?v:""), Exists(v?true:false) {}
  55. Def(const std_string& v): std_string(v), Exists(true) {}
  56. Def(Def const& d): std_string(d), Exists(d.Exists) {}
  57. bool Exists;
  58. };
  59. static Def NoDef;
  60. #if defined(CMAKE_BUILD_WITH_CMAKE)
  61. #ifdef CMake_HAVE_CXX11_UNORDERED_MAP
  62. typedef std::unordered_map<std::string, Def> MapType;
  63. #else
  64. typedef cmsys::hash_map<std::string, Def> MapType;
  65. #endif
  66. #else
  67. typedef std::map<std::string, Def> MapType;
  68. #endif
  69. MapType Map;
  70. static Def const& GetInternal(const std::string& key,
  71. std::list<cmDefinitions>::reverse_iterator rbegin,
  72. std::list<cmDefinitions>::reverse_iterator rend);
  73. void MakeClosure(std::set<std::string>& undefined,
  74. std::list<cmDefinitions>::const_reverse_iterator rbegin,
  75. std::list<cmDefinitions>::const_reverse_iterator rend);
  76. };
  77. #endif