Debtags Library

Benjamin Mesing bensmail@gmx.net
Sun, 11 Jul 2004 13:10:06 +0200


Hello,

> > There is one idea which came up to me today when I read "Design
> > Patterns" (Gamma et al). Perhaps you could use the facade pattern for
> > the simplest form of using the debtags system. The facade class could
> > provide access to the vocabulary and a simple form of searching (perhaps
> > using a search pattern as expected by the ExpressionFilter).
> 
> If I understand correctly, you are talking of something similar to the
> Debtags::Packages class (Implemented in DebtagsPackages.{h,cc}).  Or you
> mean something different?
This looks pretty much like the class I was imagining. But it seems to
have some drawbacks:

>From what I've seen the error handling looks really dangerous, consider
the function:
	void Packages::loadDebtags() const throw ()
it calls Environment::get().outputPatched(itp) which has the following
signature:
        void outputPatched(TagcollConsumer<std::string, std::string>&
        cons) const throw (FileException, ParserException);
Unless you are really sure that outputPatched will not raise an
exception this is really dangerous an might raise an
unexpected_exception!
Here is another case where such a behavoir might occur

const string& Package::fulldata() throw ()
{
	if (_fulldata.empty())
	{
		printf("Reading full data for %.*s\n", PFSTR(_name));
		_fulldata = _pool._packagedb.getPackageRecord(_name);
		            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	}
	return _fulldata;
}
The underlined statement might throw an PackageDBException unless you
are really sure this won't happen this could raise unexpected_exception.

Besides the user has no option to get to know if an error occured in an
operation - which would be neccessary to give the user some feedback.
Some complexity information in the documentation would be nice (e.g. for
the find(std::string) operation which seems to have O(log(n)). In my
opinion the class does also talk to much (but this might be because its
still under development) - users of it might be suprised to get messages
like "Beginning to load debtags..." in their application.

Nevertheless after having taken a closer look to the libdebtags library,
it seems that I might forget about libapt and use this instead. It seems
that it is performent as needed by my appliction and is definetaly
easier to use.

Btw:
	if (str) delete str;
You can spare the "if (str)" here as the C++ standards assures that
"delete 0" will do no harm.

> About the search pattern, I'm a bit wary in mandating user-related
> syntaxes, as every implementing program may have his own one...
I agree with you now, I think your Filter class is easy and obvious
enough to be used by application developers (imagining that there is
also some documentation :-) 

Greetings Ben