File: BAB_class.c

package info (click to toggle)
r-bioc-biostrings 2.42.1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 14,652 kB
  • ctags: 721
  • sloc: ansic: 10,262; sh: 11; makefile: 2
file content (66 lines) | stat: -rw-r--r-- 1,667 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/****************************************************************************
 *                    Basic manipulation of BAB objects                     *
 *                            Author: H. Pag\`es                            *
 ****************************************************************************/
#include "Biostrings.h"
#include "IRanges_interface.h"


SEXP IntegerBAB_new(SEXP max_nblock)
{
	SEXP blocks, prot, xp, classdef, ans;

	PROTECT(blocks = NEW_LIST(INTEGER(max_nblock)[0]));
	PROTECT(prot = NEW_INTEGER(2));
	INTEGER(prot)[0] = 0;  // nblock
	PROTECT(xp = R_MakeExternalPtr(NULL, blocks, prot));
	PROTECT(classdef = MAKE_CLASS("IntegerBAB"));
	PROTECT(ans = NEW_OBJECT(classdef));
	SET_SLOT(ans, mkChar("xp"), xp);
	UNPROTECT(5);
	return ans;
}

int *_get_BAB_nblock_ptr(SEXP x)
{
	SEXP xp, prot;

	xp = GET_SLOT(x, install("xp"));
	prot = R_ExternalPtrProtected(xp);
	return INTEGER(prot);
}

int *_get_BAB_lastblock_nelt_ptr(SEXP x)
{
	return _get_BAB_nblock_ptr(x) + 1;
}

SEXP _get_BAB_blocks(SEXP x)
{
	SEXP xp;

	xp = GET_SLOT(x, install("xp"));
	return R_ExternalPtrTag(xp);
}

SEXP _IntegerBAB_addblock(SEXP x, int block_length)
{
	SEXP xp, blocks, prot, block;
	int max_nblock, nblock; 

	xp = GET_SLOT(x, install("xp"));
	blocks = R_ExternalPtrTag(xp);
	max_nblock = LENGTH(blocks);
	prot = R_ExternalPtrProtected(xp);
	nblock = INTEGER(prot)[0];
	if (nblock >= max_nblock)
		error("_IntegerBAB_addblock(): reached max buffer size");
	PROTECT(block = NEW_INTEGER(block_length));
	SET_ELEMENT(blocks, nblock, block);
	UNPROTECT(1);
	nblock++;
	INTEGER(prot)[0] = nblock;
	INTEGER(prot)[1] = 0;  // lastblock_nelt
	return block;
}