1
/* $Id: blast_hspstream.c,v 1.3 2004/06/07 17:06:49 dondosha Exp $
2
* ===========================================================================
5
* National Center for Biotechnology Information
7
* This software/database is a "United States Government Work" under the
8
* terms of the United States Copyright Act. It was written as part of
9
* the author's official duties as a United States Government employee and
10
* thus cannot be copyrighted. This software/database is freely available
11
* to the public for use. The National Library of Medicine and the U.S.
12
* Government have not placed any restriction on its use or reproduction.
14
* Although all reasonable efforts have been taken to ensure the accuracy
15
* and reliability of the software and data, the NLM and the U.S.
16
* Government do not and cannot warrant the performance or results that
17
* may be obtained by using this software or data. The NLM and the U.S.
18
* Government disclaim all warranties, express or implied, including
19
* warranties of performance, merchantability or fitness for any particular
22
* Please cite the author in any work or product based on this material.
24
* ===========================================================================
26
* Author: Christiam Camacho
30
/** @file blast_hspstream.c
31
* Definition of ADT to save and retrieve lists of HSPs in the BLAST engine.
34
static char const rcsid[] =
35
"$Id: blast_hspstream.c,v 1.3 2004/06/07 17:06:49 dondosha Exp $";
37
#include <algo/blast/core/blast_hspstream.h>
38
#include <algo/blast/core/blast_def.h> /* needed for sfree */
40
/** Complete type definition of Blast Hsp Stream ADT */
41
struct BlastHSPStream {
42
BlastHSPStreamConstructor NewFnPtr; /**< Constructor */
43
BlastHSPStreamDestructor DeleteFnPtr; /**< Destructor */
45
/* The operational interface */
47
BlastHSPStreamMethod WriteFnPtr; /**< Write to BlastHSPStream */
48
BlastHSPStreamMethod ReadFnPtr; /**< Read from BlastHSPStream */
49
BlastHSPStreamCloseFnType CloseFnPtr; /**< Close BlastHSPStream for
51
void* DataStructure; /**< ADT holding HSPStream */
54
BlastHSPStream* BlastHSPStreamNew(const BlastHSPStreamNewInfo* bhsn_info)
56
BlastHSPStream* retval = NULL;
57
BlastHSPStreamFunctionPointerTypes fnptr;
59
if ( bhsn_info == NULL ) {
63
if ( !(retval = (BlastHSPStream*) calloc(1, sizeof(BlastHSPStream)))) {
67
/* Save the constructor and invoke it */
68
fnptr.ctor = bhsn_info->constructor;
69
SetMethod(retval, eConstructor, fnptr);
70
if (retval->NewFnPtr) {
71
retval = (*retval->NewFnPtr)(retval, bhsn_info->ctor_argument);
76
ASSERT(retval->DeleteFnPtr);
77
ASSERT(retval->WriteFnPtr);
78
ASSERT(retval->ReadFnPtr);
83
BlastHSPStream* BlastHSPStreamFree(BlastHSPStream* hsp_stream)
85
BlastHSPStreamDestructor destructor_fnptr = NULL;
88
return (BlastHSPStream*) NULL;
91
if ( !(destructor_fnptr = (*hsp_stream->DeleteFnPtr))) {
96
return (BlastHSPStream*) (*destructor_fnptr)(hsp_stream);
99
void BlastHSPStreamClose(BlastHSPStream* hsp_stream)
101
BlastHSPStreamCloseFnType close_fnptr = NULL;
106
/** Close functionality is optional. If closing function is not provided,
108
if ( !(close_fnptr = (*hsp_stream->CloseFnPtr))) {
112
(*close_fnptr)(hsp_stream);
115
const int kBlastHSPStream_Error = -1;
116
const int kBlastHSPStream_Success = 0;
117
const int kBlastHSPStream_Eof = 1;
119
/** This method is akin to a vtable dispatcher, invoking the method registered
120
* upon creation of the implementation of the BlastHSPStream interface
121
* @param hsp_stream The BlastHSPStream object [in]
122
* @param name Name of the method to invoke on hsp_stream [in]
123
* @param arg Arbitrary argument passed to the method name [in]
124
* @return kBlastHSPStream_Error on NULL hsp_stream or NULL method pointer
125
* (i.e.: unimplemented or uninitialized method on the BlastHSPStream
126
* interface) or return value of the implementation.
129
_MethodDispatcher(BlastHSPStream* hsp_stream, EMethodName name,
130
BlastHSPList** hsp_list)
132
BlastHSPStreamMethod method_fnptr = NULL;
135
return kBlastHSPStream_Error;
138
ASSERT(name < eMethodBoundary);
142
method_fnptr = (*hsp_stream->ReadFnPtr);
146
method_fnptr = (*hsp_stream->WriteFnPtr);
150
abort(); /* should never happen */
154
return kBlastHSPStream_Error;
157
return (*method_fnptr)(hsp_stream, hsp_list);
160
int BlastHSPStreamRead(BlastHSPStream* hsp_stream, BlastHSPList** hsp_list)
162
return _MethodDispatcher(hsp_stream, eRead, hsp_list);
165
int BlastHSPStreamWrite(BlastHSPStream* hsp_stream, BlastHSPList** hsp_list)
167
return _MethodDispatcher(hsp_stream, eWrite, hsp_list);
170
/*****************************************************************************/
172
void* GetData(BlastHSPStream* hsp_stream)
178
return hsp_stream->DataStructure;
181
int SetData(BlastHSPStream* hsp_stream, void* data)
184
return kBlastHSPStream_Error;
187
hsp_stream->DataStructure = data;
189
return kBlastHSPStream_Success;
192
int SetMethod(BlastHSPStream* hsp_stream,
194
BlastHSPStreamFunctionPointerTypes fnptr_type)
197
return kBlastHSPStream_Error;
200
ASSERT(name < eMethodBoundary);
204
hsp_stream->NewFnPtr = fnptr_type.ctor;
208
hsp_stream->DeleteFnPtr = fnptr_type.dtor;
212
hsp_stream->ReadFnPtr = fnptr_type.method;
216
hsp_stream->WriteFnPtr = fnptr_type.method;
220
hsp_stream->CloseFnPtr = fnptr_type.closeFn;
224
abort(); /* should never happen */
227
return kBlastHSPStream_Success;