cmDefinitions.h 2.8 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. typedef std::list<cmDefinitions>::reverse_iterator StackIter;
  31. typedef std::list<cmDefinitions>::const_reverse_iterator StackConstIter;
  32. public:
  33. static const char* Get(const std::string& key,
  34. StackIter begin, StackIter end);
  35. static void Raise(const std::string& key, StackIter begin, StackIter end);
  36. static bool HasKey(const std::string& key,
  37. StackConstIter begin, StackConstIter end);
  38. /** Set (or unset if null) a value associated with a key. */
  39. void Set(const std::string& key, const char* value);
  40. std::vector<std::string> UnusedKeys() const;
  41. static std::vector<std::string> ClosureKeys(StackConstIter begin,
  42. StackConstIter end);
  43. static cmDefinitions MakeClosure(StackConstIter begin, StackConstIter end);
  44. private:
  45. // String with existence boolean.
  46. struct Def: public std::string
  47. {
  48. private:
  49. typedef std::string std_string;
  50. public:
  51. Def(): std_string(), Exists(false), Used(false) {}
  52. Def(const char* v)
  53. : std_string(v ? v : ""),
  54. Exists(v ? true : false),
  55. Used(false)
  56. {}
  57. Def(const std_string& v): std_string(v), Exists(true), Used(false) {}
  58. Def(Def const& d): std_string(d), Exists(d.Exists), Used(d.Used) {}
  59. bool Exists;
  60. bool Used;
  61. };
  62. static Def NoDef;
  63. #if defined(CMAKE_BUILD_WITH_CMAKE)
  64. #ifdef CMake_HAVE_CXX11_UNORDERED_MAP
  65. typedef std::unordered_map<std::string, Def> MapType;
  66. #else
  67. typedef cmsys::hash_map<std::string, Def> MapType;
  68. #endif
  69. #else
  70. typedef std::map<std::string, Def> MapType;
  71. #endif
  72. MapType Map;
  73. static Def const& GetInternal(const std::string& key,
  74. StackIter begin, StackIter end, bool raise);
  75. };
  76. #endif