On Fri, 29 Jan 2010 20:25:46 Monty Taylor wrote:
> Stewart Smith wrote:
> > On Thu, Jan 28, 2010 at 10:37:32PM -0800, Monty Taylor wrote:
> >> Also - if there's a way to make it so that the client progs don't have
> >> to link that chunk of code from the server, that would be swell... but
> >> then also something I'll get over.
> >
> > obviously error info should be sep and not be too bad.
> >
> > how does gperf do it?
>
> gperf makes this:
>
> inline unsigned int
> symbol_hash::hash (register const char *str, register unsigned int len)
> {
> static const unsigned short asso_values[] =
> {
> 1522, 1522, 1522, 1522, 1522, 1522, 1522, 1522, 1522, 1522,
>
> So it's a static variable that's made in a function (classic singleton
> pattern)
Not really an easy thing to do with a mapping of uint_32 -> std::string,
when that map needs to be exposed to other methods, like the ability for other
libraries to add things to. Unless you do some weird magic like:
// Early apologies if I've misnamed anything, 3.5 years of rust.
typedef drizzle::hash_map<uint_32, std::string> ErrorMapping;
namespace {
// These two are private to the module.
ErrorMapping& init_error_map()
{
static ErrorMapping errors;
// lots of lines where errors are added.
return errors;
}
ErrorMapping& get_error_map()
{
static ErrorMapping& error_map = init_error_map();
return error_map;
}
};
// public method
void add_error(uint_32 key, std::string const& value)
{
ErrorMapping& errors = get_error_map();
errors.insert(ErrorMapping::value_type(key, value));
}
// another public method
std::string get_error_string(uint_32 key)
{
ErrorMapping const& errors = get_error_map();
ErrorMapping::const_iterator pos = errors.find(key);
if (pos == errors.end())
{
std::stringstream sout;
sout << "Unknown error: " << key;
return sout.str();
}
else {
return pos->value;
}
}
> In general, I don't think we need to get too fancy here - it's not that
> much data and it only (as stewart points out) gets processed once at
> started. Only things I care about are a) sane source code b) no valgrind
> warnings.
Is that too fancy?
Is that understandable to others? I am biased.
Tim
_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help : https://help.launchpad.net/ListHelp