[Clam-devel] [PATCH] (work-in-progress) ProcessingFactory managing Metadata
Pau Arumi
parumi at iua.upf.edu
Mon Jul 9 04:34:20 PDT 2007
En/na Andreas Calvo ha escrit:
> This patch (against 10363) adds support for checking if the key exists
> in the factory.
> changelog:
> * added ExistsKey in the registry and factory
> * added warning in the AddAttribute method
> * update tests to be green
Commited on revision 10364
I think KeyExists sounds better. Rename if you agree.
On the other hand, the way to handle unexisting keys when adding
metadata should be an assert. I even wrote the tests for that but
where missed in the last big patch. Let's talk about it by irc this
afternoon.
pau
>
> On 7/7/07, *Andreas Calvo* <flipy.bcn at gmail.com
> <mailto:flipy.bcn at gmail.com>> wrote:
>
> Fixed against rev 10362
>
>
> On 7/6/07, * parumi at iua.upf.edu <mailto:parumi at iua.upf.edu>*
> <parumi at iua.upf.edu <mailto:parumi at iua.upf.edu>> wrote:
>
>
>
> Andreas,
> seems that my last commit messed up svn and I can't fix it now.
> Can you
> prepare a patch to fix it?
>
> Next time prepare patches against updated revision.
> Thanks!
>
> pau
>
> _______________________________________________
> Clam-devel mailing list
> Clam-devel at llistes.projectes.lafarga.org
> <mailto:Clam-devel at llistes.projectes.lafarga.org>
> https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel
> <https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel>
>
>
>
>
>
> ------------------------------------------------------------------------
>
> Index: CLAM/test/UnitTests/FactoryTest/ProcessingFactoryTest.cxx
> ===================================================================
> --- CLAM/test/UnitTests/FactoryTest/ProcessingFactoryTest.cxx (revision 10363)
> +++ CLAM/test/UnitTests/FactoryTest/ProcessingFactoryTest.cxx (working copy)
> @@ -53,7 +53,8 @@
>
> void testGetListOfKeys_twoElements()
> {
> - //factory.AddCreator("the key", new DummyCreator());
> + factory.AddCreator("first", new DummyCreator());
> + factory.AddCreator("second", new DummyCreator());
> factory.AddAttribute("first", "category", "spectral");
> factory.AddAttribute("second", "category", "time-domain");
> CLAM::ProcessingFactory::Keys result = factory.GetListOfKeys("category", "spectral");
> @@ -62,11 +63,14 @@
> }
> void testGetValuesFor_empty()
> {
> + factory.AddCreator("non-existing", new DummyCreator());
> CLAM::ProcessingFactory::Values result = factory.GetValuesFor("non-existing");
> CPPUNIT_ASSERT_EQUAL(size_t(0), result.size());
> }
> void testGetValuesFor_twoElements()
> {
> + factory.AddCreator("first", new DummyCreator());
> + factory.AddCreator("second", new DummyCreator());
> factory.AddAttribute("first", "category", "spectral");
> factory.AddAttribute("second", "category", "time-domain");
> CLAM::ProcessingFactory::Values result = factory.GetValuesFor("category");
> @@ -76,11 +80,13 @@
> }
> void testGetValuesFrom_empty()
> {
> + factory.AddCreator("key", new DummyCreator());
> CLAM::ProcessingFactory::Values result = factory.GetValuesFrom("key","category");
> CPPUNIT_ASSERT_EQUAL(size_t(0), result.size());
> }
> void testGetValuesFrom_twoElements()
> {
> + factory.AddCreator("first", new DummyCreator());
> factory.AddAttribute("first", "category", "spectral");
> factory.AddAttribute("first", "category", "time-domain");
> factory.AddAttribute("first", "description", "short description");
> @@ -91,11 +97,13 @@
> }
> void testGetValuesOf_empty()
> {
> + factory.AddCreator("key", new DummyCreator());
> CLAM::ProcessingFactory::Attributes result = factory.GetValuesOf("key");
> CPPUNIT_ASSERT_EQUAL(size_t(0), result.size());
> }
> void testGetValuesOf_twoElements()
> {
> + factory.AddCreator("first", new DummyCreator());
> factory.AddAttribute("first", "category", "spectral");
> factory.AddAttribute("first", "category", "time-domain");
> CLAM::ProcessingFactory::Attributes result = factory.GetValuesOf("first");
> Index: CLAM/src/Base/ProcessingFactory.cxx
> ===================================================================
> --- CLAM/src/Base/ProcessingFactory.cxx (revision 10363)
> +++ CLAM/src/Base/ProcessingFactory.cxx (working copy)
> @@ -97,6 +97,11 @@
> att.name = attribute;
> att.value = value;
> // TODO check if the factory has the key
> + if(!ExistsKey(key))
> + {
> + std::cout << "[ProcessingFactory] tryind to add metadata to a non-existing key \"" << key << "\"" << std::endl;
> + return;
> + }
> if(it == mProcessingAttributes.end()) // first check if it does not exist
> {
> mValue.push_back(att);
> Index: CLAM/src/Base/Factory.hxx
> ===================================================================
> --- CLAM/src/Base/Factory.hxx (revision 10363)
> +++ CLAM/src/Base/Factory.hxx (working copy)
> @@ -138,6 +138,11 @@
> _registry.GetRegisteredNames( namesList );
> }
>
> + bool ExistsKey( const RegistryKey& key)
> + {
> + return _registry.ExistsKey(key);
> + }
> +
> public: // Inner classes. Public for better testing
> /**
> * This class is an implementation class of the Factory. It is basically
> @@ -243,6 +248,16 @@
>
> }
>
> + bool ExistsKey(const RegistryKey& key)
> + {
> + typename CreatorMap::const_iterator it = _creators.find(key);
> + if(it == _creators.end())
> + {
> + return false;
> + }
> + return true;
> + }
> +
> private: // data
> CreatorMap _creators;
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Clam-devel mailing list
> Clam-devel at llistes.projectes.lafarga.org
> https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel
More information about the clam-devel
mailing list