Getting started

Native example

This page shows the smallest native DIP workflow: register DIPL text, evaluate it, and read one known value.

#include <iostream>
#include <snt/dip/cursor.h>
#include <snt/dip/dip.h>

int main() {
    snt::dip::DIP parser;
    parser.add_string(
        "distance float = 12 m\n"
        "duration float = 3 s\n"
        "speed float = ({?distance} / {?duration}) m/s\n"
    );

    snt::dip::Environment env = parser.parse();
    std::cout << env["speed"].as<double>() << "\n";
    return 0;
}

parse() evaluates the declarations and returns an Environment. The known path speed is read through an environment cursor; its units and provenance remain available through the same cursor.

Build and run

Install the C++ package using Installation with the DIP module enabled. Save the example above as main.cpp and create this CMakeLists.txt in the same directory:

cmake_minimum_required(VERSION 3.22)
project(snt_dip_example LANGUAGES C CXX)

find_package(snt CONFIG REQUIRED)
add_executable(application main.cpp)
target_compile_features(application PRIVATE cxx_std_17)
target_link_libraries(application PRIVATE snt-dip)

Configure with the installed package prefix, build, and run:

cmake -S . -B build -DCMAKE_PREFIX_PATH=/path/to/snt
cmake --build build
./build/application

Expected output:

4

Replace /path/to/snt with the installation prefix; omit that option if CMake already finds SNT. C is enabled for discovery of HDF5 in packages built with DIP support. See Using SciNumTools from CMake for package discovery details.

Continue with Concepts and model for the core objects, Workflows for common task sequences, and Parsing and environments for source composition, cursors, schemas, and overrides.