---
title: "ClikaRT::graph::Pattern"
sidebar_label: "Pattern"
description: "A graph of operator constraints to find in a ModelGraph. Move-only."
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--class">class</span>

**Header:** `ClikaRT/graph/pattern.h`

A graph of operator constraints to find in a [`ModelGraph`](./ModelGraph.md). Move-only.

## Types

### using NodeId {#NodeId}

<div class="api-signature">

`using` **`NodeId`** `=` `std::size_t`

</div>

The handle [`add_node`](./Pattern.md#add_node) returns: the node's position in [`add_node`](./Pattern.md#add_node) order, the index of its entry in [`Match::nodes`](./Match.md#nodes).

<div class="api-declared">

Declared in `ClikaRT/graph/pattern.h`, line 69

</div>

## Static member functions

### chain() {#chain}

<div class="api-signature">

`static` [`Pattern`](./Pattern.md) **`chain`**([`ClikaRT::Span`](../Span.md)`<const` [`OpCode`](./index.md#OpCode)`>` `codes`)

</div>

The straight line `codes[0] -> codes[1] -> ...`, each node feeding the next on any port, none optional.

<div class="api-declared">

Declared in `ClikaRT/graph/pattern.h`, line 115

</div>

## Member functions

### Pattern() {#Pattern}

<div class="api-signature">

**`Pattern`**()

</div>

An empty pattern; add nodes and edges to it.

<div class="api-declared">

Declared in `ClikaRT/graph/pattern.h`, line 72

</div>

### \~Pattern() {#Pattern-2}

<div class="api-signature">

**`~Pattern`**()

</div>

Releases the pattern.

<div class="api-declared">

Declared in `ClikaRT/graph/pattern.h`, line 74

</div>

### Pattern(Pattern) {#Pattern-3}

<div class="api-signature">

**`Pattern`**(`Pattern&&`) `noexcept`

</div>

Move-only: transfers the pattern.

<div class="api-declared">

Declared in `ClikaRT/graph/pattern.h`, line 76

</div>

### operator=(Pattern) {#operator-assign}

<div class="api-signature">

[`Pattern`](./Pattern.md)`&` **`operator=`**([`Pattern`](./Pattern.md)`&&`) `noexcept`

</div>

Move-assign: transfers the pattern.

<div class="api-declared">

Declared in `ClikaRT/graph/pattern.h`, line 78

</div>

### Pattern(Pattern) {#Pattern-4}

<div class="api-signature">

**`Pattern`**(`const Pattern&`) `=delete`

</div>

<div class="api-declared">

Declared in `ClikaRT/graph/pattern.h`, line 79

</div>

### operator=(Pattern) {#operator-assign-2}

<div class="api-signature">

[`Pattern`](./Pattern.md)`&` **`operator=`**(`const` [`Pattern`](./Pattern.md)`&`) `=delete`

</div>

<div class="api-declared">

Declared in `ClikaRT/graph/pattern.h`, line 80

</div>

### add\_node(OpCode, bool) {#add_node}

<div class="api-signature">

[`NodeId`](./Pattern.md#NodeId) **`add_node`**([`OpCode`](./index.md#OpCode) `code`, `bool` `optional` `=` `false`)

</div>

A pattern node that matches a graph node whose `op_code()` is `code`. The first node added is the root, and the root is always required: `optional` is honored on every later node, where it means the occurrence may lack the node (its [`Match`](./Match.md) entry is then `std::nullopt`, and the nodes feeding it are read as feeding what it feeds; do not add that bypass edge yourself). At most [`kMaxOptionalPatternNodes`](./index.md#kMaxOptionalPatternNodes) nodes may be optional; `find_pattern` refuses a pattern with more as [`Status::InvalidArgument`](../../index.md#Status).

<div class="api-declared">

Declared in `ClikaRT/graph/pattern.h`, line 90

</div>

### add\_node(Span\< OpCode\>, bool) {#add_node-2}

<div class="api-signature">

[`NodeId`](./Pattern.md#NodeId) **`add_node`**([`ClikaRT::Span`](../Span.md)`<const` [`OpCode`](./index.md#OpCode)`>` `alternatives`, `bool` `optional` `=` `false`)

</div>

A pattern node that matches a graph node whose `op_code()` is one of `alternatives`. An empty list matches no node.

<div class="api-declared">

Declared in `ClikaRT/graph/pattern.h`, line 93

</div>

### add\_node(NodePredicate, bool) {#add_node-3}

<div class="api-signature">

[`NodeId`](./Pattern.md#NodeId) **`add_node`**([`NodePredicate`](./index.md#NodePredicate) `predicate`, `bool` `optional` `=` `false`)

</div>

A pattern node that matches every graph node `predicate` accepts. The predicate runs inside the search, throw-contained: a throw ends the search and `find_pattern` returns the failure. An empty predicate is refused when the pattern is used (`find_pattern`, [`transforms::rewrite`](./transforms/index.md#rewrite)) as [`Status::InvalidArgument`](../../index.md#Status), naming the node.

<div class="api-declared">

Declared in `ClikaRT/graph/pattern.h`, line 99

</div>

### add\_edge() {#add_edge}

<div class="api-signature">

`void` **`add_edge`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`NodeId`](./Pattern.md#NodeId) `from`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`NodeId`](./Pattern.md#NodeId) `to`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<int>` `from_port` `=` `std::nullopt`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<int>` `to_port` `=` `std::nullopt`<br />
)

</div>

The output of pattern node `from` feeds an input of pattern node `to`. With a port given, on exactly that port: `from_port` is the output port of `from`, `to_port` the input port of `to`; without, any port. Spell the edges of the full line only: an edge that bypasses an optional node is the search's own when that node is absent, and named explicitly it demands a direct edge the full line does not have. An id that names no node is reported by `find_pattern` as [`Status::InvalidArgument`](../../index.md#Status).

<div class="api-declared">

Declared in `ClikaRT/graph/pattern.h`, line 110

</div>

### size() {#size}

<div class="api-signature">

`std::size_t` **`size`**() `const noexcept`

</div>

How many pattern nodes were added.

<div class="api-declared">

Declared in `ClikaRT/graph/pattern.h`, line 118

</div>
