PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/src/PhpGenerator/UmlClassMember.cpp

http://github.com/gregsmirnov/bouml
C++ | 196 lines | 63 code | 12 blank | 121 comment | 17 complexity | df083be5828bfff6c5fa93302431b310 MD5 | raw file
Possible License(s): GPL-2.0
  1. // *************************************************************************
  2. //
  3. // Copyright 2004-2010 Bruno PAGES .
  4. //
  5. // This file is part of the BOUML Uml Toolkit.
  6. //
  7. // This program is free software; you can redistribute it and/or modify
  8. // it under the terms of the GNU General Public License as published by
  9. // the Free Software Foundation; either version 2 of the License, or
  10. // (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License
  18. // along with this program; if not, write to the Free Software
  19. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. //
  21. // e-mail : bouml@free.fr
  22. // home : http://bouml.free.fr
  23. //
  24. // *************************************************************************
  25. #include <qtextstream.h>
  26. #include "UmlClassMember.h"
  27. #include "UmlCom.h"
  28. #include "UmlTypeSpec.h"
  29. #include "UmlSettings.h"
  30. #include "PhpSettings.h"
  31. void UmlClassMember::generate_require_onces(QTextOStream &, QCString &) {
  32. }
  33. void UmlClassMember::remove_comments(QCString & s)
  34. {
  35. int index1 = 0;
  36. if ((index1 = s.find("${comment}")) != -1)
  37. s.remove((unsigned) index1, 10);
  38. else if ((index1 = s.find("${description}")) != -1)
  39. s.remove((unsigned) index1, 14);
  40. while ((index1 = s.find('/', index1)) != -1) {
  41. int index2;
  42. switch (((const char *) s)[index1 + 1]) {
  43. case '/':
  44. if ((index2 = s.find('\n', index1 + 2)) != -1)
  45. s.remove(index1, index2 - index1 + 1);
  46. else
  47. s.truncate(index1);
  48. break;
  49. case '*':
  50. if ((index2 = s.find("*/", index1 + 2)) != -1)
  51. s.replace(index1, index2 - index1 + 1, " ");
  52. else
  53. s.truncate(index1);
  54. break;
  55. default:
  56. index1 += 1;
  57. }
  58. }
  59. }
  60. void UmlClassMember::remove_arrays(QCString & s)
  61. {
  62. int index1 = 0;
  63. while ((index1 = s.find('[', index1)) != -1) {
  64. int index2 = index1 = s.find(']', index1 + 1);
  65. if (index2 == -1) {
  66. s.truncate(index1);
  67. return;
  68. }
  69. else
  70. s.replace(index1, index2 - index1 + 1, " ");
  71. }
  72. }
  73. void UmlClassMember::generate_visibility(QTextOStream & f) {
  74. switch (visibility()) {
  75. case PublicVisibility:
  76. f << "public ";
  77. break;
  78. case ProtectedVisibility:
  79. f << "protected ";
  80. break;
  81. case PrivateVisibility:
  82. f << "private ";
  83. break;
  84. default: // package
  85. break;
  86. }
  87. }
  88. /*
  89. bool UmlClassMember::compute_dependency(QList<PhpRefType> & dependencies,
  90. QCString decl, const UmlTypeSpec & t)
  91. {
  92. remove_comments(decl);
  93. remove_arrays(decl);
  94. bool have_type = FALSE;
  95. const char * p = decl;
  96. const char * dontsubstituteuntil = 0;
  97. for (;;) {
  98. UmlTypeSpec ts;
  99. char c;
  100. bool dontsearchend = FALSE;
  101. // search word beginning
  102. while ((c = *p) != 0) {
  103. if ((c == '_') ||
  104. ((c >= 'a') && (c <= 'z')) ||
  105. ((c >= 'A') && (c <= 'Z')))
  106. break;
  107. else if (dontsubstituteuntil != 0) {
  108. if (p >= dontsubstituteuntil)
  109. dontsubstituteuntil = 0;
  110. p += 1;
  111. }
  112. else if (c == '=')
  113. // init, all is done
  114. return have_type;
  115. else if (!strncmp(p, "${type}", 7)) {
  116. p += 7;
  117. ts = t;
  118. if (ts.type != 0) {
  119. dontsearchend = TRUE;
  120. break;
  121. }
  122. else {
  123. decl = ts.explicit_type + p;
  124. p = decl;
  125. }
  126. }
  127. else
  128. p += 1;
  129. }
  130. if (c == 0)
  131. return have_type;
  132. if (!dontsearchend) {
  133. // search word end
  134. const char * p2 = p;
  135. ts.explicit_type = p2;
  136. p += 1;
  137. while ((c = *p) != 0) {
  138. if ((c == '_') ||
  139. (c == ':') ||
  140. ((c >= 'a') && (c <= 'z')) ||
  141. ((c >= 'A') && (c <= 'Z')) ||
  142. ((c >= '0') && (c <= '9')))
  143. p += 1;
  144. else {
  145. ts.explicit_type.truncate(p - p2);
  146. break;
  147. }
  148. }
  149. if ((p2 = strrchr(ts.explicit_type, ':')) != 0)
  150. // remove package name !!!
  151. ts.explicit_type = p2 + 1;
  152. if (dontsubstituteuntil == 0) {
  153. QCString subst = PhpSettings::type(ts.explicit_type);
  154. if (subst != ts.explicit_type) {
  155. decl = subst + ' ' + p;
  156. p = decl;
  157. dontsubstituteuntil = p + subst.length();
  158. continue;
  159. }
  160. }
  161. }
  162. // check manually added keyword
  163. if ((ts.explicit_type == "const") ||
  164. (ts.explicit_type == "static"))
  165. continue;
  166. if (PhpRefType::add(ts, dependencies))
  167. have_type = TRUE;
  168. }
  169. return have_type;
  170. }
  171. */