-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplates.h
64 lines (49 loc) · 1.7 KB
/
templates.h
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
/* HTML template-related miscellany. */
#ifndef INCLUDED_templates_h
#define INCLUDED_templates_h
#include <string>
#include <stdio.h>
using namespace std;
typedef enum { ARTIST, TITLE, COUNT, DIRECTORY, DATE, NUMBER, ARTIST_TITLE } replace_types;
class key
{
public:
key () : isSet(false), isDefault(false) {};
key (char* init) : isSet(true), isDefault(true), keyVal(init) {};
inline bool is_set (void) const { return isSet; };
inline bool is_default (void) const { return isDefault; };
inline void set (const string & in) { keyVal = in; isSet = true; isDefault = false; };
inline string get (void) const { return keyVal; };
private:
bool isSet, isDefault;
string keyVal;
};
struct replace_map
{
char* term;
replace_types i;
int term_length;
};
extern const struct replace_map header_map[];
extern const struct replace_map body_map[];
extern key template_title;
extern key template_header;
extern key template_head_body;
extern key template_prebody;
extern key template_stats;
extern key template_body;
extern key template_body_tag;
extern key template_footer;
string replace_header (const string & in, int count, const string & directory);
string replace_body (const string & artist, const string & title, unsigned int n);
void read_template_file (char * template_fn);
/* Some very useful macros. */
#define OUTPUT_HEADER_IF_SET(stream, vec, dir, tmpl) \
if ((tmpl).is_set()) \
OUTPUT_HEADER(stream,vec,dir,tmpl)
#define OUTPUT_HEADER(stream, vec, dir, tmpl) \
assert (tmpl.is_set()); \
(stream) << replace_header((tmpl).get(), (vec)->size(), dir) << endl;
#define OUTPUT_BODY(stream, item, num) \
(stream) << replace_body((item)->artist, (item)->title, num) << endl;
#endif