~ubuntu-branches/ubuntu/hardy/avidemux/hardy

« back to all changes in this revision

Viewing changes to avidemux/gui_action.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Matvey Kozhev
  • Date: 2007-12-18 13:53:04 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071218135304-cdqec2lg2bglyz15
Tags: 1:2.4~preview3-0.0ubuntu1
* Upload to Ubuntu. (LP: #163287, LP: #126572)
* debian/changelog: re-added Ubuntu releases.
* debian/control:
  - Require debhelper >= 5.0.51 (for dh_icons) and imagemagick.
  - Build-depend on libsdl1.2-dev instead of libsdl-dev.
  - Build against newer libx264-dev. (LP: #138854)
  - Removed libamrnb-dev, not in Ubuntu yet.
* debian/rules:
  - Install all icon sizes, using convert (upstream installs none).
  - Added missing calls to dh_installmenu, dh_installman, dh_icons and
    dh_desktop.
* debian/menu, debian/avidemux-qt.menu:
  - Corrected package and executable names.
* debian/avidemux-common.install: Install icons.
* debian/avidemux.common.manpages: Install man/avidemux.1.
* debian/links, debian/avidemux-cli.links, debian/avidemux-gtk.links:
  - Link manpages to avidemux.1.gz.
* debian/install, debian/avidemux-qt.install, debian/avidemux-gtk.desktop,
  debian/avidemux-qt.desktop: Install desktop files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <vector>
 
3
using std::vector;
 
4
#include <utility>
 
5
using std::pair;
 
6
using std::make_pair;
 
7
#include <iterator>
 
8
using std::back_inserter;
 
9
#include <algorithm>
 
10
using std::transform;
 
11
using std::sort;
 
12
using std::equal_range;
 
13
 
 
14
#include "gui_action.hxx"
 
15
 
 
16
struct ActionNameNum
 
17
{
 
18
    const Action num;
 
19
    const char * const name;
 
20
};
 
21
 
 
22
// The getActionName() function assumes that the following array is sorted by
 
23
// action number, and further that it can be indexed by action number based on
 
24
// the action number of the first entry.
 
25
 
 
26
const ActionNameNum action_names [] =
 
27
{
 
28
#define ACT(_name) { ACT_ ## _name, # _name },
 
29
#include "gui_action.names"
 
30
#undef ACT
 
31
    //   { ACT_INVALID, 0 }
 
32
};
 
33
 
 
34
const int ACTION_NAME_COUNT = sizeof (action_names) / sizeof (action_names[0]);
 
35
 
 
36
// One might think to use a map here, instead of a vector (and in fact I did),
 
37
// but Scott Meyers in _Effective STL_ advises (in item 23) that it is more
 
38
// efficient to use a sorted vector when we are doing a bunch of insertions
 
39
// followed by mostly (in our case exclusively) lookups.
 
40
 
 
41
typedef pair <const char *, Action> ActionNamePair;
 
42
typedef vector <ActionNamePair> ActionNameVec;
 
43
typedef ActionNameVec::iterator ActionNameIter;
 
44
 
 
45
class ActionNameCompare
 
46
{
 
47
public:
 
48
    bool operator () (const ActionNamePair & lhs, // for sorting
 
49
                      const ActionNamePair & rhs) const
 
50
    {
 
51
        return doLess (lhs.first, rhs.first);
 
52
    }
 
53
 
 
54
    bool operator () (const ActionNamePair & lhs, // for lookups 1
 
55
                      const ActionNamePair::first_type & rhs) const
 
56
    {
 
57
        return doLess (lhs.first, rhs);
 
58
    }
 
59
 
 
60
    bool operator () (const ActionNamePair::first_type & lhs, // for lookups 2
 
61
                      const ActionNamePair & rhs) const
 
62
    {
 
63
        return doLess (lhs, rhs.first);
 
64
    }
 
65
 
 
66
private:
 
67
 
 
68
    bool doLess (const ActionNamePair::first_type & lhs,
 
69
                 const ActionNamePair::first_type & rhs) const
 
70
    {
 
71
        return (strcasecmp (lhs, rhs) < 0);
 
72
    }
 
73
};
 
74
 
 
75
class MakeActionNamePair
 
76
{
 
77
public:
 
78
    ActionNamePair operator () (const ActionNameNum & ann)
 
79
    {
 
80
        return make_pair (ann.name, ann.num);
 
81
    }
 
82
};
 
83
 
 
84
static ActionNameVec action_name_vec;
 
85
 
 
86
void initActionNameVec (void)
 
87
{
 
88
    action_name_vec.reserve (ACTION_NAME_COUNT);
 
89
    transform (action_names, action_names + ACTION_NAME_COUNT,
 
90
               back_inserter (action_name_vec), MakeActionNamePair());
 
91
    sort (action_name_vec.begin(), action_name_vec.end(),
 
92
          ActionNameCompare());
 
93
}
 
94
 
 
95
Action lookupActionByName (const char * name)
 
96
{
 
97
    if (action_name_vec.empty())
 
98
        initActionNameVec();
 
99
 
 
100
    pair <ActionNameIter, ActionNameIter> range
 
101
        = equal_range (action_name_vec.begin(),
 
102
                       action_name_vec.end(), name,
 
103
                       ActionNameCompare());
 
104
    if (range.first == range.second)
 
105
        return ACT_INVALID;
 
106
    else
 
107
        return range.first->second;
 
108
}
 
109
 
 
110
const char * getActionName (Action act)
 
111
{
 
112
    uint32_t index = act - action_names [0].num;
 
113
    return (action_names [index].name);
 
114
}
 
115
 
 
116
void dumpActionNames (const char * filename)
 
117
{
 
118
    if (action_name_vec.empty())
 
119
        initActionNameVec();
 
120
 
 
121
    printf ("# Action names (which can be used in %s, "
 
122
            "though some should not be):\n", filename);
 
123
    ActionNameIter it = action_name_vec.begin();
 
124
    while (it != action_name_vec.end())
 
125
    {
 
126
        printf ("#     %s\n", it->first);
 
127
        ++it;
 
128
    }
 
129
}