36 map<string,string> EnumWriter::hack_table;
41 string::const_iterator it1 = s1.begin();
42 string::const_iterator it2 = s2.begin();
44 while ((it1 != s1.end()) && (it2 != s2.end())) {
45 if(::toupper(*it1) != ::toupper(*it2)) {
47 return (::toupper(*it1) < ::toupper(*it2)) ? -1 : 1;
54 string::size_type size1 = s1.size();
55 string::size_type size2 = s2.size();
63 return (size1 < size2) ? -1 : 1;
67 EnumWriter::instance()
77 EnumWriter::destroy ()
83 EnumWriter::EnumWriter ()
87 EnumWriter::~EnumWriter ()
92 EnumWriter::register_distinct (
string type, vector<int> v, vector<string> s)
94 pair<string,EnumRegistration> newpair;
95 pair<Registry::iterator,bool> result;
100 result = registry.insert (newpair);
102 if (!result.second) {
108 EnumWriter::register_bits (
string type, vector<int> v, vector<string> s)
110 pair<string,EnumRegistration> newpair;
111 pair<Registry::iterator,bool> result;
113 newpair.first = type;
116 result = registry.insert (newpair);
118 if (!result.second) {
119 warning <<
_(
"enum type \"%1\" already registered with the enum writer") <<
endmsg;
124 EnumWriter::write (
string type,
int value)
126 Registry::iterator x = registry.find (type);
128 if (x == registry.end()) {
133 if (x->second.bitwise) {
134 return write_bits (x->second, value);
136 return write_distinct (x->second, value);
141 EnumWriter::read (
string type,
string value)
143 Registry::iterator x = registry.find (type);
145 if (x == registry.end()) {
150 if (x->second.bitwise) {
151 return read_bits (x->second, value);
153 return read_distinct (x->second, value);
160 vector<int>::iterator i;
161 vector<string>::iterator s;
164 for (i = er.
values.begin(), s = er.
names.begin(); i != er.
values.end(); ++i, ++s) {
166 if (!result.empty()) {
179 vector<int>::iterator i;
180 vector<string>::iterator s;
182 for (i = er.
values.begin(), s = er.
names.begin(); i != er.
values.end(); ++i, ++s) {
204 vector<int>::iterator i;
205 string enum_name =
_(
"unknown enumeration");
207 for (Registry::iterator x = registry.begin(); x != registry.end(); ++x) {
208 if (&er == &(*x).second) {
209 enum_name = (*x).first;
214 for (i = er.
values.begin(); i != er.
values.end(); ++i) {
221 enum_name, val, er.
names.front())
229 vector<int>::iterator i;
230 vector<string>::iterator s;
233 string::size_type comma;
237 if (str.length() > 2 && str[0] ==
'0' && str[1] ==
'x') {
238 int val = strtol (str.c_str(), (
char **) 0, 16);
239 return validate (er, val);
244 if (strspn (str.c_str(),
"0123456789") == str.length()) {
245 int val = strtol (str.c_str(), (
char **) 0, 10);
246 return validate (er, val);
251 comma = str.find_first_of (
',');
252 string segment = str.substr (0, comma);
254 for (i = er.
values.begin(), s = er.
names.begin(); i != er.
values.end(); ++i, ++s) {
255 if (segment == *s ||
nocase_cmp (segment, *s) == 0) {
261 if (comma == string::npos) {
265 str = str.substr (comma+1);
279 vector<int>::iterator i;
280 vector<string>::iterator s;
284 map<string,string>::iterator x;
286 if ((x = hack_table.find (str)) != hack_table.end()) {
288 cerr <<
"found hack for " << str <<
" = " << x->second << endl;
292 for (i = er.
values.begin(), s = er.
names.begin(); i != er.
values.end(); ++i, ++s) {
293 if (str == (*s) ||
nocase_cmp (str, *s) == 0) {
301 if (str.length() > 2 && str[0] ==
'0' && str[1] ==
'x') {
302 int val = strtol (str.c_str(), (
char **) 0, 16);
303 return validate (er, val);
308 if (strspn (str.c_str(),
"0123456789") == str.length()) {
309 int val = strtol (str.c_str(), (
char **) 0, 10);
310 return validate (er, val);
313 for (i = er.
values.begin(), s = er.
names.begin(); i != er.
values.end(); ++i, ++s) {
314 if (str == (*s) ||
nocase_cmp (str, *s) == 0) {
323 EnumWriter::add_to_hack_table (
string str,
string hacked)
325 hack_table[str] = hacked;
std::vector< std::string > names
LIBPBD_API Transmitter error
LIBPBD_API Transmitter warning
std::ostream & endmsg(std::ostream &ostr)
std::vector< int > values
static int nocase_cmp(const string &s1, const string &s2)
std::string string_compose(const std::string &fmt, const T1 &o1)