LabeledSetFactory.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <stdio.h>
  2. #include <QDomDocument>
  3. #include <QFile>
  4. #include "LabeledSetFactory.h"
  5. namespace OBJREC
  6. {
  7. LabeledSetFactory::LabeledSetFactory()
  8. {
  9. }
  10. void LabeledSetFactory::createLabeledSetFromXml(std::string sXmlFilename,
  11. const NICE::Config &p_conf,
  12. const ClassNames &p_classnames,
  13. LabeledSet &p_LabelSet)
  14. {
  15. QDomDocument doc("dummy");
  16. QFile file(sXmlFilename.c_str());
  17. if (!file.open(QIODevice::ReadOnly)) {
  18. std::cout << "Can not open such file" << std::endl;
  19. return;
  20. }
  21. QString errMsg;
  22. if (!doc.setContent(&file, &errMsg)) {
  23. std::cout << errMsg.toStdString() << std::endl;
  24. file.close();
  25. return;
  26. }
  27. file.close();
  28. /* getting all info */
  29. QDomElement elements = doc.documentElement();
  30. QDomDocumentType type= doc.doctype();
  31. std::string sTypeName = type.name().toStdString();
  32. //choose appropriate xml-LabeledSet loader according to the documenttype, which had previously been added by ::addCreator
  33. LabeledSetCreatorInterface *pCreator = this->m_MapLSCreators[ sTypeName ];
  34. if( pCreator == NULL )
  35. {
  36. std::cout << "LabeledSetFactory::createLabeledSetFromXml No creator found for xml type " << sTypeName << std::endl;
  37. return;
  38. }
  39. //call specific loading function for the given xml file.
  40. pCreator->createLabeledSet( sXmlFilename, p_conf, p_classnames, p_LabelSet );
  41. }
  42. void LabeledSetFactory::addCreator(std::string sCreatorName, LabeledSetCreatorInterface *pCreator)
  43. {
  44. //is there already a mapper for this document type registered?
  45. if (this->m_MapLSCreators.find(sCreatorName) != this->m_MapLSCreators.end() )
  46. return; //element already exist, so don't try to overwrite it
  47. // store the mapping
  48. this->m_MapLSCreators[sCreatorName] = pCreator;
  49. }
  50. }//namespace