1 2 /* $Id: listener.hpp 605543 2020-04-13 12:14:53Z foleyjp $ 3 * =========================================================================== 4 * 5 * PUBLIC DOMAIN NOTICE 6 * National Center for Biotechnology Information 7 * 8 * This software/database is a "United States Government Work" under the 9 * terms of the United States Copyright Act. It was written as part of 10 * the author's official duties as a United States Government employee and 11 * thus cannot be copyrighted. This software/database is freely available 12 * to the public for use. The National Library of Medicine and the U.S. 13 * Government have not placed any restriction on its use or reproduction. 14 * 15 * Although all reasonable efforts have been taken to ensure the accuracy 16 * and reliability of the software and data, the NLM and the U.S. 17 * Government do not and cannot warrant the performance or results that 18 * may be obtained by using this software or data. The NLM and the U.S. 19 * Government disclaim all warranties, express or implied, including 20 * warranties of performance, merchantability or fitness for any particular 21 * purpose. 22 * 23 * Please cite the author in any work or product based on this material. 24 * 25 * =========================================================================== 26 * 27 * Author: Justin Foley 28 * 29 * File Description: 30 * Objtools message listener classes - based on ILineErrorListener 31 * 32 */ 33 34 #ifndef _OBJTOOLS_LISTENER_HPP_ 35 #define _OBJTOOLS_LISTENER_HPP_ 36 37 #include <corelib/ncbistd.hpp> 38 #include <objtools/logging/message.hpp> 39 40 BEGIN_NCBI_SCOPE 41 BEGIN_SCOPE(objects) 42 43 44 // ============================================================================ 45 class NCBI_XOBJUTIL_EXPORT IObjtoolsListener 46 // ============================================================================ 47 { 48 public: 49 virtual ~IObjtoolsListener(void) = default; 50 51 virtual bool SevEnabled(EDiagSev severity) const; 52 53 virtual bool PutMessage(const IObjtoolsMessage& message) = 0; 54 }; 55 56 57 // ============================================================================ 58 class NCBI_XOBJUTIL_EXPORT CObjtoolsListener : public IObjtoolsListener 59 // ============================================================================ 60 { 61 protected: 62 using TMessages = vector<unique_ptr<IObjtoolsMessage>>; 63 private: 64 using TBaseIterator = TMessages::const_iterator; 65 66 public: 67 CObjtoolsListener() = default; 68 69 CObjtoolsListener(const CObjtoolsListener&) = delete; 70 71 CObjtoolsListener& operator=(const CObjtoolsListener&) = delete; 72 73 virtual ~CObjtoolsListener(void); 74 75 virtual bool PutMessage(const IObjtoolsMessage& message); 76 77 virtual void PutProgress(const string& message, 78 const Uint8 iNumDone, 79 const Uint8 iNumTotal); 80 81 virtual const IObjtoolsMessage& GetMessage(size_t index) const; 82 83 virtual size_t Count(void) const; 84 85 virtual void ClearAll(void); 86 87 virtual size_t LevelCount(EDiagSev severity) const; 88 89 virtual void Dump(CNcbiOstream& ostr) const; 90 91 virtual void DumpAsXML(CNcbiOstream& ostr) const; 92 93 virtual void SetProgressOstream(CNcbiOstream* pProgressOstream); 94 95 class CConstIterator : public TBaseIterator { 96 public: 97 using value_type = TBaseIterator::value_type::element_type; 98 using pointer = value_type*; 99 using reference = value_type&; 100 CConstIterator(const TBaseIterator & base_it)101 CConstIterator(const TBaseIterator& base_it) : TBaseIterator(base_it) {} 102 operator *() const103 reference operator*() const { return *(this->TBaseIterator::operator*()); } operator ->() const104 pointer operator->() const { return this->TBaseIterator::operator*().get(); } 105 }; 106 107 using TConstIterator = CConstIterator; 108 TConstIterator begin(void) const; 109 TConstIterator end(void) const; 110 protected: 111 TMessages m_Messages; 112 CNcbiOstream* m_pProgressOstrm = nullptr; 113 }; 114 115 116 // ============================================================================ 117 class NCBI_XOBJUTIL_EXPORT CObjtoolsListenerLevel : public CObjtoolsListener 118 // ============================================================================ 119 { 120 public: 121 CObjtoolsListenerLevel(int accept_level); 122 virtual ~CObjtoolsListenerLevel(void); 123 124 bool PutMessage(const IObjtoolsMessage& message) override; 125 private: 126 int m_AcceptLevel; 127 }; 128 129 130 // ================================================================================= 131 class NCBI_XOBJUTIL_EXPORT CObjtoolsListenerLenient final : public CObjtoolsListenerLevel 132 // ================================================================================= 133 { 134 public: 135 CObjtoolsListenerLenient(void); 136 }; 137 138 139 // ================================================================================= 140 class NCBI_XOBJUTIL_EXPORT CObjtoolsListenerStrict final : public CObjtoolsListenerLevel 141 // ================================================================================= 142 { 143 public: 144 CObjtoolsListenerStrict(void); 145 }; 146 147 END_SCOPE(objects) 148 END_NCBI_SCOPE 149 150 151 #endif // _OBJTOOLS_LISTENER_HPP_ 152 153