FDL Core Library
ASC Framing Decision List — C/C++ Reference Implementation
Loading...
Searching...
No Matches
Functions
fdl_collection_helpers.h File Reference

Template helpers for collection traversal (count, at, find_by_field). More...

#include "fdl_doc.h"
#include <cstdint>
#include <memory>
#include <string_view>

Go to the source code of this file.

Functions

uint32_t fdl::detail::root_collection_count (fdl_doc_t *doc, const char *key)
 Count elements in a root-level collection array.
 
template<typename HandleT , typename MakeHandleFn , typename GetCacheFn >
HandleT * fdl::detail::root_collection_at (fdl_doc_t *doc, const char *key, uint32_t index, MakeHandleFn make_handle, GetCacheFn get_cache)
 Access an element by index in a root-level collection, with handle deduplication.
 
template<typename HandleT , typename MakeHandleFn , typename GetCacheFn >
HandleT * fdl::detail::root_collection_find (fdl_doc_t *doc, const char *array_key, const char *field_key, const char *target, MakeHandleFn make_handle, GetCacheFn get_cache)
 Find an element by a string field in a root-level collection.
 
uint32_t fdl::detail::child_collection_count (const jsoncons::ojson *parent_node, const char *key)
 Count elements in a child collection accessed via a parent node.
 
template<typename HandleT , typename KeyT , typename MakeHandleFn , typename GetCacheFn >
HandleT * fdl::detail::child_collection_at (const jsoncons::ojson *parent_node, const char *key, uint32_t index, KeyT dedup_key, MakeHandleFn make_handle, GetCacheFn get_cache)
 Access an element by index in a child collection, with handle deduplication.
 
template<typename HandleT , typename MakeKeyFn , typename MakeHandleFn , typename GetCacheFn >
HandleT * fdl::detail::child_collection_find (const jsoncons::ojson *parent_node, const char *array_key, const char *field_key, const char *target, MakeKeyFn make_key, MakeHandleFn make_handle, GetCacheFn get_cache)
 Find an element by a string field in a child collection.
 

Detailed Description

Template helpers for collection traversal (count, at, find_by_field).

These templates eliminate duplication across the 5 collection types (framing_intents, contexts, canvas_templates, canvases, framing_decisions). Each template is parameterized by:

The doc_lock must already be held by the caller.

Function Documentation

◆ root_collection_count()

uint32_t fdl::detail::root_collection_count ( fdl_doc_t doc,
const char *  key 
)
inline

Count elements in a root-level collection array.

Caller must hold the document lock.

Parameters
docDocument handle.
keyJSON key for the root-level array (e.g., "contexts").
Returns
Number of elements, or 0 if absent.

◆ root_collection_at()

template<typename HandleT , typename MakeHandleFn , typename GetCacheFn >
HandleT * fdl::detail::root_collection_at ( fdl_doc_t doc,
const char *  key,
uint32_t  index,
MakeHandleFn  make_handle,
GetCacheFn  get_cache 
)

Access an element by index in a root-level collection, with handle deduplication.

Caller must hold the document lock.

Template Parameters
HandleTHandle struct type.
MakeHandleFnCallable: (fdl_doc_t*, uint32_t) -> std::unique_ptr<HandleT>.
GetCacheFnCallable: (fdl_doc_t*) -> std::pair<vector<unique_ptr<HandleT>>&, map<KeyT,HandleT*>&>.
Parameters
docDocument handle.
keyJSON key for the root-level array.
indexElement index.
make_handleFactory for creating new handles.
get_cacheAccessor for ownership vector and dedup map.
Returns
Handle pointer, or nullptr if out of bounds.

◆ root_collection_find()

template<typename HandleT , typename MakeHandleFn , typename GetCacheFn >
HandleT * fdl::detail::root_collection_find ( fdl_doc_t doc,
const char *  array_key,
const char *  field_key,
const char *  target,
MakeHandleFn  make_handle,
GetCacheFn  get_cache 
)

Find an element by a string field in a root-level collection.

Performs a linear scan of the array, matching on the given field. Caller must hold the document lock.

Template Parameters
HandleTHandle struct type.
MakeHandleFnCallable: (fdl_doc_t*, uint32_t) -> std::unique_ptr<HandleT>.
GetCacheFnCallable: (fdl_doc_t*) -> std::pair<vector<unique_ptr<HandleT>>&, map<KeyT,HandleT*>&>.
Parameters
docDocument handle.
array_keyJSON key for the root-level array.
field_keyJSON key within each element to match against.
targetValue to search for.
make_handleFactory for creating new handles.
get_cacheAccessor for ownership vector and dedup map.
Returns
Handle pointer, or nullptr if not found.

◆ child_collection_count()

uint32_t fdl::detail::child_collection_count ( const jsoncons::ojson *  parent_node,
const char *  key 
)
inline

Count elements in a child collection accessed via a parent node.

Caller must hold the document lock.

Parameters
parent_nodeResolved parent JSON node (e.g., context node).
keyJSON key for the child array (e.g., "canvases").
Returns
Number of elements, or 0 if absent.

◆ child_collection_at()

template<typename HandleT , typename KeyT , typename MakeHandleFn , typename GetCacheFn >
HandleT * fdl::detail::child_collection_at ( const jsoncons::ojson *  parent_node,
const char *  key,
uint32_t  index,
KeyT  dedup_key,
MakeHandleFn  make_handle,
GetCacheFn  get_cache 
)

Access an element by index in a child collection, with handle deduplication.

Caller must hold the document lock.

Template Parameters
HandleTHandle struct type.
KeyTDedup map key type (uint64_t for packed keys).
MakeHandleFnCallable: (uint32_t) -> std::unique_ptr<HandleT>.
GetCacheFnCallable: () -> std::pair<vector<unique_ptr<HandleT>>&, map<KeyT,HandleT*>&>.
Parameters
parent_nodeResolved parent JSON node.
keyJSON key for the child array.
indexElement index.
dedup_keyPacked key for dedup map lookup.
make_handleFactory for creating new handles.
get_cacheAccessor for ownership vector and dedup map.
Returns
Handle pointer, or nullptr if out of bounds.

◆ child_collection_find()

template<typename HandleT , typename MakeKeyFn , typename MakeHandleFn , typename GetCacheFn >
HandleT * fdl::detail::child_collection_find ( const jsoncons::ojson *  parent_node,
const char *  array_key,
const char *  field_key,
const char *  target,
MakeKeyFn  make_key,
MakeHandleFn  make_handle,
GetCacheFn  get_cache 
)

Find an element by a string field in a child collection.

Caller must hold the document lock.

Template Parameters
HandleTHandle struct type.
MakeKeyFnCallable: (uint32_t) -> KeyT. Computes dedup key from index.
MakeHandleFnCallable: (uint32_t) -> std::unique_ptr<HandleT>.
GetCacheFnCallable: () -> std::pair<vector<unique_ptr<HandleT>>&, map<KeyT,HandleT*>&>.
Parameters
parent_nodeResolved parent JSON node.
array_keyJSON key for the child array.
field_keyJSON key within each element to match against.
targetValue to search for.
make_keyKey factory for dedup map.
make_handleHandle factory.
get_cacheAccessor for ownership vector and dedup map.
Returns
Handle pointer, or nullptr if not found.