File: Version.h

package info (click to toggle)
storm-lang 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,004 kB
  • sloc: ansic: 261,462; cpp: 140,405; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (110 lines) | stat: -rw-r--r-- 2,649 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#pragma once
#include "Named.h"
#include "Reader.h"

namespace storm {
	STORM_PKG(core.info);

	/**
	 * Holds version information about something. Inspired by semantic versioning: http://semver.org/
	 */
	class Version : public Object {
		STORM_CLASS;
	public:
		// Create.
		STORM_CTOR Version(Nat major, Nat minor, Nat patch);

		// Copy.
		Version(const Version &o);

		// Major, minor and patch levels.
		Nat major;
		Nat minor;
		Nat patch;

		// Pre-release?
		Array<Str *> *pre;

		// Build info?
		Array<Str *> *build;

		// Compare versions.
		Bool STORM_FN operator <(const Version &o) const;
		Bool STORM_FN operator <=(const Version &o) const;
		Bool STORM_FN operator >(const Version &o) const;
		Bool STORM_FN operator >=(const Version &o) const;
		Bool STORM_FN operator ==(const Version &o) const;
		Bool STORM_FN operator !=(const Version &o) const;

		// Hash.
		virtual Nat STORM_FN hash() const;

		// Deep copy.
		virtual void STORM_FN deepCopy(CloneEnv *env);

		// Serialization.
		static SerializedType *STORM_FN serializedType(EnginePtr e);
		static Version *STORM_FN read(ObjIStream *from);
		Version(ObjIStream *from);
		void STORM_FN write(ObjOStream *to) const;

		// To string.
		virtual void STORM_FN toS(StrBuf *to) const;
	};

	// Parse a version string.
	MAYBE(Version *) STORM_FN parseVersion(Str *src);


	/**
	 * Stores a Version object in the name tree so that it can be associated with some part of the system easily.
	 */
	class VersionTag : public Named {
		STORM_CLASS;
	public:
		// Create.
		STORM_CTOR VersionTag(Str *name, Version *version, SrcPos pos);

		// The version.
		Version *version;

		// Replace.
		virtual MAYBE(Str *) STORM_FN canReplace(Named *old, ReplaceContext *ctx);

		// To string.
		virtual void STORM_FN toS(StrBuf *to) const;
	};

	// Find all currently loaded licenses in some part of the name tree.
	Array<VersionTag *> *STORM_FN versions(EnginePtr e) ON(Compiler);
	Array<VersionTag *> *STORM_FN versions(Named *root) ON(Compiler);



	STORM_PKG(lang.version);

	namespace version {
		// Reader for version annotations.
		PkgReader *STORM_FN reader(Array<Url *> *files, Package *pkg) ON(Compiler);
	}

	/**
	 * Reader for version files.
	 *
	 * We don't bother implementing individual file readers, as syntax highlighting is not very
	 * important for this file type.
	 */
	class VersionReader : public PkgReader {
		STORM_CLASS;
	public:
		// Create.
		STORM_CTOR VersionReader(Array<Url *> *files, Package *pkg);

		// We read versions as types.
		virtual void STORM_FN readTypes();

	private:
		// Load a single license.
		VersionTag *STORM_FN readVersion(Url *file);
	};
}