diff --git a/src/FastaVector.c b/src/FastaVector.c index fa9ae31..9e608be 100644 --- a/src/FastaVector.c +++ b/src/FastaVector.c @@ -50,15 +50,10 @@ void fastaVectorDealloc(struct FastaVector *fastaVector) { fastaVectorStringDealloc(&fastaVector->header); fastaVectorMetadataVectorDealloc(&fastaVector->metadata); } -#ifdef __cplusplus -enum FastaVectorReturnCode -fastaVectorReadFasta(const char *__restrict__ const fileSrc, - struct FastaVector *fastaVector) { -#else + enum FastaVectorReturnCode -fastaVectorReadFasta(const char *restrict const fileSrc, +fastaVectorReadFasta(const char *_RESTRICT_ const fileSrc, struct FastaVector *fastaVector) { -#endif FILE *fastaFile = fopen(fileSrc, "r"); if (__builtin_expect(!fastaFile, false)) { @@ -174,16 +169,10 @@ fastaVectorReadFasta(const char *restrict const fileSrc, return FASTA_VECTOR_OK; } -#ifdef __cplusplus -fastaVectorWriteFasta(const char *__restrict__ const fileSrc, - struct FastaVector *fastaVector, - uint32_t fileLineLength) { -#else enum FastaVectorReturnCode -fastaVectorWriteFasta(const char *restrict const fileSrc, +fastaVectorWriteFasta(const char *_RESTRICT_ const fileSrc, struct FastaVector *fastaVector, uint32_t fileLineLength) { -#endif FILE *fastaFile = fopen(fileSrc, "w+"); if (!fastaFile) { return FASTA_VECTOR_FILE_WRITE_FAIL; @@ -304,9 +293,8 @@ fastaVectorAddSequenceToList(struct FastaVector *fastaVector, char *header, // return NULL for headerPtr and 0 for header length if the fastaVector does not // have a header for the given headerIndex -void fastaVectorFastaGetHeader(struct FastaVector *fastaVector, - size_t headerIndex, char **headerPtr, - size_t *headerLength) { +void fastaVectorGetHeader(struct FastaVector *fastaVector, size_t headerIndex, + char **headerPtr, size_t *headerLength) { if (__builtin_expect(headerIndex >= fastaVector->metadata.count, false)) { *headerLength = 0; *headerPtr = NULL; @@ -326,9 +314,9 @@ void fastaVectorFastaGetHeader(struct FastaVector *fastaVector, // return NULL for headerPtr and 0 for header length if the fastaVector does not // have a header for the given headerIndex -void fastaVectorFastaGetSequence(struct FastaVector *fastaVector, - size_t sequenceIndex, char **sequencePtr, - size_t *sequenceLength) { +void fastaVectorGetSequence(struct FastaVector *fastaVector, + size_t sequenceIndex, char **sequencePtr, + size_t *sequenceLength) { if (__builtin_expect(sequenceIndex >= fastaVector->metadata.count, false)) { *sequenceLength = 0; *sequencePtr = NULL; diff --git a/src/FastaVector.h b/src/FastaVector.h index 2b8bc52..9791e5d 100644 --- a/src/FastaVector.h +++ b/src/FastaVector.h @@ -13,6 +13,12 @@ #include #include +#ifdef __cplusplus +#define _RESTRICT_ __restrict__ +#else +#define _RESTRICT_ restrict +#endif + /// @brief Primary struct that stores data for a given FASTA file. struct FastaVector { /// @brief Storage for the fasta sequence data. @@ -98,15 +104,9 @@ void fastaVectorDealloc(struct FastaVector *fastaVector); * takes any properly formed fasta file, and loads all headers and sequences. * */ -#ifdef __cplusplus -enum FastaVectorReturnCode -fastaVectorReadFasta(const char *__restrict__ const fileSrc, - struct FastaVector *fastaVector); -#else enum FastaVectorReturnCode -fastaVectorReadFasta(const char *restrict const fileSrc, +fastaVectorReadFasta(const char *_RESTRICT_ const fileSrc, struct FastaVector *fastaVector); -#endif /** * @relates FastaVector @@ -124,15 +124,9 @@ fastaVectorReadFasta(const char *restrict const fileSrc, * This function will overwrite the file at the given path. * */ -#ifdef __cplusplus enum FastaVectorReturnCode -fastaVectorWriteFasta(const char *__restrict__ const filePath, +fastaVectorWriteFasta(const char *_RESTRICT_ const filePath, struct FastaVector *fastaVector, uint32_t fileLineLength); -#else -enum FastaVectorReturnCode -fastaVectorWriteFasta(const char *restrict const filePath, - struct FastaVector *fastaVector, uint32_t fileLineLength); -#endif /** * @relates FastaVector @@ -168,9 +162,8 @@ fastaVectorAddSequenceToList(struct FastaVector *fastaVector, char *header, * * */ -void fastaVectorFastaGetHeader(struct FastaVector *fastaVector, - size_t headerIndex, char **headerPtr, - size_t *headerLength); +void fastaVectorGetHeader(struct FastaVector *fastaVector, size_t headerIndex, + char **headerPtr, size_t *headerLength); /** * @relates FastaVector @@ -187,9 +180,9 @@ void fastaVectorFastaGetHeader(struct FastaVector *fastaVector, * TODO: Should we return a static code in case the index was out of bounds? * */ -void fastaVectorFastaGetSequence(struct FastaVector *fastaVector, - size_t sequenceIndex, char **sequencePtr, - size_t *sequenceLength); +void fastaVectorGetSequence(struct FastaVector *fastaVector, + size_t sequenceIndex, char **sequencePtr, + size_t *sequenceLength); /** * @relates FastaVector diff --git a/tests/fileReadTest/fileReadTest.c b/tests/fileReadTest/fileReadTest.c index d065415..c4df860 100644 --- a/tests/fileReadTest/fileReadTest.c +++ b/tests/fileReadTest/fileReadTest.c @@ -23,7 +23,7 @@ void readTest(char **const testHeaderStrings, char **const testSequenceStrings, const size_t expectedSequenceLength = strlen(testSequenceStrings[i]); size_t headerLength; char *headerPtr; - fastaVectorFastaGetHeader(&fastaVector, i, &headerPtr, &headerLength); + fastaVectorGetHeader(&fastaVector, i, &headerPtr, &headerLength); sprintf(buffer, "header length of %zu did not match expected length %zu.", headerLength, expectedHeaderLength); @@ -38,7 +38,7 @@ void readTest(char **const testHeaderStrings, char **const testSequenceStrings, char *sequencePtr; size_t sequenceLength; - fastaVectorFastaGetSequence(&fastaVector, i, &sequencePtr, &sequenceLength); + fastaVectorGetSequence(&fastaVector, i, &sequencePtr, &sequenceLength); sprintf(buffer, "sequence length of %zu did not match expected length %zu.", sequenceLength, expectedSequenceLength); testAssertString(sequenceLength == expectedSequenceLength, buffer); @@ -53,7 +53,7 @@ void readTest(char **const testHeaderStrings, char **const testSequenceStrings, char terminator = headerPtr[headerLength - 1]; sprintf(buffer, - "header index %zu was not null terminated! (found char %c after " + "header index %zu was not null terminated! (found char %u after " "the end of the header)", i, terminator); testAssertString(terminator == '\0', buffer); diff --git a/tests/fileWriteTest/fileWriteTest.c b/tests/fileWriteTest/fileWriteTest.c index 9288108..6e0aa25 100644 --- a/tests/fileWriteTest/fileWriteTest.c +++ b/tests/fileWriteTest/fileWriteTest.c @@ -110,9 +110,9 @@ void fastaVectorFileWriteTest(const size_t numSequences, const char *fileSrc) { char *sequenceFromVector; size_t headerLengthFromVector; size_t sequenceLengthFromVector; - fastaVectorFastaGetHeader(&fastaVector, sequenceNum, &headerFromVector, + fastaVectorGetHeader(&fastaVector, sequenceNum, &headerFromVector, &headerLengthFromVector); - fastaVectorFastaGetSequence(&fastaVector, sequenceNum, &sequenceFromVector, + fastaVectorGetSequence(&fastaVector, sequenceNum, &sequenceFromVector, &sequenceLengthFromVector); sprintf(buffer, "header was supposed to be length %zu, but got %zu.", headerLength, headerLengthFromVector); @@ -155,7 +155,7 @@ void fastaVectorFileWriteTest(const size_t numSequences, const char *fileSrc) { if (fastaVector.header.count != fastaReadVector.header.count) { size_t lastHeaderLen; char *lastHeaderPtr; - fastaVectorFastaGetHeader(&fastaVector, fastaVector.metadata.count - 1, + fastaVectorGetHeader(&fastaVector, fastaVector.metadata.count - 1, &lastHeaderPtr, &lastHeaderLen); printf("headers did not match, \n h1: %.*s\n h2: %.*s\n hr: %.*s\n", (int)fastaVector.header.count, fastaVector.header.charData,