Code

Filter effects dialog:
[inkscape.git] / src / util / enums.h
1 /**
2  * \brief Simplified management of enumerations of svg items with UI labels
3  *
4  * Authors:
5  *   Nicholas Bishop <nicholasbishop@gmail.com>
6  *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
7  *
8  * Copyright (C) 2007 Authors
9  *
10  * Released under GNU GPL.  Read the file 'COPYING' for more information.
11  */
13 #ifndef INKSCAPE_UTIL_ENUMS_H
14 #define INKSCAPE_UTIL_ENUMS_H
16 #include <glibmm/ustring.h>
18 namespace Inkscape {
19 namespace Util {
21 template<typename E> class EnumData
22 {
23 public:
24     E id;
25     const Glib::ustring label;
26     const Glib::ustring key;
27 };
29 template<typename E> class EnumDataConverter
30 {
31 public:
32     typedef EnumData<E> Data;
34     EnumDataConverter(const EnumData<E>* cd, const int endval)
35         : end(endval), _data(cd)
36     {}
38     E get_id_from_label(const Glib::ustring& label) const
39     {
40         for(int i = 0; i < end; ++i) {
41             if(_data[i].label == label)
42                 return (E)i;
43         }
45         return (E)0;
46     }
48     E get_id_from_key(const Glib::ustring& key) const
49     {
50         for(int i = 0; i < end; ++i) {
51             if(_data[i].key == key)
52                 return (E)i;
53         }
55         return (E)0;
56     }
58     bool is_valid_key(const Glib::ustring& key) const
59     {
60         for(int i = 0; i < end; ++i) {
61             if(_data[i].key == key)
62                 return true;
63         }
65         return false;
66     }
68     const Glib::ustring& get_label(const E e) const
69     {
70         return _data[e].label;
71     }
73     const Glib::ustring& get_key(const E e) const
74     {
75         return _data[e].key;
76     }
78     const EnumData<E>& data(const int i) const
79     {
80         return _data[i];
81     }
83     const int end;
84 private:
85     const EnumData<E>* _data;
86 };
89 }
90 }
92 #endif
94 /*
95   Local Variables:
96   mode:c++
97   c-file-style:"stroustrup"
98   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
99   indent-tabs-mode:nil
100   fill-column:99
101   End:
102 */
103 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :