PIP 5.6.1
Platform-Independent Primitives
Code generation

Introduction

Code generation helps when you need string representation of entities (classes, enums, etc.) or automated serialization/deserialization of structures and classes. For example, you may need a list of "name" = "value" pairs from an enumeration for a UI, or to traverse nested structures with metadata. You can describe a structure of any complexity, assign field IDs, and get ready-made operators for PIBinaryStream with versioning and backward compatibility.

pip_cmg

PIP provides the pip_cmg utility: it takes source files, include paths, and options, and produces a .h/.cpp pair. Depending on options, the output may include: entity metadata; serialization operators; and the ability to get a PIVariant for any member by name.

Processing options: -s (do not follow #include); -I<include_dir> (add include path); -D<define> (add macro; PICODE is always defined).

Creation options: -A (create all); -M (metadata); -E (enums); -S (serialization operators); -G (get value by name); -o <output_file> (output base name without extension).

CMake

The pip_code_model CMake macro invokes pip_cmg and keeps the model up to date. Call format: pip_code_model(<out_var> file0 [file1 ...] [OPTIONS ...] [NAME name]). Parameters: out_var receives generated file paths; file... are sources; OPTIONS are passed to pip_cmg (e.g. "-Es"); NAME sets the model file base (default "ccm_${PROJECT_NAME}"). The macro adds PIP include paths. Run pip_cmg -v for current options.

Details

Metadata: attach PIMETA(...) to types, members or enums; read at runtime via PICODEINFO::classes() and PICODEINFO::enums(). Serialization: struct-level PIMETA(simple-stream) or PIMETA(no-stream), or per-member chunk ids (default); see Chunk stream and versioned serialization. Add the generated .h/.cpp to your target and #include the generated header; metadata loads before main().