Skip to content

Convert CSV files into C/C++ header files for easy #include

License

Notifications You must be signed in to change notification settings

fleschutz/csv2hpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

106 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

csv2hpp

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.).

πŸ‘£ Steps

  1. Export your database in CSV file format, e.g. to: database.csv
  2. Edit the CSV file and just add datatype hints to the header line, e.g.: Name (string), Age (int), Weight (_kg)
  3. Convert by executing: csv2hpp database.csv name_of_object > headerfile.hpp.
  4. Add the header file and #include "headerfile.hpp" to your project and immediately start developing.

πŸ’‘ Hints

  • 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:length and 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.

πŸŽ‰ Example

Using planets.csv and executing: csv2hpp planets.csv planet > planets.hpp results in the header file: planets.hpp.

🀝 Contributing

  • 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.

πŸ“œ License & Copyright

This open source project is licensed under the CC0-1.0 license. All trademarks are the property of their respective owners.