Loading...
Searching...
No Matches
comps_obj.h File Reference

COMPS_Object header file. More...

`#include "comps_mm.h"`

Go to the source code of this file.

## Data Structures

struct | COMPS_ObjectInfo
struct | COMPS_Object
struct | COMPS_Num
struct | COMPS_Str

## Macros

#define | COMPS_OBJECT_CREATE(objtype, args)
| macro for create object by choosen type without explicit needs of typecast. Macro returns concrete type of object not COMPS_Object type. If you want use this macro, you have to declare COMPS_ObjectInfo object exactly as <YourObject>_ObjInfo
#define | COMPS_OBJECT_CMP(obj1, obj2)
| macro for compare two COMPS_Object derivates without typecasting to COMPS_Object pointer
#define | COMPS_OBJECT_DESTROY(obj1)
| macro for call comps_object_destroy without typecasting to COMPS_Object pointer
#define | COMPS_OBJECT_COPY(obj)
| macro for call comps_object_copy without typecasting to COMPS_Object pointer
#define | COMPS_Object_HEAD
#define | COMPS_Object_TAIL(obj)
| insert "extern COMPS_ObjectInfo <obj>_ObjInfo" statement. Use this macro in combination with COMPS_OBJECT_CREATE

## Functions

COMPS_Object * | comps_object_create (COMPS_ObjectInfo *obj_info, COMPS_Object **args)
void | comps_object_destroy (COMPS_Object *comps_obj)
COMPS_Object * | comps_object_copy (COMPS_Object *comps_obj)
signed char | comps_object_cmp (COMPS_Object *obj1, COMPS_Object *obj2)
char * | comps_object_tostr (COMPS_Object *obj1)
COMPS_Object * | comps_object_incref (COMPS_Object *obj)
COMPS_Num * | comps_num (int n)
COMPS_Str * | comps_str (const char *s)
COMPS_Str * | comps_str_x (char *s)
void | comps_str_set (COMPS_Str *str, char *s)
signed char | comps_str_fnmatch (COMPS_Str *str, char *pattern, int flags)
signed char | comps_str_fnmatch_o (COMPS_Str *str, COMPS_Str *pattern, int flags)

## Detailed Description

COMPS_Object header file.

## Macro Definition Documentation

## COMPS_OBJECT_CREATE

#define COMPS_OBJECT_CREATE | ( |  | objtype,
|  |  | args )

Value:
(objtype*)comps_object_create(&objtype##_ObjInfo, args)
comps_object_create
COMPS_Object * comps_object_create(COMPS_ObjectInfo *obj_info, COMPS_Object **args)

macro for create object by choosen type without explicit needs of typecast. Macro returns concrete type of object not COMPS_Object type. If you want use this macro, you have to declare COMPS_ObjectInfo object exactly as <YourObject>_ObjInfo

See also
  COMPS_Object_TAIL

## COMPS_Object_HEAD

#define COMPS_Object_HEAD

Value:
COMPS_RefC *refc;\
COMPS_ObjectInfo *obj_info
COMPS_ObjectInfo
Definition comps_obj.h:102
COMPS_RefC
Definition comps_mm.h:36

ensure that COMPS_Object derivate has need struct members for properly behaviour

## COMPS_Object_TAIL

#define COMPS_Object_TAIL | ( |  | obj | ) |

Value:
extern COMPS_ObjectInfo obj##_ObjInfo

insert "extern COMPS_ObjectInfo <obj>_ObjInfo" statement. Use this macro in combination with COMPS_OBJECT_CREATE

See also
  COMPS_OBJECT_CREATE

## Function Documentation

## comps_num()

COMPS_Num * comps_num | ( | int | n | ) |

Directly construct COMPS_Num derivate from passed argument

Parameters

  n | value of COMPS_Num

## comps_object_cmp()

signed char comps_object_cmp | ( | COMPS_Object * | obj1,
|  | COMPS_Object * | obj2 )

Compare two COMPS_Object derivates and return non-zero value if equals

Warning
  Function doen't check equality of derivate types (COMPS_ObjectInfo)!!

Parameters

  obj1 | first derivate
  obj2 | second derivate

Returns
  non-zero value if equals, zero otherwise

## comps_object_copy()

COMPS_Object * comps_object_copy | ( | COMPS_Object * | comps_obj | ) |

Return whole new copy of COMPS_Object derivate.

Function create new allocation of derivate and call obj_copy callback with old instance and new instance of derivate. Copying inner structure members are in programmers care

Parameters

  comps_obj | derivate object want to be copied

Returns
  new copy of derivate object

See also
  COMPS_ObjectInfo

## comps_object_create()

COMPS_Object * comps_object_create | ( | COMPS_ObjectInfo * | obj_info,
|  | COMPS_Object ** | args )

Create COMPS_Object derivate and pass args arguments to its constructor

Parameters

  obj_info | pointer to COMPS_ObjectInfo structure
  args | array of arguments passed to derivate constructor. Array doesn't have to end with NULL sentinel. Processing args attribute passed to contructor is completely in programmer's care

Returns
  COMPS_Object derivate typecasted as general COMPS_Object

## comps_object_destroy()

void comps_object_destroy | ( | COMPS_Object * | comps_obj | ) |

Destroy passed COMPS_Object derivate if its reference counter is zero if not, only decrement reference counter

## comps_object_incref()

COMPS_Object * comps_object_incref | ( | COMPS_Object * | obj | ) |

Increment COMPS_Object derivate reference counter

## comps_object_tostr()

char * comps_object_tostr | ( | COMPS_Object * | obj1 | ) |

Return string representation of COMPS_Object derivate

Warning
  Returned string is new allocation which needs to be freed manualy

Parameters

  obj1 | COMPS_Object derivate

Returns
  new alllocation of string representation of concrete object

## comps_str()

COMPS_Str * comps_str | ( | const char * | s | ) |

Directly construct COMPS_Str derivate from passed argument

passed argument is copied as new allocation

Parameters

  s | string value of derivate

## comps_str_fnmatch()

signed char comps_str_fnmatch | ( | COMPS_Str * | str,
|  | char * | pattern,
|  | int | flags )

Return non-zero if str match the pattern by fnmatch

Parameters

  str | source string. COMPS_Str object
  pattern | match pattern

## comps_str_fnmatch_o()

signed char comps_str_fnmatch_o | ( | COMPS_Str * | str,
|  | COMPS_Str * | pattern,
|  | int | flags )

Return non-zero if str match the pattern by fnmatch

Parameters

  str | source string. COMPS_Str object
  pattern | COMPS_Str match pattern

## comps_str_set()

void comps_str_set | ( | COMPS_Str * | str,
|  | char * | s )

Set memory copy of passed argument as COMPS_Str value

Parameters

  str | COMPS_Str object
  s | desired new COMPS_Str object value

## comps_str_x()

COMPS_Str * comps_str_x | ( | char * | s | ) |

Directly construct COMPS_Str derivate from passed argument

Warning
  passed argument is not copied. COMPS_Str derivate use same memory place as s argument and during destruction of derivate this memory place is freed

Parameters

  s | string value of derivate