File: plugin-helper.hh

package info (click to toggle)
gwyddion 2.67-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 54,152 kB
  • sloc: ansic: 412,023; python: 7,885; sh: 5,492; makefile: 4,957; xml: 3,954; cpp: 2,107; pascal: 418; perl: 154; ruby: 130
file content (45 lines) | stat: -rw-r--r-- 1,420 bytes parent folder | download | duplicates (3)
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
/**
 * $Id: plugin-helper.hh 22454 2019-08-31 19:53:40Z yeti-dn $
 * Gwyddion plug-in helper.
 * Written by Yeti <yeti@gwyddion.net>.  Public domain.
 **/
#ifndef __GWYDDION_PLUGIN_HELPER_H__
#define __GWYDDION_PLUGIN_HELPER_H__

#include <string>
#include <iostream>

class PluginAction {
    public:
    std::string name;              /* action name: register, load, run, ... */
    int arg_num;                   /* number of arguments NOT including
                                      program name, nor action name */
    bool (*action)(char *args[]);  /* action itself, will get array of
                                      arg_num program argument, NOT including
                                      program name, nor action name */

    bool check(int argc, char *argv[]) { return argc == arg_num + 2
                                                && name.compare(argv[1]) == 0; }
};

/* Find action and run it */
static bool
run_action(int nactions, PluginAction *actions,
           int argc, char *argv[])
{
    int i;

    for (i = 0; i < nactions; i++) {
        if (actions[i].check(argc, argv)) {
            actions[i].action(argv + 2);
            return true;
        }
    }
    std::cerr << "Plug-in has to be called from Gwyddion plugin-proxy."
              << std::endl;
    return false;
}

#endif

/* vim: set cin et ts=4 sw=4 cino=>1s,e0,n0,f0,{0,}0,^0,\:1s,=0,g1s,h0,t0,+1s,c3,(0,u0 : */