Generate code for pretty-printing C++ enums

enums

Generate code for pretty-printing C++ enums.

Supported platforms

Only Linux x86/x86_64 systems are supported.

For the missing platforms, the tool can be compiled from source. See here.

Download

Go to the latest release and:

  • download the attached gzipped file
  • gunzip it
  • make it executable: chmod +x enums

Optionally, if you want to install it, you can copy it somewhere in your PATH(e.g. /usr/local/bin).

Usage

Usage: enums [FLAGS] inputfile.[ch]pp enum_name1...enum_nameN

Flags:
    -h, --help             print this message
    --version              print version
    --namespace=value      add given namespace to the generated file
    --include-guard=value  add given include guard to the generated file

Examples

Let's say you have the following header(input.hpp) which contains the enum Foo:

#include <cstdint>

namespace test {
enum class Foo : uint32_t {
  a = 1,
  b,
  c,
  d,
  e,
};
}  // namespace test

Now you want to be able to print the string equivalent for a given enum literal for the Foo enum.

For Foo::a print "a", for Foo::b print "b" and so on.

You can use the enums tool to generate code that can be used to do exactly that.

There are two approaches:

Generate the code and include it into the original header

Here's how:

  • run the tool:
enums --namespace=test input.hpp Foo > input_generated.inc
  • include the generated code at the end of input.hpp:
#include <cstdint>

namespace test {
enum class Foo : uint32_t {
  a = 1,
  b,
  c,
};

#include "input_generated.inc"

}  // namespace test

Now, wherever you include the input.hpp header, you have access to the generated EnumNameFoo() function.

#include "input.hpp"

...

std::cout << EnumNameFoo(test::Foo::a) << std::endl;

This will print the string "a".

Generate the code as a standalone header

Here's how:

  • run the tool:
enums --namespace=test --include-guard=__INPUT_GENERATED_HPP__ input.hpp Foo > input_generated.hpp

Now, wherever you include the input.hpp header and if after it you include the input_generated.hpp header, you have access to the generated EnumNameFoo() function.

#include "input.hpp"
#include "input_generated.hpp"

...

std::cout << EnumNameFoo(test::Foo::a) << std::endl;

This will print the string "a".

Owner
Similar Resources

Juice the carrots from ウマ娘プリティーダービー (Umamusume Pretty Derby) - Windows implementation

Hooks the decryption function in libnative.dll of ウマ娘プリティーダービー (Umamusume Pretty Derby), to allow inspecting the packets (and provide some useful information during the game).

Dec 16, 2022

Pretty much the repo name sums it up.

Pretty much the repo name sums it up.

🧮 Console_Calculator Version Supported Date Ended Support v.1.0 ✔️ 🌳 Features The 🧮 Console_Calculator can do basic arithmatic, and yes there is no

Dec 31, 2021

its a pretty dodo 0.1% os

Dodo OS why did i make this os? idk im bored and i wanted to learn alot of new stuff. so i decided to make dodo os. i will see for how far i will go i

Jan 4, 2022

C parsing, semantic analys, generate a graph from a source code. An educational project during my third year of Computer Science Licence.

Pour compiler le programme, il suffit d'exécuter compiler.sh avec la commande "./compiler.sh" en se trouvant dans le dossier racine du projet. Un fich

Feb 3, 2022

Matryoshka loader is a tool that red team operators can leverage to generate shellcode for Microsoft Office document phishing payloads.

Overview Matryoshka loader is a tool that red team operators can leverage to generate shellcode for an egghunter to bypass size-limitations and perfor

Dec 15, 2022

Generate and Install NDS Forwarders

NDSForwarder This app will create nds forwarders and install them to the home screen of the 3ds. The forwarders created with this app work in conjunct

Jan 3, 2023

LLpatch: Userspace tool to generate Linux kernel livepatch

LLpatch: LLVM-based Kernel Livepatch Generation LLpatch generates, from a source patch, a kernel loadable module or binary package, that can update Li

Nov 30, 2022

Generate huge load-avg

Loadavg-generator Will create a lot of threads, limited to 2 CPUs to avoid hanging the system. Code is avoiding pthread to avoid eating too much memor

Jul 6, 2022

Generate dense random crosswords

CrosswordGenerator crossword_gen is a program written in C allowing to generate random crosswords from a list of words. The following parameters are e

Oct 31, 2021
Dec 29, 2022
Tiny header-only library providing bitwise operators for enums in C++11

bitflags Tiny header-only library providing bitwise operators for enums in C++11. Getting started Import the operators from namespace avakar::bitflags

Aug 28, 2022
Pattern Printing For beginners!

Patterns Project on Patterns Installation Download the source files and compile it. Linux g++ main.cpp -o patterns.out ./patterns.out Windows g++ mai

Oct 17, 2021
Creates 3D lithophanes from image files, exports them to stl files, ready for slicing and 3D printing.

LithoMaker Creates 3D lithophanes from PNG image files and exports them to STL files, ready for slicing and 3D printing. Download the latest release h

Dec 24, 2022
MKS TinyBee is a mainboard for 3d printing, based on ESP32 module
MKS TinyBee is a mainboard for 3d printing, based on ESP32 module

MKS-TinyBee MKS TinyBee is a mainboard for 3d printing, based on ESP32 module. Support Marlin2.0 firmware, in addition to ordinary LCD2004, 12864 scre

Dec 20, 2022
Converter for X3's .bod files to OBJs for 3D printing

Quick and dirty tool to convert X3 .bod files to OBJ for 3D printing. No, really, it is probably the worst code I've ever written. Don't judge me on t

Jan 9, 2022
PRINT++ is a simple, open source print library for C++, the main usage of PRINT++ is printing out "log" messages
PRINT++ is a simple, open source print library for C++, the main usage of PRINT++ is printing out

note that for now, print++ is using std::cout. In future it will be using own print function. Windows version can be unstable That library is in alpha

Jan 23, 2022
Pretty Printer for Modern C++
Pretty Printer for Modern C++

Highlights Single header file Requires C++17 MIT License Quick Start Simply include pprint.hpp and you're good to go. #include <pprint.hpp> To start p

Dec 22, 2022
Localify "ウマ娘: Pretty Derby" DMM client

中文 赛马娘 (DMM版) 本地化补丁 使用方法: 将 version.dll 和 config.json 以及 config.json 中引用的字典放置于 umamusume.exe 边上 启动游戏 设置选项: enableConsole 启用用来输出调试信息的控制台 (true/false) e

Dec 30, 2022