Standard C++ Libaray
This library contains standard C++ code, and is dependant on nothing other than the standard C/C++ library. Where posible I like to implement my common tools and utility code within the CyTools namespace.
#include <iostrem> // std::cout
#include <iomanip> // std::setfill, std::setw...
#include <string> // std::string
#include <cstring> // std::strncpy
#include <CyCrc.hpp> // CyTools::crc32
int main(int argc, char* argv[]) {
int data_a = 0x7590b31a;
float data_b = 2.538f;
char data_c[10];
std::string data_d = "String 1";
std::strncpy(data_c, "String 2", sizeof(data_c));
CyTools::crc32 a_crc; // creates a crc using the default 32-bit standard (PK-Zip)
// construction with default constructor enables JIT table
a_crc.add(data_a); // Uses sizeof and adds data_a
a_crc.add(data_b); // Uses sizeof and adds data_b
a_crc.add(data_c); // Uses std::char_traits<char>::length, adds 8 characters
a_crc.add(data_c, sizeof(data_c)); // adds all charaters of data_c, including nulls
a_crc.add(data_d); // not binary safe, but has overload, adds 8 characters
std::cout << std::setfill('0') << std::setw(8) << std::right << std::hex;
std::cout << a_crc << std::endl; // auto-finalization for seemless cast & stream
return 0;
}
CyCrc
version - 1.0.3
A small, fast, single header, CRC engine. Working with or without tables. When used, tables can be compile-time or run-time calculated. Tables can also be left to the CRC engine to manage, in this case tables are created just-in-time. The main header defines CRC standards for 8, 16, 32, and 64-bit CRC's. A second header (optional) defines a number of other standards.
Downloads
| CyCrc.zip | Main CRC header only. |
| CyCrc-complete.zip | CRC and extra definitions headers. |
| CyCrc-examples.zip | Sample code showing usage of CyCrc. |
#include <iostream> // std::cout
#include <iomanip> // std::setfill, std::setw...
#include <CyEndian.hpp> // CyTools::fix_byte_order
int main(int argc, char* argv[]) {
int data = 0x19ad75e0;
// prepare data for network transport; posibaly cross-platform
CyTools::fix_byte_order(data, CyTools::endian::system, CyTools::endian::network);
std::cout << std::setfill('0') << std::setw(8) << right << hex;
std::cout << data << std::endl;
// fix data from network for local processing
CyTools::fix_byte_order(data, CyTools::endian::network, CyTools::endian::system);
std::cout << std::setfill('0') << std::setw(8) << right << hex;
std::cout << data << std::endl;
// force data to a fixed order; may be for a file format
CyTools::fix_byte_order(data, CyTools::endian::system, CyTools::endian::big);
std::cout << std::setfill('0') << std::setw(8) << right << hex;
std::cout << data << std::endl;
return 0;
}
CyEndian
version - 1.0.1
Simple tool to detect system endianness, and data byte order conversion, in a single header. Defines an enum that holds values for big and little endianess, and system and network byte orders. A single templated function applies data conversion when in and out resolved to different orders.
Downloads
| CyEndian.zip | Endian, single header file. |
| CyEndian-examples.zip | Examples of using CyEndian. |