cmDefinitions.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #include "cmsys/hash_map.hxx"
  15. #endif
  16. #include <list>
  17. /** \class cmDefinitions
  18. * \brief Store a scope of variable definitions for CMake language.
  19. *
  20. * This stores the state of variable definitions (set or unset) for
  21. * one scope. Sets are always local. Gets search parent scopes
  22. * transitively and save results locally.
  23. */
  24. class cmDefinitions
  25. {
  26. typedef std::list<cmDefinitions>::reverse_iterator StackIter;
  27. typedef std::list<cmDefinitions>::const_reverse_iterator StackConstIter;
  28. public:
  29. /** Get the value associated with a key; null if none.
  30. Store the result locally if it came from a parent. */
  31. static const char* Get(const std::string& key,
  32. StackIter begin, StackIter end);
  33. /** Set (or unset if null) a value associated with a key. */
  34. void Set(const std::string& key, const char* value);
  35. void Erase(const std::string& key);
  36. /** Get the set of all local keys. */
  37. std::vector<std::string> LocalKeys() const;
  38. static std::vector<std::string> ClosureKeys(StackConstIter begin,
  39. StackConstIter end);
  40. static cmDefinitions MakeClosure(StackConstIter begin, StackConstIter end);
  41. private:
  42. // String with existence boolean.
  43. struct Def: public std::string
  44. {
  45. private:
  46. typedef std::string std_string;
  47. public:
  48. Def(): std_string(), Exists(false) {}
  49. Def(const char* v): std_string(v?v:""), Exists(v?true:false) {}
  50. Def(const std_string& v): std_string(v), Exists(true) {}
  51. Def(Def const& d): std_string(d), Exists(d.Exists) {}
  52. bool Exists;
  53. };
  54. static Def NoDef;
  55. // Local definitions, set or unset.
  56. #if defined(CMAKE_BUILD_WITH_CMAKE)
  57. typedef cmsys::hash_map<std::string, Def> MapType;
  58. #else
  59. typedef std::map<std::string, Def> MapType;
  60. #endif
  61. MapType Map;
  62. static Def const& GetInternal(const std::string& key,
  63. StackIter begin, StackIter end);
  64. };
  65. #endif