1 #ifndef WRITER__HPP_INCLUDED
2 #define WRITER__HPP_INCLUDED
3 /* */
4 
5 /*  $Id: writer.hpp 493171 2016-02-24 19:31:13Z vasilche $
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 *  Author:  Anton Butanaev, Eugene Vasilchenko
29 *
30 *  File Description: Base data reader interface
31 *
32 */
33 
34 #include <corelib/ncbiobj.hpp>
35 #include <corelib/plugin_manager.hpp>
36 #include <objtools/data_loaders/genbank/impl/request_result.hpp>
37 #include <util/cache/icache.hpp>
38 #include <vector>
39 #include <list>
40 
41 BEGIN_NCBI_SCOPE
42 
43 class CByteSource;
44 class CByteSourceReader;
45 
46 BEGIN_SCOPE(objects)
47 
48 class CBlob_id;
49 class CSeq_id_Handle;
50 class CReaderRequestResult;
51 class CProcessor;
52 class CReadDispatcher;
53 class CReaderCacheManager;
54 
55 class NCBI_XREADER_EXPORT CWriter : public CObject
56 {
57 public:
58     typedef CBlob_id                                    TBlobId;
59     typedef int                                         TChunkId;
60     typedef int                                         TBlobState;
61     typedef int                                         TBlobVersion;
62     typedef int                                         TProcessorTag;
63 
64     enum EType {
65         eBlobWriter,
66         eIdWriter
67     };
68 
69     virtual ~CWriter(void);
70 
71     virtual void SaveSeq_idSeq_ids(CReaderRequestResult& result,
72                                    const CSeq_id_Handle& seq_id) = 0;
73     virtual void SaveSeq_idGi(CReaderRequestResult& result,
74                               const CSeq_id_Handle& seq_id) = 0;
75     virtual void SaveSeq_idAccVer(CReaderRequestResult& result,
76                                   const CSeq_id_Handle& seq_id) = 0;
77     virtual void SaveSeq_idLabel(CReaderRequestResult& result,
78                                  const CSeq_id_Handle& seq_id) = 0;
79     virtual void SaveSeq_idTaxId(CReaderRequestResult& result,
80                                  const CSeq_id_Handle& seq_id) = 0;
81     virtual void SaveSequenceHash(CReaderRequestResult& result,
82                                   const CSeq_id_Handle& seq_id) = 0;
83     virtual void SaveSequenceLength(CReaderRequestResult& result,
84                                     const CSeq_id_Handle& seq_id) = 0;
85     virtual void SaveSequenceType(CReaderRequestResult& result,
86                                   const CSeq_id_Handle& seq_id) = 0;
87     virtual void SaveSeq_idBlob_ids(CReaderRequestResult& result,
88                                     const CSeq_id_Handle& seq_id,
89                                     const SAnnotSelector* sel) = 0;
90     virtual void SaveBlobState(CReaderRequestResult& result,
91                                const TBlobId& blob_id,
92                                TBlobState blob_state) = 0;
93     virtual void SaveBlobVersion(CReaderRequestResult& result,
94                                  const TBlobId& blob_id,
95                                  TBlobVersion version) = 0;
96 
97     class NCBI_XREADER_EXPORT CBlobStream : public CObject {
98     public:
99         virtual ~CBlobStream(void);
100         virtual bool CanWrite(void) const = 0;
101         virtual CNcbiOstream& operator*(void) = 0;
102         virtual void Close(void) = 0;
103         virtual void Abort(void) = 0;
104     };
105 
106     virtual CRef<CBlobStream> OpenBlobStream(CReaderRequestResult& result,
107                                              const TBlobId& blob_id,
108                                              TChunkId chunk_id,
109                                              const CProcessor& processor) = 0;
110 
111     virtual bool CanWrite(EType type) const = 0;
112 
113     // helper writers
114     static void WriteInt(CNcbiOstream& stream, int value);
115     static void WriteBytes(CNcbiOstream& stream, CRef<CByteSource> bs);
116     static void WriteBytes(CNcbiOstream& stream, CRef<CByteSourceReader> rdr);
117     typedef vector<char> TOctetString;
118     typedef list<TOctetString*> TOctetStringSequence;
119     static void WriteBytes(CNcbiOstream& stream,
120                            const TOctetString& data);
121     static void WriteBytes(CNcbiOstream& stream,
122                            const TOctetStringSequence& data);
123     static void WriteProcessorTag(CNcbiOstream& stream,
124                                   const CProcessor& processor);
125 
126     virtual void InitializeCache(CReaderCacheManager& cache_manager,
127                                  const TPluginManagerParamTree* params);
128     virtual void ResetCache(void);
129 };
130 
131 
132 END_SCOPE(objects)
133 END_NCBI_SCOPE
134 
135 #endif // WRITER__HPP_INCLUDED
136