libStatGen Software 1
Loading...
Searching...
No Matches
SamRecordPool.h
1/*
2 * Copyright (C) 2011 Regents of the University of Michigan
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __SAM_RECORD_POOL_H__
19#define __SAM_RECORD_POOL_H__
20
21#include <queue>
22#include "SamRecord.h"
23
24
26{
27public:
28 /// Constructor that sets there to be no max number of allocated records.
30
31 /// Constructor that sets the maximum number of allocated records
32 /// \param maxNumRecs maximum number of allocated records (-1 means no max)
33 SamRecordPool(int maxNumRecs);
34
35 /// Destructor. Any records that were allocated without calling "releaseRecord"
36 /// will not get cleaned up and the user will need to delete them.
38
39 /// Get a SamRecord. If records are already allocated and free use those, if not
40 /// and there are still more that are allowed to be allocated, allocate a new one.
41 /// If no more records are allowed to be allocated, NULL is returned.
42 /// NOTE: The user should call releaseRecord when done using the record.
43 /// If the user deletes the record instead, it still counts as allocated when
44 /// comparing against the maxNumRecs but cannot be reused.
45 /// \return pointer to a SamRecord available for use, or NULL if no more records
46 /// are allowed to be allocated.
48
49 /// If record is not NULL, adds it back to the free list.
50 /// If record is NULL, nothing is done.
51 /// \param record pointer to a record that is no longer being used
52 /// and is available for reuse.
53 void releaseRecord(SamRecord* record);
54
55 /// Set the maximum number of records allowed to be allocated.
56 /// If more than the new value have already been allocated,
57 /// it does not deallocate any, and will continue to reuse
58 /// the already allocated records, but it will not allocate
59 /// any additional records.
60 void setMaxAllocatedRecs(int maxNumRecs);
61
62
63private:
64
65 std::queue<SamRecord*> myFreeSamRecords;
66 int myMaxAllowedRecs;
67 int myAllocatedRecs;
68};
69
70#endif
void setMaxAllocatedRecs(int maxNumRecs)
Set the maximum number of records allowed to be allocated.
void releaseRecord(SamRecord *record)
If record is not NULL, adds it back to the free list.
~SamRecordPool()
Destructor.
SamRecordPool()
Constructor that sets there to be no max number of allocated records.
SamRecord * getRecord()
Get a SamRecord.
Class providing an easy to use interface to get/set/operate on the fields in a SAM/BAM record.
Definition SamRecord.h:52