/spec/specification.d

http://github.com/wilkie/djehuty · D · 61 lines · 35 code · 12 blank · 14 comment · 2 complexity · 6e42811440ceb03a8ec5280fcdb5a753 MD5 · raw file

  1. /*
  2. * specification.d
  3. *
  4. * This module facilitates specifying the application.
  5. *
  6. * Originated: May 6th, 2010
  7. *
  8. */
  9. module spec.specification;
  10. import spec.packagespecification;
  11. import djehuty;
  12. class Specification {
  13. static:
  14. string name() {
  15. return Djehuty.app.name;
  16. }
  17. void add(PackageSpecification spec) {
  18. _packages[spec.name] = spec;
  19. }
  20. PackageSpecification traverse(string name) {
  21. if (!(name in _packages)) {
  22. return null;
  23. }
  24. return _packages[name];
  25. }
  26. int opApply(int delegate(ref PackageSpecification) loopBody) {
  27. foreach(pack; _packages.values.sort) {
  28. if (loopBody(pack)) {
  29. return 1;
  30. }
  31. }
  32. return 1;
  33. }
  34. // Description: Print out the specification, which is documentation of
  35. // the application.
  36. string toString() {
  37. // Package
  38. // Module
  39. // Item should do this
  40. // Item should do that
  41. string ret = "";
  42. foreach(pack; _packages.values.sort) {
  43. ret ~= pack.toString();
  44. }
  45. return ret;
  46. }
  47. private:
  48. PackageSpecification[string] _packages;
  49. }