NCBI C++ ToolKit
gb_release_file.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef UTILS___GB_RELEASE_FILE__HPP
2 #define UTILS___GB_RELEASE_FILE__HPP
3 
4 /* $Id: gb_release_file.hpp 97745 2022-08-22 15:10:59Z gotvyans $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Author: Mati Shomrat
30  * File Description:
31  * Utility class for processing Genbank release files.
32  */
33 
34 #include <corelib/ncbistd.hpp>
36 
37 
40 
41 /// forward decleration
42 class CGBReleaseFileImpl;
43 
44 
45 /// CGBReleaseFile is a utility class to ease the processing of Genbank
46 /// release files one Seq-entry at a time.
47 /// It shields the user from the underlying I/O hook mechanism.
48 ///
49 /// Usage:
50 /// 1. Implement ISeqEntryHandler interface
51 /// 2. Create a CGBReleaseFile with the release file's name
52 /// 3. Register the handler object.
53 /// 4. Call Read(..), the handling method will be called for each Seq-entry.
54 
55 /* Another way of using CGBReleaseFile is to use lamba function
56 The example should look like:
57  CGBReleaseFile gbfile(filename);
58  gbfile.RegisterHandler([&your_captcha](CRef<CSeq_entry>& entry) -> bool)
59  {
60  bool success = your_captcha.ProcessEntry(entry);
61  return success;
62  });
63 */
64 
66 {
67 public:
68 
69  /// Interface for handling Seq-entry objects
71  {
72  public:
73  /// user code for handling a Seq-entry goes here.
74  /// The return value indicates whethear to continue (true),
75  /// or abort (false) the read.
76  virtual bool HandleSeqEntry(CRef<CSeq_entry>& entry) = 0;
77  virtual ~ISeqEntryHandler(void) {};
78  };
79  // alternate approach via lambda or unnamed functions
80  using TSeqEntryHandler=std::function<bool(CRef<CSeq_entry>&)>;
81 
82  /// constructors
83  CGBReleaseFile(const string& file_name, bool propagate=false);
84 
85  /// Build a release file on a pre-established object stream
86  /// NOTE: this constructor will take ownership of the object, and it will
87  /// be deleted with this class.
88  CGBReleaseFile(CObjectIStream& in, bool propagate=false);
89 
90  /// destructor
91  virtual ~CGBReleaseFile(void);
92 
93  /// Register handler
94  void RegisterHandler(ISeqEntryHandler* handler);
95  void RegisterHandler(TSeqEntryHandler handler);
96 
97  /// Read the release file
98  void Read(void);
99 
100 private:
101 
102  CGBReleaseFileImpl& x_GetImpl(void);
104 };
105 
106 
108 
109 #endif /// UTILS___GB_RELEASE_FILE__HPP
#define bool
Definition: bool.h:34
Interface for handling Seq-entry objects.
virtual bool HandleSeqEntry(CRef< CSeq_entry > &entry)=0
user code for handling a Seq-entry goes here.
CGBReleaseFile is a utility class to ease the processing of Genbank release files one Seq-entry at a ...
CRef< CObject > m_Impl
std::function< bool(CRef< CSeq_entry > &)> TSeqEntryHandler
CObjectIStream –.
Definition: objistr.hpp:93
void(*)(CSeq_entry_Handle seh, IWorkbench *wb, const CSerialObject &obj) handler
Include a standard set of the NCBI C++ Toolkit most basic headers.
const char * file_name[]
USING_SCOPE(objects)
void Read(CObjectIStream &in, TObjectPtr object, const CTypeRef &type)
Definition: serial.cpp:60
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_SEQSET_EXPORT
Definition: ncbi_export.h:793
std::istream & in(std::istream &in_, double &x_)
Modified on Tue Feb 27 05:51:41 2024 by modify_doxy.py rev. 669887