From 4f5e3f48ec887eb8781e9c066750ed37be063552 Mon Sep 17 00:00:00 2001 From: Daniel Standage Date: Wed, 31 May 2017 23:31:12 -0700 Subject: [PATCH] Replace ad hoc defines with an enumerated type --- include/oxli/oxli.hh | 13 ++++++++++--- src/khmer/_cpy_khmer.cc | 6 +++--- src/oxli/storage.cc | 18 +++++++++--------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/include/oxli/oxli.hh b/include/oxli/oxli.hh index ac8923662e..393403bd63 100644 --- a/include/oxli/oxli.hh +++ b/include/oxli/oxli.hh @@ -87,13 +87,20 @@ private:\ # define SAVED_SIGNATURE "OXLI" # define SAVED_FORMAT_VERSION 4 -# define SAVED_COUNTING_HT 1 -# define SAVED_HASHBITS 2 # define SAVED_TAGS 3 # define SAVED_STOPTAGS 4 # define SAVED_SUBSET 5 # define SAVED_LABELSET 6 -# define SAVED_SMALLCOUNT 7 + +typedef enum saved_sketch_type { + SAVED_NODETABLE, + SAVED_COUNTTABLE, + SAVED_SMALLCOUNTTABLE, + // The following are set explicitly for backwards compatibility + SAVED_NODEGRAPH = 2, + SAVED_COUNTGRAPH = 1, + SAVED_SMALLCOUNTGRAPH = 7 +} saved_sketch_type; # define TRAVERSAL_LEFT 0 # define TRAVERSAL_RIGHT 1 diff --git a/src/khmer/_cpy_khmer.cc b/src/khmer/_cpy_khmer.cc index 8722b18322..3ad404646c 100644 --- a/src/khmer/_cpy_khmer.cc +++ b/src/khmer/_cpy_khmer.cc @@ -350,13 +350,13 @@ MOD_INIT(_khmer) } PyObject * filetype_dict = Py_BuildValue("{s,i,s,i,s,i,s,i,s,i,s,i,s,i}", - "COUNTING_HT", SAVED_COUNTING_HT, - "HASHBITS", SAVED_HASHBITS, + "COUNTING_HT", SAVED_COUNTGRAPH, + "HASHBITS", SAVED_NODEGRAPH, "TAGS", SAVED_TAGS, "STOPTAGS", SAVED_STOPTAGS, "SUBSET", SAVED_SUBSET, "LABELSET", SAVED_LABELSET, - "SMALLCOUNT", SAVED_SMALLCOUNT); + "SMALLCOUNT", SAVED_SMALLCOUNTGRAPH); if (PyModule_AddObject( m, "FILETYPES", filetype_dict ) < 0) { return MOD_ERROR_VAL; } diff --git a/src/oxli/storage.cc b/src/oxli/storage.cc index 66acff127b..d82c03ca37 100644 --- a/src/oxli/storage.cc +++ b/src/oxli/storage.cc @@ -113,7 +113,7 @@ void BitStorage::save(std::string outfilename, WordLength ksize) unsigned char version = SAVED_FORMAT_VERSION; outfile.write((const char *) &version, 1); - unsigned char ht_type = SAVED_HASHBITS; + unsigned char ht_type = SAVED_NODEGRAPH; outfile.write((const char *) &ht_type, 1); outfile.write((const char *) &save_ksize, sizeof(save_ksize)); @@ -200,7 +200,7 @@ void BitStorage::load(std::string infilename, WordLength &ksize) << " while reading k-mer graph from " << infilename << "; should be " << (int) SAVED_FORMAT_VERSION; throw oxli_file_exception(err.str()); - } else if (!(ht_type == SAVED_HASHBITS)) { + } else if (!(ht_type == SAVED_NODEGRAPH)) { std::ostringstream err; err << "Incorrect file format type " << (int) ht_type << " while reading k-mer graph from " << infilename; @@ -330,7 +330,7 @@ ByteStorageFileReader::ByteStorageFileReader( << " while reading k-mer count file from " << infilename << "; should be " << (int) SAVED_FORMAT_VERSION; throw oxli_file_exception(err.str()); - } else if (!(ht_type == SAVED_COUNTING_HT)) { + } else if (!(ht_type == SAVED_COUNTGRAPH)) { std::ostringstream err; err << "Incorrect file format type " << (int) ht_type << " while reading k-mer count file from " << infilename; @@ -446,7 +446,7 @@ ByteStorageGzFileReader::ByteStorageGzFileReader( SAVED_SIGNATURE; throw oxli_file_exception(err.str()); } else if (!(version == SAVED_FORMAT_VERSION) - || !(ht_type == SAVED_COUNTING_HT)) { + || !(ht_type == SAVED_COUNTGRAPH)) { if (!(version == SAVED_FORMAT_VERSION)) { std::ostringstream err; err << "Incorrect file format version " << (int) version @@ -454,7 +454,7 @@ ByteStorageGzFileReader::ByteStorageGzFileReader( << "; should be " << (int) SAVED_FORMAT_VERSION; gzclose(infile); throw oxli_file_exception(err.str()); - } else if (!(ht_type == SAVED_COUNTING_HT)) { + } else if (!(ht_type == SAVED_COUNTGRAPH)) { std::ostringstream err; err << "Incorrect file format type " << (int) ht_type << " while reading k-mer count file from " << infilename; @@ -599,7 +599,7 @@ ByteStorageFileWriter::ByteStorageFileWriter( unsigned char version = SAVED_FORMAT_VERSION; outfile.write((const char *) &version, 1); - unsigned char ht_type = SAVED_COUNTING_HT; + unsigned char ht_type = SAVED_COUNTGRAPH; outfile.write((const char *) &ht_type, 1); unsigned char use_bigcount = 0; @@ -666,7 +666,7 @@ ByteStorageGzFileWriter::ByteStorageGzFileWriter( unsigned char version = SAVED_FORMAT_VERSION; gzwrite(outfile, (const char *) &version, 1); - unsigned char ht_type = SAVED_COUNTING_HT; + unsigned char ht_type = SAVED_COUNTGRAPH; gzwrite(outfile, (const char *) &ht_type, 1); unsigned char use_bigcount = 0; @@ -786,7 +786,7 @@ void NibbleStorage::save(std::string outfilename, WordLength ksize) unsigned char version = SAVED_FORMAT_VERSION; outfile.write((const char *) &version, 1); - unsigned char ht_type = SAVED_SMALLCOUNT; + unsigned char ht_type = SAVED_SMALLCOUNTGRAPH; outfile.write((const char *) &ht_type, 1); outfile.write((const char *) &save_ksize, sizeof(save_ksize)); @@ -860,7 +860,7 @@ void NibbleStorage::load(std::string infilename, WordLength& ksize) << " while reading k-mer count file from " << infilename << "; should be " << (int) SAVED_FORMAT_VERSION; throw oxli_file_exception(err.str()); - } else if (!(ht_type == SAVED_SMALLCOUNT)) { + } else if (!(ht_type == SAVED_SMALLCOUNTGRAPH)) { std::ostringstream err; err << "Incorrect file format type " << (int) ht_type << " while reading k-mer count file from " << infilename;