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;
354 static DataIOManager& getInstance();
356 InputHandlerList inputHandlers;
357 OutputHandlerList outputHandlers;
363 # define _CDPL_BASE_API
365 # define _CDPL_BASE_API CDPL_BASE_API
368 extern template class _CDPL_BASE_API DataIOManager<Chem::Molecule>;
370 extern template class _CDPL_BASE_API DataIOManager<Chem::MolecularGraph>;
372 extern template class _CDPL_BASE_API DataIOManager<Chem::Reaction>;
374 extern template class _CDPL_BASE_API DataIOManager<Pharm::Pharmacophore>;
376 extern template class _CDPL_BASE_API DataIOManager<Pharm::FeatureContainer>;
378 extern template class _CDPL_BASE_API DataIOManager<Grid::RegularGrid<double, double> >;
380 extern template class _CDPL_BASE_API DataIOManager<Grid::RegularGridSet<double, double> >;
382 #undef _CDPL_BASE_API
391 template <
typename T>
394 static DataIOManager<T> instance;
399 template <
typename T>
402 getInstance().inputHandlers.push_back(handler);
405 template <
typename T>
408 getInstance().outputHandlers.push_back(handler);
411 template <
typename T>
414 InputHandlerList& handlers = getInstance().inputHandlers;
416 typename InputHandlerList::iterator it = std::find_if(handlers.begin(), handlers.end(),
417 std::bind(std::equal_to<DataFormat>(), std::ref(fmt),
419 if (it != handlers.end()) {
427 template <
typename T>
430 OutputHandlerList& handlers = getInstance().outputHandlers;
432 typename OutputHandlerList::iterator it = std::find_if(handlers.begin(), handlers.end(),
433 std::bind(std::equal_to<DataFormat>(), std::ref(fmt),
435 if (it != handlers.end()) {
443 template <
typename T>
446 InputHandlerList& handlers = getInstance().inputHandlers;
448 typename InputHandlerList::iterator it = std::find(handlers.begin(), handlers.end(), handler);
450 if (it != handlers.end()) {
458 template <
typename T>
461 OutputHandlerList& handlers = getInstance().outputHandlers;
463 typename OutputHandlerList::iterator it = std::find(handlers.begin(), handlers.end(), handler);
465 if (it != handlers.end()) {
473 template <
typename T>
476 InputHandlerList& handlers = getInstance().inputHandlers;
478 if (idx >= handlers.size())
479 throw IndexError(
"DataIOManager: handler index out of bounds");
481 handlers.erase(handlers.begin() + idx);
484 template <
typename T>
487 using namespace std::placeholders;
489 OutputHandlerList& handlers = getInstance().outputHandlers;
491 if (idx >= handlers.size())
492 throw IndexError(
"DataIOManager: handler index out of bounds");
494 handlers.erase(handlers.begin() + idx);
497 template <
typename T>
501 InputHandlerList& handlers = getInstance().inputHandlers;
503 if (it < handlers.begin() || it >= handlers.end())
504 throw RangeError(
"DataIOManager: input-handler iterator out of valid range");
506 return handlers.erase(it);
509 template <
typename T>
513 OutputHandlerList& handlers = getInstance().outputHandlers;
515 if (it < handlers.begin() || it >= handlers.end())
516 throw RangeError(
"DataIOManager: output-handler iterator out of valid range");
518 return handlers.erase(it);
521 template <
typename T>
524 return getInstance().inputHandlers.size();
527 template <
typename T>
530 return getInstance().outputHandlers.size();
533 template <
typename T>
536 const InputHandlerList& handlers = getInstance().inputHandlers;
538 if (idx >= handlers.size())
539 throw IndexError(
"DataIOManager: handler index out of bounds");
541 return handlers[idx];
544 template <
typename T>
547 const OutputHandlerList& handlers = getInstance().outputHandlers;
549 if (idx >= handlers.size())
550 throw IndexError(
"DataIOManager: handler index out of bounds");
552 return handlers[idx];
555 template <
typename T>
558 return getInstance().inputHandlers.begin();
561 template <
typename T>
564 return getInstance().inputHandlers.end();
567 template <
typename T>
570 return getInstance().outputHandlers.begin();
573 template <
typename T>
576 return getInstance().outputHandlers.end();
579 template <
typename T>
582 const InputHandlerList& handlers = getInstance().inputHandlers;
584 typename InputHandlerList::const_iterator it = std::find_if(handlers.begin(), handlers.end(),
585 std::bind(std::equal_to<DataFormat>(), std::ref(fmt),
590 template <
typename T>
593 const InputHandlerList& handlers = getInstance().inputHandlers;
595 typename InputHandlerList::const_iterator it = std::find_if(handlers.begin(), handlers.end(),
596 std::bind(&DataFormat::matchesFileExtension,
598 std::ref(file_ext)));
602 template <
typename T>
605 auto& handlers = getInstance().inputHandlers;
606 std::string file_ext;
608 for (std::string::size_type i = file_name.find_first_of(
'.', 0); i != std::string::npos; i = file_name.find_first_of(
'.', i)) {
609 file_ext = file_name.substr(++i);
611 auto it = std::find_if(handlers.begin(), handlers.end(), [&](
const InputHandlerPointer& handler) {
612 return handler->getDataFormat().matchesFileExtension(file_ext);
615 if (it != handlers.end())
622 template <
typename T>
625 const InputHandlerList& handlers = getInstance().inputHandlers;
627 typename InputHandlerList::const_iterator it = std::find_if(handlers.begin(), handlers.end(),
628 std::bind(&DataFormat::matchesName,
634 template <
typename T>
637 const InputHandlerList& handlers = getInstance().inputHandlers;
639 typename InputHandlerList::const_iterator it = std::find_if(handlers.begin(), handlers.end(),
640 std::bind(&DataFormat::matchesMimeType,
642 std::ref(mime_type)));
646 template <
typename T>
649 const OutputHandlerList& handlers = getInstance().outputHandlers;
651 typename OutputHandlerList::const_iterator it = std::find_if(handlers.begin(), handlers.end(),
652 std::bind(std::equal_to<DataFormat>(), std::ref(fmt),
657 template <
typename T>
660 const OutputHandlerList& handlers = getInstance().outputHandlers;
662 typename OutputHandlerList::const_iterator it = std::find_if(handlers.begin(), handlers.end(),
663 std::bind(&DataFormat::matchesName,
669 template <
typename T>
672 const OutputHandlerList& handlers = getInstance().outputHandlers;
674 typename OutputHandlerList::const_iterator it = std::find_if(handlers.begin(), handlers.end(),
675 std::bind(&DataFormat::matchesFileExtension,
677 std::ref(file_ext)));
681 template <
typename T>
684 auto& handlers = getInstance().outputHandlers;
685 std::string file_ext;
687 for (std::string::size_type i = file_name.find_first_of(
'.', 0); i != std::string::npos; i = file_name.find_first_of(
'.', i)) {
688 file_ext = file_name.substr(++i);
690 auto it = std::find_if(handlers.begin(), handlers.end(), [&](
const OutputHandlerPointer& handler) {
691 return handler->getDataFormat().matchesFileExtension(file_ext);
694 if (it != handlers.end())
701 template <
typename T>
704 const OutputHandlerList& handlers = getInstance().outputHandlers;
706 typename OutputHandlerList::const_iterator it = std::find_if(handlers.begin(), handlers.end(),
707 std::bind(&DataFormat::matchesMimeType,
709 std::ref(mime_type)));
Definition of the preprocessor macro CDPL_BASE_API.
Definition of exception classes.
Definition of the class CDPL::Base::DataOutputHandler.
A singleton class that serves as a global registry for Base::DataInputHandler and Base::DataOutputHan...
Definition: DataIOManager.hpp:104
static OutputHandlerPointer getOutputHandlerByMimeType(const std::string &mime_type)
Returns a pointer to a Base::DataOutputHandler implementation instance registered for the data format...
Definition: DataIOManager.hpp:702
static InputHandlerPointer getInputHandlerByName(const std::string &name)
Returns a pointer to a Base::DataInputHandler implementation instance registered for the data format ...
Definition: DataIOManager.hpp:623
static void registerInputHandler(const InputHandlerPointer &handler)
Registers the specified Base::DataInputHandler implementation instance.
Definition: DataIOManager.hpp:400
OutputHandlerList::iterator OutputHandlerIterator
An iterator used to iterate over the list of registered output handlers.
Definition: DataIOManager.hpp:126
static std::size_t getNumOutputHandlers()
Returns the number of registered Base::DataOutputHandler implementation instances.
Definition: DataIOManager.hpp:528
DataInputHandler< T > InputHandlerType
Definition: DataIOManager.hpp:107
static InputHandlerPointer getInputHandlerByFormat(const DataFormat &fmt)
Returns a pointer to a Base::DataInputHandler implementation instance registered for the specified da...
Definition: DataIOManager.hpp:580
static OutputHandlerIterator getOutputHandlersEnd()
Returns an iterator pointing to the end of the list of registered Base::DataOutputHandler implementat...
Definition: DataIOManager.hpp:574
static OutputHandlerIterator getOutputHandlersBegin()
Returns an iterator pointing to the beginning of the list of registered Base::DataOutputHandler imple...
Definition: DataIOManager.hpp:568
static bool unregisterInputHandler(const DataFormat &fmt)
Unregisters the Base::DataInputHandler implementation instance for the specified data format.
Definition: DataIOManager.hpp:412
static void registerOutputHandler(const OutputHandlerPointer &handler)
Registers the specified Base::DataOutputHandler implementation instance.
Definition: DataIOManager.hpp:406
static const InputHandlerPointer & getInputHandler(std::size_t idx)
Returns a reference to the registered Base::DataInputHandler implementation instance with the specifi...
Definition: DataIOManager.hpp:534
static OutputHandlerPointer getOutputHandlerByFileName(const std::string &file_name)
Returns a pointer to a Base::DataOutputHandler implementation instance registered for the data format...
Definition: DataIOManager.hpp:682
OutputHandlerType::SharedPointer OutputHandlerPointer
Definition: DataIOManager.hpp:111
InputHandlerList::iterator InputHandlerIterator
An iterator used to iterate over the list of registered input handlers.
Definition: DataIOManager.hpp:121
static std::size_t getNumInputHandlers()
Returns the number of registered Base::DataInputHandler implementation instances.
Definition: DataIOManager.hpp:522
static OutputHandlerPointer getOutputHandlerByFileExtension(const std::string &file_ext)
Returns a pointer to a Base::DataOutputHandler implementation instance registered for the data format...
Definition: DataIOManager.hpp:670
static InputHandlerPointer getInputHandlerByMimeType(const std::string &mime_type)
Returns a pointer to a Base::DataInputHandler implementation instance registered for the data format ...
Definition: DataIOManager.hpp:635
DataOutputHandler< T > OutputHandlerType
Definition: DataIOManager.hpp:108
static bool unregisterOutputHandler(const DataFormat &fmt)
Unregisters the Base::DataOutputHandler implementation instance for the specified data format.
Definition: DataIOManager.hpp:428
static InputHandlerPointer getInputHandlerByFileExtension(const std::string &file_ext)
Returns a pointer to a Base::DataInputHandler implementation instance registered for the data format ...
Definition: DataIOManager.hpp:591
static const OutputHandlerPointer & getOutputHandler(std::size_t idx)
Returns a reference to the registered Base::DataOutputHandler implementation instance with the specif...
Definition: DataIOManager.hpp:545
static OutputHandlerPointer getOutputHandlerByName(const std::string &name)
Returns a pointer to a Base::DataOutputHandler implementation instance registered for the data format...
Definition: DataIOManager.hpp:658
static InputHandlerIterator getInputHandlersBegin()
Returns an iterator pointing to the beginning of the list of registered Base::DataInputHandler implem...
Definition: DataIOManager.hpp:556
static OutputHandlerPointer getOutputHandlerByFormat(const DataFormat &fmt)
Returns a pointer to a Base::DataOutputHandler implementation instance registered for the specified d...
Definition: DataIOManager.hpp:647
InputHandlerType::SharedPointer InputHandlerPointer
Definition: DataIOManager.hpp:110
static InputHandlerPointer getInputHandlerByFileName(const std::string &file_name)
Returns a pointer to a Base::DataInputHandler implementation instance registered for the data format ...
Definition: DataIOManager.hpp:603
static InputHandlerIterator getInputHandlersEnd()
Returns an iterator pointing to the end of the list of registered Base::DataInputHandler implementati...
Definition: DataIOManager.hpp:562
A factory interface providing methods for the creation of Base::DataWriter instances handling a parti...
Definition: DataOutputHandler.hpp:53
std::shared_ptr< DataOutputHandler > SharedPointer
Definition: DataOutputHandler.hpp:58
Thrown to indicate that an index is out of range.
Definition: Base/Exceptions.hpp:152
Thrown to indicate that a value is out of range.
Definition: Base/Exceptions.hpp:114
The namespace of the Chemical Data Processing Library.