This utility converts databases from CSV file format into C/C++ header files. Afterward, include them in your software projects and immediately work on structured, well-formed datasets (and skip CSV file delivering, loading, parsing, converting, etc.).
- Export your database in CSV file format, e.g. to:
database.csv - Edit the CSV file and just add datatype hints to the header line, e.g.:
Name (string), Age (int), Weight (_kg) - Convert by executing:
csv2hpp database.csv name_of_object > headerfile.hpp. - Add the header file and
#include "headerfile.hpp"to your project and immediately start developing.
- Datatype hints are mapped to C/C++ datatypes as follows:
(string) -> const char*,(int) -> int,(long) -> long,(float) -> float,(double) -> double,(byte) -> unsigned char,(bool) -> bool,(skip)skips the entire column,(_km) -> SI:lengthand so on. - Empty CSV cells are mapped to "" for strings and to 00 for everything else (as a hint).
- Trailing '0's for float and double values are removed (more compact).
- Precision hints (e.g. 'Β±05') are removed for float and double values.
- Supports very large .CSV files by using 'const char*' instead of 'std::string' (breaks some compilers) and by omitting whitespaces.
Using planets.csv and executing: csv2hpp planets.csv planet > planets.hpp results in the header file: planets.hpp.
- Contributions, suggestions, and improvements are welcome!
- Open an Issue if you encounter bugs or have feature ideas.
- Create a Pull Request if you'd like to improve something.
This open source project is licensed under the CC0-1.0 license. All trademarks are the property of their respective owners.