cmVTKMakeInstantiatorCommand.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 cmVTKMakeInstantiatorCommand_h
  33. #define cmVTKMakeInstantiatorCommand_h
  34. #include "cmStandardIncludes.h"
  35. #include "cmCommand.h"
  36. /** \class cmVTKMakeInstantiatorCommand
  37. * cmVTKMakeInstantiatorCommand implements the VTK_MAKE_INSTANTIATOR
  38. * command. This generates a source file to add to a VTK library that
  39. * registers instance creation functions with vtkInstantiator for every
  40. * class in that library.
  41. */
  42. class cmVTKMakeInstantiatorCommand : public cmCommand
  43. {
  44. public:
  45. /** This is a virtual constructor for the command. */
  46. virtual cmCommand* Clone()
  47. { return new cmVTKMakeInstantiatorCommand; }
  48. /**
  49. * This is called when the command is first encountered in
  50. * the CMakeLists.txt file.
  51. */
  52. virtual bool InitialPass(std::vector<std::string> const& args);
  53. /** The name of the command as specified in CMakeList.txt. */
  54. virtual const char* GetName() { return "VTK_MAKE_INSTANTIATOR"; }
  55. /** Succinct documentation. */
  56. virtual const char* GetTerseDocumentation()
  57. {
  58. return "Register classes for creation by vtkInstantiator";
  59. }
  60. /** More documentation. */
  61. virtual const char* GetFullDocumentation()
  62. {
  63. return
  64. "VTK_MAKE_INSTANTIATOR(className outSourceList\n"
  65. " src-list1 [src-list2 ..]\n"
  66. " EXPORT_MACRO exportMacro\n"
  67. " [HEADER_LOCATION dir] [GROUP_SIZE groupSize])\n"
  68. "Generates a new class with the given name and adds its files to the\n"
  69. "given outSourceList. It registers the classes from the other given\n"
  70. "source lists with vtkInstantiator when it is loaded. The output\n"
  71. "source list should be added to the library with the classes it\n"
  72. "registers.\n"
  73. "The EXPORT_MACRO argument must be given and followed by the export\n"
  74. "macro to use when generating the class (ex. VTK_COMMON_EXPORT).\n"
  75. "The HEADER_LOCATION option must be followed by a path. It specifies\n"
  76. "the directory in which to place the generated class's header file.\n"
  77. "The generated class implementation files always go in the build\n"
  78. "directory corresponding to the CMakeLists.txt file containing\n"
  79. "the command. This is the default location for the header.\n"
  80. "The GROUP_SIZE option must be followed by a positive integer.\n"
  81. "As an implementation detail, the registered creation functions may\n"
  82. "be split up into multiple files. The groupSize option specifies\n"
  83. "the number of classes per file. Its default is 10.";
  84. }
  85. cmTypeMacro(cmVTKMakeInstantiatorCommand, cmCommand);
  86. protected:
  87. std::string m_ClassName;
  88. std::string m_ExportMacro;
  89. std::vector<cmStdString> m_Classes;
  90. std::string GenerateCreationFileName(unsigned int group);
  91. void GenerateHeaderFile(std::ostream&);
  92. void GenerateImplementationFile(std::ostream&);
  93. void GenerateCreationFile(std::ostream&, unsigned int groupStart,
  94. unsigned int groupSize);
  95. };
  96. #endif