/////////////////////////////////////////////////////////////////////////// // crc.cpp - CRC calculations performed at compile-time using Template // // MetaProgramming // // // // source: Moliate, "A gentle introduction to Template Metaprogramming // // with C++", www.codeproject.com/cpp/crc_meta.asp // // Edits: Jim Fawcett, CSE687 - Object Oriented Design, Spring 2005 // // - a very few cosmetic modifications, like this prologue // // - prepended template <> before struct REF<0>, in crc.h, // // needed under the compilation rules for VC 7.1 // // Note: Notice that compilation time takes a lot longer than you are // // used to due to the compile time calculations done here. // /////////////////////////////////////////////////////////////////////////// // CRC_meta.cpp : Prints some text and exits. Not really interesting. // #include "stdafx.h" #include #include "crc.h" int main(int argc, char* argv[]) { #ifdef _DEBUG printf("================= CRC TABLE ============\n\n"); CRC::print_table(); printf("\n========================================\n\n"); #endif printf("\tCRC information\n"); printf("\tName: \t\"%s\"\n", CRC_NAME); printf("\tWidth: \t%ld bit\n", CRC_WIDTH); printf("\tPoly: \t%X", CRC_POLY); printf("\n\tInit: \t%X", CRC_INIT); printf("\n\tReflection in:\t"); #if TRUE == CRC_REFIN printf("TRUE\n"); #else printf("FALSE\n"); #endif printf("\tReflection out:\t"); #if TRUE == CRC_REFOUT printf("TRUE\n"); #else printf("FALSE\n"); #endif printf("\tXOR: \t%X", CRC_XOROUT); printf("\n\n"); if (1==argc) { char* teststring = CRC_CHECKSTRING; printf("============== Test results ============\n"); printf("Hashing string: \"%s\"\n", teststring); unsigned int res = CRC::Hash(reinterpret_cast(teststring), strlen(teststring)); printf("Result: %X %s\n", res, (CRC_CHECK==res)?"(Equals checkvalue)":"- FAILED"); if (CRC_CHECK != res) printf("Checkvalue: %X\n", CRC_CHECK); printf("=========================================\n\n"); } else {printf("\n=========================================\nChecksum for strings:\n\n"); for (int i = 1; i < argc; i++) printf("%X\t\"%s\"\n", CRC::Hash(reinterpret_cast(argv[i]), strlen(argv[i])), argv[i]); } return 0; }