51 template<
class ENUM,
class VAL,
class INFO>
56 const defn *defs = (
const defn *)vdefs;
58 for(n=1; defs[n].token != defs[0].token; n++)
61 this->ndefinitions = n;
62 this->definitions =
new defn[n];
64 this->definitions[0] = defs[0];
65 for(n=1; defs[n].token != defs[0].token; n++)
66 this->definitions[n] = defs[n];
68 this->p_unknown_enum = defs[n].
token;
69 this->p_unknown_value = defs[n].values[0];
72 template<
class ENUM,
class VAL,
class INFO>
79 const _EST_TMPNAME *defs = (
const _EST_TMPNAME *)vdefs;
83 for(n=1; strcmp(defs[n].token, defs[0].token) != 0; n++)
90 this->ndefinitions = n;
92 this->definitions =
new defn[n];
94 this->definitions[0].
token = conv(defs[0].token);
97 this->definitions[0].info = defs[0].info;
98 for(n=1; strcmp(defs[n].token, defs[0].token) != 0; n++)
100 this->definitions[n].token = conv(defs[n].token);
103 this->definitions[n].info = defs[n].info;
106 this->p_unknown_enum = conv(defs[n].token);
107 this->p_unknown_value = defs[n].values[0];
110 template<
class ENUM,
class VAL,
class INFO>
113 if (this->definitions)
114 delete[] this->definitions;
117 template<
class ENUM,
class VAL,
class INFO>
120 return this->ndefinitions;
123 template<
class ENUM,
class VAL,
class INFO>
128 for(i=0; i<this->ndefinitions; i++)
129 if (this->definitions[i].token == token)
130 return this->definitions[i].values[n];
132 return this->p_unknown_value;
135 template<
class ENUM,
class VAL,
class INFO>
140 for(i=0; i<this->ndefinitions; i++)
141 if (this->definitions[i].token == token)
142 return this->definitions[i].info;
144 std::cerr <<
"Fetching info for invalid entry" << std::endl;
151 template<
class ENUM,
class VAL,
class INFO>
154 if (n>=0 && n < this->ndefinitions)
155 return this->definitions[n].token;
157 return this->p_unknown_enum;
160 template<
class ENUM,
class VAL,
class INFO>
165 for(i=0; i<this->ndefinitions; i++)
167 if (eq_vals(this->definitions[i].
values[j], value))
168 return this->definitions[i].token;
170 return this->p_unknown_enum;
177 #define LINE_LENGTH (1024) 179 char *buffer = (
char *)line;
186 if ((file=fopen(name,
"rb"))==
NULL)
189 if (this->definitions)
190 delete[] this->definitions;
192 this->ndefinitions= -1;
193 this->definitions=
NULL;
201 std::cerr <<
"line too long .. '" << buffer <<
"'\n";
205 if (this->ndefinitions>=0 && quote !=
'\0' && buffer[0] ==
'=')
209 if ( n>= this->ndefinitions)
211 std::cerr <<
"too many definitions\n";
216 this->definitions[n].token = (ENUM)atoi(tokens[0].after(0,1));
218 for(
int i=1; i<ntokens; i++)
219 this->definitions[n].
values[i-1] =
wstrdup(tokens[i].unquote_if_needed(quote));
225 else if (have_unknown && this->ndefinitions>=0 && quote !=
'\0' && buffer[0] == quote)
230 std::cerr <<
"can't use names in this definition\n";
233 if ( n>= this->ndefinitions)
235 std::cerr <<
"too many definitions\n";
241 this->definitions[n].token = definitive->
token(tokens[0].unquote(quote));
243 for(
int i=1; i<ntokens; i++)
244 this->definitions[n].
values[i-1] =
wstrdup(tokens[i].unquote_if_needed(quote));
255 int eq = line.
search(
"=", 1, mlen);
259 std::cerr <<
"bad header line '" << line;
270 else if (key ==
"number")
272 this->ndefinitions=atoi(line.
after(eq,1));
274 this->definitions =
new Defn[this->ndefinitions];
275 for(
int i=0; i<this->ndefinitions; i++)
279 else if (key ==
"unknown")
281 this->p_unknown_enum=(ENUM)atoi(line.
after(eq,1));
287 std::cerr <<
"bad header line '" << line;
305 if ((file=fopen(name,
"wb"))==
NULL)
308 fprintf(file,
"unknown=%d\n", this->p_unknown_enum);
309 fprintf(file,
"quote=%c\n", quote);
310 fprintf(file,
"number=%d\n", this->ndefinitions);
312 for(
int i=0; i<this->ndefinitions; i++)
313 if (this->definitions[i].
values[0])
316 fprintf(file,
"%s ", (
const char *)
EST_String(definitive->
name(this->definitions[i].token)).
quote(quote));
318 fprintf(file,
"=%d ", (
int)this->definitions[i].token);
321 fprintf(file,
"%s ", (
const char *)
EST_String(this->definitions[i].values[j]).quote_if_needed(quote));
char * wstrdup(const char *s)
ENUM token(VAL value) const
#define NAMED_ENUM_MAX_SYNONYMS
size_t search(const char *s, size_t len, size_t &mlen, ssize_t pos=0) const
Find a substring.
virtual ~EST_TValuedEnumI(void)
ENUM nth_token(int n) const
const char * name(ENUM tok, int n=0) const
EST_Regex RXwhite("[ \n\t\r]+")
White space.
The file was written successfully.
The file was not written successfully.
VAL value(ENUM token, int n=0) const
INFO & info(ENUM token) const
EST_String after(int pos, int len=1) const
Part after pos+len.
EST_String before(int pos, int len=0) const
Part before position.