-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoutputformat.d
More file actions
63 lines (50 loc) · 1.35 KB
/
outputformat.d
File metadata and controls
63 lines (50 loc) · 1.35 KB
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
/* Interface for output formats.
Author: Adrian Matoga
Poetic License:
This work 'as-is' we provide.
No warranty express or implied.
We've done our best,
to debug and test.
Liability for damages denied.
Permission is granted hereby,
to copy, share, and modify.
Use as is fit,
free or for profit.
These rights, on this notice, rely.
*/
module outputformat;
import std.algorithm;
import std.array;
import std.conv;
import std.exception;
import std.getopt;
interface OutputFormat
{
void parseOptions(ref string[] args);
ubyte[] convert(string filename, const(ubyte)[] caption, bool dither);
static OutputFormat create(string name)
{
auto info = _registeredFormats.get(name, FormatInfo.init);
enforce(info.name !is null, text("Unknown output format " ~ name));
return info.create();
}
static register(string name, string extension, string description, CreateFunc create)
{
enforce(name !in _registeredFormats, text(name, " already registered"));
_registeredFormats[name] = FormatInfo(name, extension, description, create);
}
static FormatInfo[] getAllFormats()
{
return _registeredFormats.values.sort!"a.name < b.name"().array();
}
alias CreateFunc = OutputFormat function();
struct FormatInfo
{
string name;
string extension;
string description;
CreateFunc create;
}
private:
static FormatInfo[string] _registeredFormats;
}