cmCableData.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2001 Insight Consortium
  8. All rights reserved.
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions are met:
  11. * Redistributions of source code must retain the above copyright notice,
  12. this list of conditions and the following disclaimer.
  13. * Redistributions in binary form must reproduce the above copyright notice,
  14. this list of conditions and the following disclaimer in the documentation
  15. and/or other materials provided with the distribution.
  16. * The name of the Insight Consortium, nor the names of any consortium members,
  17. nor of any contributors, may be used to endorse or promote products derived
  18. from this software without specific prior written permission.
  19. * Modified source versions must be plainly marked as such, and must not be
  20. misrepresented as being the original software.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
  22. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
  25. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. =========================================================================*/
  32. #ifndef cmCableData_h
  33. #define cmCableData_h
  34. #include "cmStandardIncludes.h"
  35. #include "cmCommand.h"
  36. class cmCableCommand;
  37. class cmCablePackageCommand;
  38. /** \class cmCableData
  39. * \brief Hold data in one location for all cmCableCommand subclasses.
  40. */
  41. class cmCableData
  42. {
  43. public:
  44. cmCableData(const cmCableCommand*, const std::string&);
  45. ~cmCableData();
  46. /**
  47. * Returns true if the given cmCableCommand is the owner of this
  48. * cmCableData.
  49. */
  50. bool OwnerIs(const cmCableCommand* owner) const
  51. { return (owner == m_Owner); }
  52. std::ostream& GetOutputStream()
  53. { return m_OutputFile; }
  54. void InitializeOutputFile();
  55. void CloseOutputFile();
  56. void WriteConfigurationHeader();
  57. void WriteConfigurationFooter();
  58. /**
  59. * Class to simplify indentation printing.
  60. */
  61. class Indentation
  62. {
  63. public:
  64. Indentation(int indent): m_Indent(indent) {}
  65. void Print(std::ostream& os) const;
  66. Indentation Next() const { return Indentation(m_Indent+2); }
  67. Indentation Previous() const { return Indentation(m_Indent-2); }
  68. private:
  69. int m_Indent;
  70. };
  71. void Indent() { m_Indentation = m_Indentation.Next(); }
  72. void Unindent() { m_Indentation = m_Indentation.Previous(); }
  73. const Indentation& GetIndentation() const { return m_Indentation; }
  74. void OpenNamespace(const std::string&);
  75. void CloseNamespace(const std::string&);
  76. void BeginPackage(cmCablePackageCommand*);
  77. void EndPackage();
  78. cmCablePackageCommand *GetCurrentPackage() { return m_Package; }
  79. private:
  80. /**
  81. * The cmCableCommand which created this instance of cmCableCommand.
  82. */
  83. const cmCableCommand* m_Owner;
  84. /**
  85. * The name of the output file opened as m_OutputFile.
  86. */
  87. std::string m_OutputFileName;
  88. /**
  89. * The output file to which the configuration is written.
  90. */
  91. std::ofstream m_OutputFile;
  92. /**
  93. * Current indentation for output.
  94. */
  95. Indentation m_Indentation;
  96. /**
  97. * The stack of namespaces.
  98. */
  99. std::list<std::string> m_NamespaceStack;
  100. /**
  101. * The command that created the package currently being defined.
  102. */
  103. cmCablePackageCommand* m_Package;
  104. /**
  105. * The namespace level at which the current package was created.
  106. * This must be the level when the package is ended.
  107. */
  108. unsigned int m_PackageNamespaceDepth;
  109. };
  110. std::ostream& operator<<(std::ostream&, const cmCableData::Indentation&);
  111. #endif