cmClassFile.cxx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2000 National Library of Medicine
  8. All rights reserved.
  9. See COPYRIGHT.txt for copyright details.
  10. =========================================================================*/
  11. #include "cmClassFile.h"
  12. #include "cmStandardIncludes.h"
  13. #include "cmSystemTools.h"
  14. // Set the name of the class and the full path to the file.
  15. // The class must be found in dir and end in name.cxx, name.txx,
  16. // name.c or it will be considered a header file only class
  17. // and not included in the build process
  18. void cmClassFile::SetName(const char* name, const char* dir)
  19. {
  20. m_HeaderFileOnly = true;
  21. m_ClassName = name;
  22. std::string pathname = dir;
  23. if(pathname != "")
  24. {
  25. pathname += "/";
  26. }
  27. // First try and see whether the listed file can be found
  28. // as is without extensions added on.
  29. pathname += m_ClassName;
  30. std::string hname = pathname;
  31. if(cmSystemTools::FileExists(hname.c_str()))
  32. {
  33. m_HeaderFileOnly = false;
  34. m_FullPath = hname;
  35. return;
  36. }
  37. // Try various extentions
  38. hname = pathname;
  39. hname += ".cxx";
  40. if(cmSystemTools::FileExists(hname.c_str()))
  41. {
  42. m_ClassExtension = "cxx";
  43. m_HeaderFileOnly = false;
  44. m_FullPath = hname;
  45. return;
  46. }
  47. hname = pathname;
  48. hname += ".c";
  49. if(cmSystemTools::FileExists(hname.c_str()))
  50. {
  51. m_HeaderFileOnly = false;
  52. m_ClassExtension = "c";
  53. m_FullPath = hname;
  54. return;
  55. }
  56. hname = pathname;
  57. hname += ".txx";
  58. if(cmSystemTools::FileExists(hname.c_str()))
  59. {
  60. m_HeaderFileOnly = false;
  61. m_ClassExtension = "txx";
  62. m_FullPath = hname;
  63. return;
  64. }
  65. hname = pathname;
  66. hname += ".h";
  67. if(cmSystemTools::FileExists(hname.c_str()))
  68. {
  69. m_ClassExtension = "h";
  70. m_FullPath = hname;
  71. return;
  72. }
  73. cmSystemTools::Error("can not find file ", hname.c_str());
  74. cmSystemTools::Error("Tried .txx .cxx .c for ", hname.c_str());
  75. }
  76. void cmClassFile::SetName(const char* name, const char* dir, const char *ext,
  77. bool hfo)
  78. {
  79. m_HeaderFileOnly = hfo;
  80. m_ClassName = name;
  81. std::string pathname = dir;
  82. if(pathname != "")
  83. {
  84. pathname += "/";
  85. }
  86. pathname += m_ClassName + "." + ext;
  87. m_FullPath = pathname;
  88. m_ClassExtension = ext;
  89. return;
  90. }
  91. void cmClassFile::Print() const
  92. {
  93. if(m_AbstractClass)
  94. {
  95. std::cout << "Abstract ";
  96. }
  97. else
  98. {
  99. std::cout << "Concrete ";
  100. }
  101. if(m_HeaderFileOnly)
  102. {
  103. std::cout << "Header file ";
  104. }
  105. else
  106. {
  107. std::cout << "CXX file ";
  108. }
  109. std::cout << m_ClassName << std::endl;
  110. }