cmDefinitions.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. /** Get the value associated with a key; null if none.
  34. Store the result locally if it came from a parent. */
  35. static const char* Get(const std::string& key,
  36. StackIter begin, StackIter end);
  37. /** Set (or unset if null) a value associated with a key. */
  38. void Set(const std::string& key, const char* value);
  39. void Erase(const std::string& key);
  40. /** Get the set of all local keys. */
  41. std::vector<std::string> LocalKeys() const;
  42. static std::vector<std::string> ClosureKeys(StackConstIter begin,
  43. StackConstIter end);
  44. static cmDefinitions MakeClosure(StackConstIter begin, StackConstIter end);
  45. private:
  46. // String with existence boolean.
  47. struct Def: public std::string
  48. {
  49. private:
  50. typedef std::string std_string;
  51. public:
  52. Def(): std_string(), Exists(false) {}
  53. Def(const char* v): std_string(v?v:""), Exists(v?true:false) {}
  54. Def(const std_string& v): std_string(v), Exists(true) {}
  55. Def(Def const& d): std_string(d), Exists(d.Exists) {}
  56. bool Exists;
  57. };
  58. static Def NoDef;
  59. #if defined(CMAKE_BUILD_WITH_CMAKE)
  60. #ifdef CMake_HAVE_CXX11_UNORDERED_MAP
  61. typedef std::unordered_map<std::string, Def> MapType;
  62. #else
  63. typedef cmsys::hash_map<std::string, Def> MapType;
  64. #endif
  65. #else
  66. typedef std::map<std::string, Def> MapType;
  67. #endif
  68. MapType Map;
  69. static Def const& GetInternal(const std::string& key,
  70. StackIter begin, StackIter end);
  71. };
  72. #endif