GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_common.h File Reference

Common macros. More...

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <stddef.h>
#include <core/gp_compiler.h>

Go to the source code of this file.

Macros

#define GP_MIN(a, b)
 Returns a minimum of the two numbers.
 
#define GP_MIN3(a, b, c)
 Returns a minimum of the three numbers.
 
#define GP_MAX(a, b)
 Returns a maximum of the two numbers.
 
#define GP_MAX3(a, b, c)
 Returns a maximum of the three numbers.
 
#define GP_CONCAT2(a, b)
 A macro to concatenate two strings.
 
#define GP_UNIQUE_ID(prefix)
 Generates an unique C identifier with a given prefix.
 
#define GP_ABS(a)
 Returns an absolute value.
 
#define GP_ABS_DIFF(a, b)
 Computes an absolute value of a difference.
 
#define GP_ALIGN2(a)
 Aligns a value to be even.
 
#define GP_SWAP(a, b)
 Swaps a and b.
 
#define GP_ARRAY_SIZE(array)
 Computes number of elements of a statically defined array size.
 
#define GP_CONTAINER_OF(ptr, structure, member)
 Converts from a pointer to a struct field to a pointer to the struct itself.
 

Detailed Description

Common macros.

Definition in file gp_common.h.

Macro Definition Documentation

◆ GP_ABS

#define GP_ABS ( a)
Value:
({ \
typeof(a) gp_a_tmp = a; \
gp_a_tmp > 0 ? gp_a_tmp : - gp_a_tmp; \
})

Returns an absolute value.

Parameters
aA number.
Returns
An absolute value of a.

Definition at line 110 of file gp_common.h.

◆ GP_ABS_DIFF

#define GP_ABS_DIFF ( a,
b )
Value:
({ \
typeof(a) gp_a_tmp = a; \
typeof(b) gp_b_tmp = b; \
gp_a_tmp > gp_b_tmp ? gp_a_tmp - gp_b_tmp : gp_b_tmp - gp_a_tmp; \
})

Computes an absolute value of a difference.

Parameters
aA number.
bA number.
Returns
An absolute value of a difference between a and b.

Definition at line 123 of file gp_common.h.

◆ GP_ALIGN2

#define GP_ALIGN2 ( a)
Value:
({ \
typeof(a) gp_a_tmp = a; \
gp_a_tmp + (gp_a_tmp%2); \
})

Aligns a value to be even.

Parameters
aAn integer number.
Returns
A value aligned to be divisible by two.

Definition at line 135 of file gp_common.h.

◆ GP_ARRAY_SIZE

#define GP_ARRAY_SIZE ( array)
Value:
(sizeof(array) / sizeof(*array))

Computes number of elements of a statically defined array size.

Parameters
arrayAn array.
Returns
A number of array elements.

Definition at line 168 of file gp_common.h.

◆ GP_CONCAT2

#define GP_CONCAT2 ( a,
b )
Value:
a##b

A macro to concatenate two strings.

Parameters
aA string constant.
bA string constant.
Returns
A concatenated string.

Definition at line 88 of file gp_common.h.

◆ GP_CONTAINER_OF

#define GP_CONTAINER_OF ( ptr,
structure,
member )
Value:
((structure *)((char *)(ptr) - offsetof(structure, member)))

Converts from a pointer to a struct field to a pointer to the struct itself.

The inverse functions is part of the C language and is called offsetof().

Parameters
ptrA pointer to a structure member.
structureA structure C type e.g. struct foo.
memberA structure member name.

Definition at line 180 of file gp_common.h.

◆ GP_MAX

#define GP_MAX ( a,
b )
Value:
({ \
typeof(a) gp_a_tmp = (a); \
typeof(b) gp_b_tmp = (b); \
gp_a_tmp > gp_b_tmp ? gp_a_tmp : gp_b_tmp; \
})

Returns a maximum of the two numbers.

Parameters
aA number.
bA number.
Returns
A maximum of a and b.

Definition at line 59 of file gp_common.h.

Referenced by gp_bbox_intersection(), and gp_bbox_merge().

◆ GP_MAX3

#define GP_MAX3 ( a,
b,
c )
Value:
({ \
typeof(a) gp_a_tmp = (a); \
typeof(b) gp_b_tmp = (b); \
typeof(c) gp_c_tmp = (c); \
gp_a_tmp > gp_b_tmp ? (gp_a_tmp > gp_c_tmp ? gp_a_tmp : gp_c_tmp) : (gp_b_tmp > gp_c_tmp ? gp_b_tmp : gp_c_tmp); \
})

Returns a maximum of the three numbers.

Parameters
aA number.
bA number.
cA number.
Returns
A maximum of a, b and c.

Definition at line 73 of file gp_common.h.

◆ GP_MIN

#define GP_MIN ( a,
b )
Value:
({ \
typeof(a) gp_a_tmp = (a); \
typeof(b) gp_b_tmp = (b); \
gp_a_tmp < gp_b_tmp ? gp_a_tmp : gp_b_tmp; \
})

Returns a minimum of the two numbers.

Parameters
aA number.
bA number.
Returns
A minimum of a and b.

Definition at line 31 of file gp_common.h.

Referenced by gp_bbox_intersection(), and gp_bbox_merge().

◆ GP_MIN3

#define GP_MIN3 ( a,
b,
c )
Value:
({ \
typeof(a) gp_a_tmp = (a); \
typeof(b) gp_b_tmp = (b); \
typeof(c) gp_c_tmp = (c); \
gp_a_tmp < gp_b_tmp ? (gp_a_tmp < gp_c_tmp ? gp_a_tmp : gp_c_tmp) : (gp_b_tmp < gp_c_tmp ? gp_b_tmp : gp_c_tmp); \
})

Returns a minimum of the three numbers.

Parameters
aA number.
bA number.
cA number.
Returns
A minimum of a, b and c.

Definition at line 45 of file gp_common.h.

◆ GP_SWAP

#define GP_SWAP ( a,
b )
Value:
do { \
typeof(b) gp_b_tmp = b; \
b = a; \
a = gp_b_tmp; \
} while (0)

Swaps a and b.

Attention
Modifies the variables passed as parameters.
Parameters
aA value to be swapped.
bA value to be swapped.

Definition at line 148 of file gp_common.h.

◆ GP_UNIQUE_ID

#define GP_UNIQUE_ID ( prefix)
Value:
GP_UNIQUE_ID2(prefix, __COUNTER__)

Generates an unique C identifier with a given prefix.

This is intended to be used to generate an unique indentifier for functions or structures generated by macros.

Parameters
prefixA prefix for the unique ID.
Returns
An unique C identifier with a given prefix.

Definition at line 102 of file gp_common.h.