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

Shared implementation of custom attribute operations on ojson nodes. More...

#include "fdl_custom_attr.h"
#include <functional>
#include <string>
#include <unordered_map>
#include "fdl_tl_cache.h"

Functions

std::string fdl::detail::custom_attr::make_key (const char *name)
 Build the internal key by prepending '_' to the user-visible name.
 
bool fdl::detail::custom_attr::has (const ojson *node, const char *name)
 Check if a custom attribute exists on a node.
 
fdl_custom_attr_type_t fdl::detail::custom_attr::get_type (const ojson *node, const char *name)
 Get the type of a custom attribute.
 
int fdl::detail::custom_attr::set_string (ojson *node, const char *name, const char *value)
 Set a string custom attribute.
 
int fdl::detail::custom_attr::set_int (ojson *node, const char *name, int64_t value)
 Set an integer custom attribute.
 
int fdl::detail::custom_attr::set_float (ojson *node, const char *name, double value)
 Set a floating-point custom attribute.
 
int fdl::detail::custom_attr::set_bool (ojson *node, const char *name, int value)
 Set a boolean custom attribute.
 
int fdl::detail::custom_attr::set_point_f64 (ojson *node, const char *name, double x, double y)
 Set a point_f64 custom attribute.
 
int fdl::detail::custom_attr::set_dims_f64 (ojson *node, const char *name, double width, double height)
 Set a dims_f64 custom attribute.
 
int fdl::detail::custom_attr::set_dims_i64 (ojson *node, const char *name, int64_t width, int64_t height)
 Set a dims_i64 custom attribute.
 
const char * fdl::detail::custom_attr::get_string (const ojson *node, const char *name)
 Get a string custom attribute.
 
int fdl::detail::custom_attr::get_int (const ojson *node, const char *name, int64_t *out)
 Get an integer custom attribute.
 
int fdl::detail::custom_attr::get_float (const ojson *node, const char *name, double *out)
 Get a floating-point custom attribute.
 
int fdl::detail::custom_attr::get_bool (const ojson *node, const char *name, int *out)
 Get a boolean custom attribute.
 
int fdl::detail::custom_attr::get_point_f64 (const ojson *node, const char *name, double *x, double *y)
 Get a point_f64 custom attribute.
 
int fdl::detail::custom_attr::get_dims_f64 (const ojson *node, const char *name, double *width, double *height)
 Get a dims_f64 custom attribute.
 
int fdl::detail::custom_attr::get_dims_i64 (const ojson *node, const char *name, int64_t *width, int64_t *height)
 Get a dims_i64 custom attribute.
 
int fdl::detail::custom_attr::remove (ojson *node, const char *name)
 Remove a custom attribute.
 
uint32_t fdl::detail::custom_attr::count (const ojson *node)
 Count the number of custom attributes on a node.
 
const char * fdl::detail::custom_attr::name_at (const ojson *node, uint32_t index)
 Get the name of a custom attribute by index.
 

Detailed Description

Shared implementation of custom attribute operations on ojson nodes.

All functions expect the caller to hold the document mutex. String returns use thread-local buffers keyed by (node address, attribute name) to avoid heap allocation per call, following the pattern in fdl_accessors_api.cpp.

Function Documentation

◆ make_key()

std::string fdl::detail::custom_attr::make_key ( const char *  name)

Build the internal key by prepending '_' to the user-visible name.

Parameters
nameUser-visible attribute name (without '_' prefix).
Returns
Internal key string (e.g., "_vendor" for "vendor").

◆ has()

bool fdl::detail::custom_attr::has ( const ojson node,
const char *  name 
)

Check if a custom attribute exists on a node.

Parameters
nodeTarget JSON node.
nameUser-visible attribute name.
Returns
True if the '_'-prefixed key exists.

◆ get_type()

fdl_custom_attr_type_t fdl::detail::custom_attr::get_type ( const ojson node,
const char *  name 
)

Get the type of a custom attribute.

Parameters
nodeTarget JSON node.
nameUser-visible attribute name.
Returns
One of FDL_CUSTOM_ATTR_TYPE_* constants.

◆ set_string()

int fdl::detail::custom_attr::set_string ( ojson node,
const char *  name,
const char *  value 
)

Set a string custom attribute.

Fails if the key exists with a different type.

Parameters
nodeTarget JSON node.
nameUser-visible attribute name.
valueString value to set.
Returns
0 on success, -1 on type mismatch.

◆ set_int()

int fdl::detail::custom_attr::set_int ( ojson node,
const char *  name,
int64_t  value 
)

Set an integer custom attribute.

Fails if the key exists with a different type.

Parameters
nodeTarget JSON node.
nameUser-visible attribute name.
valueInteger value to set.
Returns
0 on success, -1 on type mismatch.

◆ set_float()

int fdl::detail::custom_attr::set_float ( ojson node,
const char *  name,
double  value 
)

Set a floating-point custom attribute.

Fails if the key exists with a different type.

Parameters
nodeTarget JSON node.
nameUser-visible attribute name.
valueDouble value to set.
Returns
0 on success, -1 on type mismatch.

◆ set_bool()

int fdl::detail::custom_attr::set_bool ( ojson node,
const char *  name,
int  value 
)

Set a boolean custom attribute.

Fails if the key exists with a different type.

Parameters
nodeTarget JSON node.
nameUser-visible attribute name.
valueBoolean value (non-zero = true, zero = false).
Returns
0 on success, -1 on type mismatch.

◆ set_point_f64()

int fdl::detail::custom_attr::set_point_f64 ( ojson node,
const char *  name,
double  x,
double  y 
)

Set a point_f64 custom attribute.

Fails if the key exists with a different type.

Parameters
nodeTarget JSON node.
nameUser-visible attribute name.
xX coordinate.
yY coordinate.
Returns
0 on success, -1 on type mismatch.

◆ set_dims_f64()

int fdl::detail::custom_attr::set_dims_f64 ( ojson node,
const char *  name,
double  width,
double  height 
)

Set a dims_f64 custom attribute.

Fails if the key exists with a different type.

Parameters
nodeTarget JSON node.
nameUser-visible attribute name.
widthWidth value.
heightHeight value.
Returns
0 on success, -1 on type mismatch.

◆ set_dims_i64()

int fdl::detail::custom_attr::set_dims_i64 ( ojson node,
const char *  name,
int64_t  width,
int64_t  height 
)

Set a dims_i64 custom attribute.

Fails if the key exists with a different type.

Parameters
nodeTarget JSON node.
nameUser-visible attribute name.
widthWidth value.
heightHeight value.
Returns
0 on success, -1 on type mismatch.

◆ get_string()

const char * fdl::detail::custom_attr::get_string ( const ojson node,
const char *  name 
)

Get a string custom attribute.

Parameters
nodeTarget JSON node.
nameUser-visible attribute name.
Returns
Thread-local C string pointer, or nullptr if absent or wrong type.

◆ get_int()

int fdl::detail::custom_attr::get_int ( const ojson node,
const char *  name,
int64_t *  out 
)

Get an integer custom attribute.

Parameters
nodeTarget JSON node.
nameUser-visible attribute name.
outOutput pointer for the integer value.
Returns
0 on success, -1 if absent or wrong type.

◆ get_float()

int fdl::detail::custom_attr::get_float ( const ojson node,
const char *  name,
double *  out 
)

Get a floating-point custom attribute.

Parameters
nodeTarget JSON node.
nameUser-visible attribute name.
outOutput pointer for the double value.
Returns
0 on success, -1 if absent or wrong type.

◆ get_bool()

int fdl::detail::custom_attr::get_bool ( const ojson node,
const char *  name,
int *  out 
)

Get a boolean custom attribute.

Parameters
nodeTarget JSON node.
nameUser-visible attribute name.
outOutput pointer for the boolean value (FDL_TRUE or FDL_FALSE).
Returns
0 on success, -1 if absent or wrong type.

◆ get_point_f64()

int fdl::detail::custom_attr::get_point_f64 ( const ojson node,
const char *  name,
double *  x,
double *  y 
)

Get a point_f64 custom attribute.

Parameters
nodeTarget JSON node.
nameUser-visible attribute name.
xOutput pointer for X coordinate.
yOutput pointer for Y coordinate.
Returns
0 on success, -1 if absent or wrong type.

◆ get_dims_f64()

int fdl::detail::custom_attr::get_dims_f64 ( const ojson node,
const char *  name,
double *  width,
double *  height 
)

Get a dims_f64 custom attribute.

Parameters
nodeTarget JSON node.
nameUser-visible attribute name.
widthOutput pointer for width.
heightOutput pointer for height.
Returns
0 on success, -1 if absent or wrong type.

◆ get_dims_i64()

int fdl::detail::custom_attr::get_dims_i64 ( const ojson node,
const char *  name,
int64_t *  width,
int64_t *  height 
)

Get a dims_i64 custom attribute.

Parameters
nodeTarget JSON node.
nameUser-visible attribute name.
widthOutput pointer for width.
heightOutput pointer for height.
Returns
0 on success, -1 if absent or wrong type.

◆ remove()

int fdl::detail::custom_attr::remove ( ojson node,
const char *  name 
)

Remove a custom attribute.

Parameters
nodeTarget JSON node.
nameUser-visible attribute name.
Returns
0 if removed, -1 if not found.

◆ count()

uint32_t fdl::detail::custom_attr::count ( const ojson node)

Count the number of custom attributes on a node.

Parameters
nodeTarget JSON node.
Returns
Number of '_'-prefixed keys.

◆ name_at()

const char * fdl::detail::custom_attr::name_at ( const ojson node,
uint32_t  index 
)

Get the name of a custom attribute by index.

Returns names without the '_' prefix. The index refers to the order among custom attributes only (not all keys).

Parameters
nodeTarget JSON node.
indexZero-based index among custom attributes.
Returns
Thread-local C string pointer, or nullptr if index is out of range.