/*** null ***/
class null_cmd : public cmd_exec {
+public:
+ null_cmd(cmd *c UNUSED) { }
vector<page *> process(vector<page *> &pages) override { return pages; }
};
{ NULL, 0 }
};
-static cmd_exec *null_ctor(cmd *c UNUSED)
-{
- return new null_cmd;
-}
-
/*** Generic transformed page ***/
class xform_page : public page {
/*** move ***/
class move_cmd : public cmd_exec_simple {
-public:
double x, y;
+public:
+ move_cmd(cmd *c)
+ {
+ x = c->args.at(0)->as_double(0);
+ y = c->args.at(1)->as_double(0);
+ }
page *process_page(page *p) override
{
pdf_matrix m;
{ NULL, 0 }
};
-static cmd_exec *move_ctor(cmd *c)
-{
- move_cmd *m = new move_cmd;
- m->x = c->args.at(0)->as_double(0);
- m->y = c->args.at(1)->as_double(0);
- return m;
-}
-
/*** scale ***/
class scale_cmd : public cmd_exec_simple {
-public:
double x_factor, y_factor;
+public:
+ scale_cmd(cmd *c)
+ {
+ x_factor = c->args.at(0)->as_double(1);
+ y_factor = c->args.at(1)->as_double(x_factor);
+ }
page *process_page(page *p) override
{
pdf_matrix m;
{ NULL, 0 }
};
-static cmd_exec *scale_ctor(cmd *c)
-{
- scale_cmd *s = new scale_cmd;
- s->x_factor = c->args.at(0)->as_double(1);
- s->y_factor = c->args.at(1)->as_double(s->x_factor);
- return s;
-}
-
/*** rotate ***/
class rotate_cmd : public cmd_exec_simple {
-public:
int deg;
+public:
+ rotate_cmd(cmd *c)
+ {
+ deg = c->args.at(0)->as_int(0) % 360;
+ if (deg < 0)
+ deg += 360;
+ if (deg % 90)
+ die("Rotate requires a multiple of 90 degrees");
+ }
page *process_page(page *p) override
{
pdf_matrix m;
{ NULL, 0 }
};
-static cmd_exec *rotate_ctor(cmd *c)
-{
- rotate_cmd *r = new rotate_cmd;
- r->deg = c->args.at(0)->as_int(0) % 360;
- if (r->deg < 0)
- r->deg += 360;
- if (r->deg % 90)
- die("Rotate requires a multiple of 90 degrees");
- return r;
-}
-
/*** flip ***/
class flip_cmd : public cmd_exec_simple {
-public:
bool horizontal;
bool vertical;
+public:
+ flip_cmd(cmd *c)
+ {
+ horizontal = c->args.at(0)->as_int(0);
+ vertical = c->args.at(1)->as_int(0);
+ if (!horizontal && !vertical)
+ die("Flip has no direction specified");
+ }
page *process_page(page *p) override
{
pdf_matrix m;
{ NULL, 0 }
};
-static cmd_exec *flip_ctor(cmd *c)
-{
- flip_cmd *f = new flip_cmd;
- f->horizontal = c->args.at(0)->as_int(0);
- f->vertical = c->args.at(1)->as_int(0);
- if (!f->horizontal && !f->vertical)
- die("Flip has no direction specified");
- return f;
-}
-
/*** select ***/
class select_cmd : public cmd_exec {
-public:
pipeline *pipe;
+public:
+ select_cmd(cmd *c)
+ {
+ pipe = c->pipe;
+ }
vector<page *> process(vector<page *> &pages);
};
return out;
}
-static cmd_exec *select_ctor(cmd *c)
-{
- select_cmd *r = new select_cmd;
- r->pipe = c->pipe;
- return r;
-}
-
/*** apply ***/
class apply_cmd : public cmd_exec {
-public:
pipeline *pipe;
+public:
+ apply_cmd(cmd *c)
+ {
+ pipe = c->pipe;
+ }
vector<page *> process(vector<page *> &pages);
};
return out;
}
-static cmd_exec *apply_ctor(cmd *c)
-{
- apply_cmd *r = new apply_cmd;
- r->pipe = c->pipe;
- return r;
-}
-
/*** modulo ***/
class modulo_cmd : public cmd_exec {
-public:
pipeline *pipe;
int n;
+public:
+ modulo_cmd(cmd *c)
+ {
+ n = c->args.at(0)->as_int(0);
+ if (n <= 0)
+ die("Modulo must have n > 0");
+ pipe = c->pipe;
+ }
vector<page *> process(vector<page *> &pages);
};
{ NULL, 0 }
};
-static cmd_exec *modulo_ctor(cmd *c)
-{
- modulo_cmd *m = new modulo_cmd;
- m->n = c->args.at(0)->as_int(0);
- if (m->n <= 0)
- die("Modulo must have n > 0");
- m->pipe = c->pipe;
- return m;
-}
-
/*** draw_bbox ***/
class draw_bbox_cmd : public cmd_exec {
public:
+ draw_bbox_cmd(cmd *c UNUSED) { }
vector<page *> process(vector<page *> &pages);
};
return out;
}
-static cmd_exec *draw_bbox_ctor(cmd *c UNUSED)
-{
- draw_bbox_cmd *m = new draw_bbox_cmd;
- return m;
-}
-
/*** Command table ***/
+template<typename T> cmd_exec *ctor(cmd *c) { return new T(c); }
+
const cmd_def cmd_table[] = {
- { "null", no_args, 0, null_ctor },
- { "move", move_args, 0, move_ctor },
- { "scale", scale_args, 0, scale_ctor },
- { "rotate", rotate_args, 0, rotate_ctor },
- { "flip", flip_args, 0, flip_ctor },
- { "select", no_args, 1, select_ctor },
- { "apply", no_args, 1, apply_ctor },
- { "modulo", modulo_args, 1, modulo_ctor },
- { "draw_bbox",no_args, 0, draw_bbox_ctor },
+ { "null", no_args, 0, &ctor<null_cmd> },
+ { "move", move_args, 0, &ctor<move_cmd> },
+ { "scale", scale_args, 0, &ctor<scale_cmd> },
+ { "rotate", rotate_args, 0, &ctor<rotate_cmd> },
+ { "flip", flip_args, 0, &ctor<flip_cmd> },
+ { "select", no_args, 1, &ctor<select_cmd> },
+ { "apply", no_args, 1, &ctor<apply_cmd> },
+ { "modulo", modulo_args, 1, &ctor<modulo_cmd> },
+ { "draw_bbox",no_args, 0, &ctor<draw_bbox_cmd> },
{ NULL, NULL, 0, NULL }
};