PageRenderTime 27ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/spec/packagespecification.d

http://github.com/wilkie/djehuty
D | 101 lines | 67 code | 19 blank | 15 comment | 4 complexity | 02ffc6cab0477a3780b75df2b64e88ab MD5 | raw file
  1. /*
  2. * packagespecification.d
  3. *
  4. * This module implements a class that will provide an outlet to test an entire
  5. * package.
  6. *
  7. * Originated: May 6th, 2010
  8. *
  9. */
  10. module spec.packagespecification;
  11. import spec.modulespecification;
  12. import djehuty;
  13. class PackageSpecification {
  14. this(string name) {
  15. _name = name.dup;
  16. }
  17. string name() {
  18. return _name;
  19. }
  20. void add(ModuleSpecification spec) {
  21. _modules[spec.name] = spec;
  22. }
  23. void add(PackageSpecification spec) {
  24. _packages[spec.name] = spec;
  25. }
  26. PackageSpecification traverse(string name) {
  27. if (!(name in _packages)) {
  28. return null;
  29. }
  30. return _packages[name];
  31. }
  32. ModuleSpecification retrieve(string name) {
  33. if (!(name in _modules)) {
  34. return null;
  35. }
  36. return _modules[name];
  37. }
  38. int opApply(int delegate(ref PackageSpecification) loopBody) {
  39. foreach(pack; _packages.keys.sort) {
  40. if (loopBody(_packages[pack])) {
  41. return 1;
  42. }
  43. }
  44. return 1;
  45. }
  46. int opApply(int delegate(ref ModuleSpecification) loopBody) {
  47. foreach(mod; _modules.keys.sort) {
  48. if (loopBody(_modules[mod])) {
  49. return 1;
  50. }
  51. }
  52. return 1;
  53. }
  54. // Description: Print out the specification of the package, which serves as
  55. // documentation for the application.
  56. string toString() {
  57. // Package
  58. // Module
  59. // Item should do this
  60. // Item should do that
  61. return _toString("");
  62. }
  63. private:
  64. string _toString(string padding) {
  65. string ret = padding ~ _name ~ "\n";
  66. foreach(pack; _packages.values.sort) {
  67. ret ~= pack._toString(padding ~ " ");
  68. }
  69. foreach(mod; _modules.values.sort) {
  70. ret ~= padding ~ " " ~ mod.name ~ "\n";
  71. foreach(item; mod) {
  72. foreach(spec; item) {
  73. ret ~= padding ~ " " ~ item.name ~ " " ~ spec ~ "\n";
  74. }
  75. }
  76. }
  77. return ret;
  78. }
  79. string _name;
  80. ModuleSpecification _modules[string];
  81. PackageSpecification _packages[string];
  82. }