cppmagic is a tool for generating C++ source files and headers. It provides functionality to generate, sort, and synchronize C++ files based on headers.
This program works based on the output generate by ctags.
# Runtime dependency
sudo apt install universal-ctags
# Optional dependency.
sudo apt install libgtest-dev libdw-dev libunwind-devgit clone https://github.com/ms-jagadeeshan/cppmagic.git
cd cppmagic && mkdir build && cd build
cmake .. -DENABLE_TRACEBACK=OFF
make -j$(nproc)cppmagic <subcommand> <options> files/folders
generateGenerate .cpp from header.sortSort the functions in .cpp with respect to given sorting method.boomSort the functions in .cpp and fills the missing functions in .cpp
-h,--helpPrint this help message and exit--method TEXTSorting method. header, alpha (Default :header)
--ctags-path ...Path of ctags executable.(Default:/usr/bin/ctags)--header-ext ...File extensions to be considered as headers.--source-ext ...File extensions to be considered as sources.-i,--in-place SUFFIXEdit files in place (makes backup if SUFFIX supplied)
To sort C++ files based on their header files, you can specify directories or individual files:
- Sorting Directories: If you have both headers and sources in separate directories:
- HEADER_FOLDER: The directory containing your header files (e.g.,
include/mylibrary). - SOURCE_FOLDER: The directory where the source files exist or to be generated (e.g.,
src/).
./cppmagic sort [HEADER_FOLDER] [SOURCE_FOLDER]- Sorting Single Folder: If your headers and sources are in the same directory:
./cppmagic sort [FOLDER]- Sorting Files: if you want to sort certail files only:
./cppmagic sort [FILES]To sort functions in .cpp with respect to function order in header.
cppmagic/
├── CMakeLists.txt
├── include/
│ ├── cppmagic/
│ │ ├── CppMagic.hpp
│ │ ├── FilePath.hpp
│ │ ├── FileSelector.hpp
│ │ ├── GenerateMode.hpp
│ │ └── ... (other headers)
├── src/
│ ├── CppMagic.cpp
│ ├── FilePath.cpp
│ ├── FileSelector.cpp
│ ├── GenerateMode.cpp
│ └── ... (other files)cppmagic sort include/cppmagic src
cppmagic/
├── CMakeLists.txt
├── src/
│ ├── CppMagic.cpp
│ ├── FilePath.cpp
│ ├── FileSelector.cpp
│ ├── GenerateMode.cpp
│ ├── ... (other files)
│ ├── CppMagic.hpp
│ ├── FilePath.hpp
│ ├── FileSelector.hpp
│ ├── GenerateMode.hpp
│ └── ... (other headers)cppmagic sort src
By default, files won't be overwritted. You could use -i or --in-place flag to overwrite.
cppmagic sort -i src
- Functions will be generated for pure virtual functions and deleted constructor/destructor.
Contributions to cppmagic are welcome. Please follow these steps to contribute:
- Fork the Repository: Create a personal copy of the repository on GitHub.
- Create a Branch: Make a new branch for your changes:
git checkout -b feature/your-feature-name- Make Changes: Implement your changes and follow the existing code style.
- Push Changes: Push the branch to GitHub:
git push origin feature/your-feature-name- Create a Pull Request: Open a pull request on GitHub with details of the changes.
For support:
- GitHub Issues: Open an issue for questions or problems.
Thank you for contributing!