Skip to content

Commit 0b836c0

Browse files
committed
Add bcf_get_info_int64; make bcf_update_info_int64 a static inline
As bcf_get_info_int64() and bcf_update_info_int64() are new interfaces, they can be made static inlines instead of macros so that the compiler can check the data type of the values / dst parameter. The old macros probably have to stay as they are as we don't know how they are being used in third-party code. The documentation around the bcf_get_info_ and bcf_update_info_ macros is made a bit more doxygen-like.
1 parent 9dc3992 commit 0b836c0

1 file changed

Lines changed: 71 additions & 19 deletions

File tree

htslib/vcf.h

Lines changed: 71 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -669,26 +669,51 @@ set to one of BCF_ERR* codes and must be checked before calling bcf_write().
669669
int bcf_update_id(const bcf_hdr_t *hdr, bcf1_t *line, const char *id);
670670
int bcf_add_id(const bcf_hdr_t *hdr, bcf1_t *line, const char *id);
671671

672-
/*
672+
/**
673673
* bcf_update_info_*() - functions for updating INFO fields
674-
* @hdr: the BCF header
675-
* @line: VCF line to be edited
676-
* @key: the INFO tag to be updated
677-
* @values: pointer to the array of values. Pass NULL to remove the tag.
678-
* @n: number of values in the array. When set to 0, the INFO tag is removed
674+
* @param hdr: the BCF header
675+
* @param line: VCF line to be edited
676+
* @param key: the INFO tag to be updated
677+
* @param values: pointer to the array of values. Pass NULL to remove the tag.
678+
* @param n: number of values in the array. When set to 0, the INFO tag is removed
679+
* @return 0 on success or negative value on error.
679680
*
680-
* The @string in bcf_update_info_flag() is optional, @n indicates whether
681-
* the flag is set or removed.
681+
* The @p string in bcf_update_info_flag() is optional,
682+
* @p n indicates whether the flag is set or removed.
682683
*
683-
* Returns 0 on success or negative value on error.
684684
*/
685685
#define bcf_update_info_int32(hdr,line,key,values,n) bcf_update_info((hdr),(line),(key),(values),(n),BCF_HT_INT)
686-
#define bcf_update_info_int64(hdr,line,key,values,n) bcf_update_info((hdr),(line),(key),(values),(n),BCF_HT_LONG)
687686
#define bcf_update_info_float(hdr,line,key,values,n) bcf_update_info((hdr),(line),(key),(values),(n),BCF_HT_REAL)
688687
#define bcf_update_info_flag(hdr,line,key,string,n) bcf_update_info((hdr),(line),(key),(string),(n),BCF_HT_FLAG)
689688
#define bcf_update_info_string(hdr,line,key,string) bcf_update_info((hdr),(line),(key),(string),1,BCF_HT_STR)
690689
int bcf_update_info(const bcf_hdr_t *hdr, bcf1_t *line, const char *key, const void *values, int n, int type);
691690

691+
/// Set or update 64-bit integer INFO values
692+
/**
693+
* @param hdr: the BCF header
694+
* @param line: VCF line to be edited
695+
* @param key: the INFO tag to be updated
696+
* @param values: pointer to the array of values. Pass NULL to remove the tag.
697+
* @param n: number of values in the array. When set to 0, the INFO tag is removed
698+
* @return 0 on success or negative value on error.
699+
*
700+
* The @p string in bcf_update_info_flag() is optional,
701+
* @p n indicates whether the flag is set or removed.
702+
*
703+
* This function takes an int64_t values array as input. The data
704+
* actually stored will be shrunk to the minimum size that can
705+
* accept all of the values.
706+
*
707+
* INFO values outside of the range BCF_MIN_BT_INT32 to BCF_MAX_BT_INT32
708+
* can only be written to VCF files.
709+
*/
710+
static inline int bcf_update_info_int64(const bcf_hdr_t *hdr, bcf1_t *line,
711+
const char *key,
712+
const int64_t *values, int n)
713+
{
714+
return bcf_update_info(hdr, line, key, values, n, BCF_HT_LONG);
715+
}
716+
692717
/*
693718
* bcf_update_format_*() - functions for updating FORMAT fields
694719
* @values: pointer to the array of values, the same number of elements
@@ -756,29 +781,56 @@ set to one of BCF_ERR* codes and must be checked before calling bcf_write().
756781

757782
/**
758783
* bcf_get_info_*() - get INFO values, integers or floats
759-
* @hdr: BCF header
760-
* @line: BCF record
761-
* @tag: INFO tag to retrieve
762-
* @dst: *dst is pointer to a memory location, can point to NULL
763-
* @ndst: pointer to the size of allocated memory
784+
* @param hdr: BCF header
785+
* @param line: BCF record
786+
* @param tag: INFO tag to retrieve
787+
* @param dst: *dst is pointer to a memory location, can point to NULL
788+
* @param ndst: pointer to the size of allocated memory
789+
* @return 0 on success
790+
* -1 .. no such INFO tag defined in the header
791+
* -2 .. clash between types defined in the header and encountered in the VCF record
792+
* -3 .. tag is not present in the VCF record
764793
*
765794
* Returns negative value on error or the number of written values
766795
* (including missing values) on success. bcf_get_info_string() returns
767796
* on success the number of characters written excluding the null-
768797
* terminating byte. bcf_get_info_flag() returns 1 when flag is set or 0
769798
* if not.
770799
*
771-
* List of return codes:
772-
* -1 .. no such INFO tag defined in the header
773-
* -2 .. clash between types defined in the header and encountered in the VCF record
774-
* -3 .. tag is not present in the VCF record
775800
*/
776801
#define bcf_get_info_int32(hdr,line,tag,dst,ndst) bcf_get_info_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_INT)
777802
#define bcf_get_info_float(hdr,line,tag,dst,ndst) bcf_get_info_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_REAL)
778803
#define bcf_get_info_string(hdr,line,tag,dst,ndst) bcf_get_info_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_STR)
779804
#define bcf_get_info_flag(hdr,line,tag,dst,ndst) bcf_get_info_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_FLAG)
780805
int bcf_get_info_values(const bcf_hdr_t *hdr, bcf1_t *line, const char *tag, void **dst, int *ndst, int type);
781806

807+
/// Put integer INFO values into an int64_t array
808+
/**
809+
* @param hdr: BCF header
810+
* @param line: BCF record
811+
* @param tag: INFO tag to retrieve
812+
* @param dst: *dst is pointer to a memory location, can point to NULL
813+
* @param ndst: pointer to the size of allocated memory
814+
* @return 0 on success
815+
* -1 .. no such INFO tag defined in the header
816+
* -2 .. clash between types defined in the header and encountered in the VCF record
817+
* -3 .. tag is not present in the VCF record
818+
*
819+
* Returns negative value on error or the number of written values
820+
* (including missing values) on success. bcf_get_info_string() returns
821+
* on success the number of characters written excluding the null-
822+
* terminating byte. bcf_get_info_flag() returns 1 when flag is set or 0
823+
* if not.
824+
*
825+
*/
826+
static inline int bcf_get_info_int64(const bcf_hdr_t *hdr, bcf1_t *line,
827+
const char *tag, int64_t **dst,
828+
int *ndst)
829+
{
830+
return bcf_get_info_values(hdr, line, tag,
831+
(void **) dst, ndst, BCF_HT_LONG);
832+
}
833+
782834
/**
783835
* bcf_get_format_*() - same as bcf_get_info*() above
784836
*

0 commit comments

Comments
 (0)