PageRenderTime 27ms CodeModel.GetById 16ms app.highlight 8ms RepoModel.GetById 1ms 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
 11module spec.packagespecification;
 12
 13import spec.modulespecification;
 14
 15import djehuty;
 16
 17class PackageSpecification {
 18	this(string name) {
 19		_name = name.dup;
 20	}
 21
 22	string name() {
 23		return _name;
 24	}
 25
 26	void add(ModuleSpecification spec) {
 27		_modules[spec.name] = spec;
 28	}
 29
 30	void add(PackageSpecification spec) {
 31		_packages[spec.name] = spec;
 32	}
 33
 34	PackageSpecification traverse(string name) {
 35		if (!(name in _packages)) {
 36			return null;
 37		}
 38		return _packages[name];
 39	}
 40
 41	ModuleSpecification retrieve(string name) {
 42		if (!(name in _modules)) {
 43			return null;
 44		}
 45		return _modules[name];
 46	}
 47
 48	int opApply(int delegate(ref PackageSpecification) loopBody) {
 49		foreach(pack; _packages.keys.sort) {
 50			if (loopBody(_packages[pack])) {
 51				return 1;
 52			}
 53		}
 54		return 1;
 55	}
 56
 57	int opApply(int delegate(ref ModuleSpecification) loopBody) {
 58		foreach(mod; _modules.keys.sort) {
 59			if (loopBody(_modules[mod])) {
 60				return 1;
 61			}
 62		}
 63		return 1;
 64	}
 65
 66	// Description: Print out the specification of the package, which serves as
 67	//   documentation for the application.
 68	string toString() {
 69		// Package
 70		//   Module
 71		//     Item should do this
 72		//     Item should do that
 73		return _toString("");
 74	}
 75
 76private:
 77
 78	string _toString(string padding) {
 79		string ret = padding ~ _name ~ "\n";
 80
 81		foreach(pack; _packages.values.sort) {
 82			ret ~= pack._toString(padding ~ "  ");
 83		}
 84
 85		foreach(mod; _modules.values.sort) {
 86			ret ~= padding ~ "  " ~ mod.name ~ "\n";
 87			foreach(item; mod) {
 88				foreach(spec; item) {
 89					ret ~= padding ~ "    " ~ item.name ~ " " ~ spec ~ "\n";
 90				}
 91			}
 92		}
 93
 94		return ret;
 95	}
 96
 97	string _name;
 98
 99	ModuleSpecification _modules[string];
100	PackageSpecification _packages[string];
101}