29 #ifndef CDPL_BASE_DATAIOMANAGER_HPP
30 #define CDPL_BASE_DATAIOMANAGER_HPP
60 class FeatureContainer;
66 template <
typename T,
typename CVT>
68 template <
typename T,
typename CVT>
102 template <
typename T>
114 typedef std::vector<InputHandlerPointer> InputHandlerList;
115 typedef std::vector<OutputHandlerPointer> OutputHandlerList;
336 static DataIOManager& getInstance();
338 InputHandlerList inputHandlers;
339 OutputHandlerList outputHandlers;
345 # define _CDPL_BASE_API
347 # define _CDPL_BASE_API CDPL_BASE_API
350 extern template class _CDPL_BASE_API DataIOManager<Chem::Molecule>;
352 extern template class _CDPL_BASE_API DataIOManager<Chem::MolecularGraph>;
354 extern template class _CDPL_BASE_API DataIOManager<Chem::Reaction>;
356 extern template class _CDPL_BASE_API DataIOManager<Pharm::Pharmacophore>;
358 extern template class _CDPL_BASE_API DataIOManager<Pharm::FeatureContainer>;
360 extern template class _CDPL_BASE_API DataIOManager<Grid::RegularGrid<double, double> >;
362 extern template class _CDPL_BASE_API DataIOManager<Grid::RegularGridSet<double, double> >;
364 #undef _CDPL_BASE_API
373 template <
typename T>
376 static DataIOManager<T> instance;
381 template <
typename T>
384 getInstance().inputHandlers.push_back(handler);
387 template <
typename T>
390 getInstance().outputHandlers.push_back(handler);
393 template <
typename T>
396 InputHandlerList& handlers = getInstance().inputHandlers;
398 typename InputHandlerList::iterator it = std::find_if(handlers.begin(), handlers.end(),
399 std::bind(std::equal_to<DataFormat>(), std::ref(fmt),
401 if (it != handlers.end()) {
409 template <
typename T>
412 OutputHandlerList& handlers = getInstance().outputHandlers;
414 typename OutputHandlerList::iterator it = std::find_if(handlers.begin(), handlers.end(),
415 std::bind(std::equal_to<DataFormat>(), std::ref(fmt),
417 if (it != handlers.end()) {
425 template <
typename T>
428 InputHandlerList& handlers = getInstance().inputHandlers;
430 typename InputHandlerList::iterator it = std::find(handlers.begin(), handlers.end(), handler);
432 if (it != handlers.end()) {
440 template <
typename T>
443 OutputHandlerList& handlers = getInstance().outputHandlers;
445 typename OutputHandlerList::iterator it = std::find(handlers.begin(), handlers.end(), handler);
447 if (it != handlers.end()) {
455 template <
typename T>
458 InputHandlerList& handlers = getInstance().inputHandlers;
460 if (idx >= handlers.size())
461 throw IndexError(
"DataIOManager: handler index out of bounds");
463 handlers.erase(handlers.begin() + idx);
466 template <
typename T>
469 using namespace std::placeholders;
471 OutputHandlerList& handlers = getInstance().outputHandlers;
473 if (idx >= handlers.size())
474 throw IndexError(
"DataIOManager: handler index out of bounds");
476 handlers.erase(handlers.begin() + idx);
479 template <
typename T>
483 InputHandlerList& handlers = getInstance().inputHandlers;
485 if (it < handlers.begin() || it >= handlers.end())
486 throw RangeError(
"DataIOManager: input-handler iterator out of valid range");
488 return handlers.erase(it);
491 template <
typename T>
495 OutputHandlerList& handlers = getInstance().outputHandlers;
497 if (it < handlers.begin() || it >= handlers.end())
498 throw RangeError(
"DataIOManager: output-handler iterator out of valid range");
500 return handlers.erase(it);
503 template <
typename T>
506 return getInstance().inputHandlers.size();
509 template <
typename T>
512 return getInstance().outputHandlers.size();
515 template <
typename T>
518 const InputHandlerList& handlers = getInstance().inputHandlers;
520 if (idx >= handlers.size())
521 throw IndexError(
"DataIOManager: handler index out of bounds");
523 return handlers[idx];
526 template <
typename T>
529 const OutputHandlerList& handlers = getInstance().outputHandlers;
531 if (idx >= handlers.size())
532 throw IndexError(
"DataIOManager: handler index out of bounds");
534 return handlers[idx];
537 template <
typename T>
540 return getInstance().inputHandlers.begin();
543 template <
typename T>
546 return getInstance().inputHandlers.end();
549 template <
typename T>
552 return getInstance().outputHandlers.begin();
555 template <
typename T>
558 return getInstance().outputHandlers.end();
561 template <
typename T>
564 const InputHandlerList& handlers = getInstance().inputHandlers;
566 typename InputHandlerList::const_iterator it = std::find_if(handlers.begin(), handlers.end(),
567 std::bind(std::equal_to<DataFormat>(), std::ref(fmt),
572 template <
typename T>
575 const InputHandlerList& handlers = getInstance().inputHandlers;
577 typename InputHandlerList::const_iterator it = std::find_if(handlers.begin(), handlers.end(),
578 std::bind(&DataFormat::matchesFileExtension,
580 std::ref(file_ext)));
584 template <
typename T>
587 const InputHandlerList& handlers = getInstance().inputHandlers;
589 typename InputHandlerList::const_iterator it = std::find_if(handlers.begin(), handlers.end(),
590 std::bind(&DataFormat::matchesName,
596 template <
typename T>
599 const InputHandlerList& handlers = getInstance().inputHandlers;
601 typename InputHandlerList::const_iterator it = std::find_if(handlers.begin(), handlers.end(),
602 std::bind(&DataFormat::matchesMimeType,
604 std::ref(mime_type)));
608 template <
typename T>
611 const OutputHandlerList& handlers = getInstance().outputHandlers;
613 typename OutputHandlerList::const_iterator it = std::find_if(handlers.begin(), handlers.end(),
614 std::bind(std::equal_to<DataFormat>(), std::ref(fmt),
619 template <
typename T>
622 const OutputHandlerList& handlers = getInstance().outputHandlers;
624 typename OutputHandlerList::const_iterator it = std::find_if(handlers.begin(), handlers.end(),
625 std::bind(&DataFormat::matchesName,
631 template <
typename T>
634 const OutputHandlerList& handlers = getInstance().outputHandlers;
636 typename OutputHandlerList::const_iterator it = std::find_if(handlers.begin(), handlers.end(),
637 std::bind(&DataFormat::matchesFileExtension,
639 std::ref(file_ext)));
643 template <
typename T>
646 const OutputHandlerList& handlers = getInstance().outputHandlers;
648 typename OutputHandlerList::const_iterator it = std::find_if(handlers.begin(), handlers.end(),
649 std::bind(&DataFormat::matchesMimeType,
651 std::ref(mime_type)));
655 #endif // CDPL_BASE_DATAIOMANAGER_HPP