How shajeen/spreadsheet-to-cpplib works
Project Type & Purpose
• It’s a command‐line Python application (CLI tool) that reads spreadsheet files (CSV or Excel) and outputs a self‐contained C++ library (with CMake build scripts).
• It optionally embeds the ExprTk header‐only math library for formula evaluation.
File Structure
• Top‐level:
• setup.py, pyproject.toml → Python packaging & CLI entry point
• README.md, LICENSE, CONTRIBUTING, .github/ → project governance
• example/, sample/ → usage demos
• spreadsheet_to_cpplib/ → core implementation
• Inside spreadsheet_to_cpplib/:
• main.py / run.py / clitest.py → CLI argument parsing & user prompts
• parse.py, csvToCpp.py → spreadsheet reading & conversion to an internal representation (IR)
• template_*.py → code‐generation templates (CMake, header‐only, math support, source files)
• fileOperations.py → file system abstraction (create output dirs, write files)
• lib/exprtk.hpp → bundled third‐party header library
README for Insights
• The tool “promotes questions” and then “generates files in output,” so there is a user‐interaction step via CLI.
• Outputs: CMakeLists.txt, .h/.cpp files, optionally header‐only or full library.
Draft the Main Components
a. User & CLI Layer
– User invokes spreadsheet-to-cpplib --file=…
– clitest.py + main.py parse arguments and call run.py
b. Orchestrator / Controller (run.py)
– Hosts the Q&A flow, determines user options (header‐only, math support, etc.)
c. Parser / Converter
– parse.py (for Excel)
– csvToCpp.py (for CSV)
→ Both output a uniform IR (cells, formulas, types).
d. Template Engine
– template_cmake.py → Generates CMakeLists.txt
– template_headeronly.py → Emits .h files if header‐only
– template_source.py → Emits .cpp + .h for non‐header‐only
– template_math.py → Injects ExprTk-dependent code if math support selected
– asciitext.py → (optional) produces ASCII table documentation in code
e. File System Writer (fileOperations.py)
– Creates output folder structure
– Copies exprtk.hpp into the output lib/ folder when needed
– Writes all generated code & CMake files
f. External / Third-Party
– Python stdlib csv, openpyxl (implicitly used by parse.py)
– ExprTk C++ header (bundled in lib/)
Relationships & Data Flow
User → CLI Parsing → Orchestrator
Orchestrator → (based on file extension) → Parser or CSV Converter → IR
IR → Template Engine (multiple modules) → Generated code artifacts
Generated artifacts + exprtk.hpp → FileOperations → Output directory
Architectural Patterns & Design Principles
• Separation of concerns: parsing vs templating vs I/O
• Strategy pattern: each template_*.py is a strategy for a code‐generation variant
• Modularity: each major function lives in its own module
Technologies & Frameworks
• Python 3 CLI (setup.py / pyproject.toml)
• CMake for generated C++ library
• ExprTk header‐only library for math formulas
• CSV / Excel reading via Python libraries