design_pattern_for_c  V 1.00
prototype.h File Reference

This is API for Prototype design pattern. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  prototype_factory_method_t
 PrototypeFactory methods interface definition, to set prototype_register. More...
 

Macros

#define PROTOTYPE_SUCCESS   (0)
 
#define PROTOTYPE_FAILED   (-1)
 

Typedefs

typedef struct prototype_manager_tPrototypeManager
 PrototypeManager class definition, member is defined in prototype_manager_t. More...
 
typedef struct prototype_factory_tPrototypeFactory
 PrototypeFactory class definition, member is defined in prototype_factory_t. More...
 
typedef struct prototype_factory_method_t prototype_factory_method_t
 

Functions

PrototypeManager prototype_manager_new (int is_threadsafe)
 Create PrototypeManager class. More...
 
void prototype_manager_free (PrototypeManager this)
 free class handle More...
 
PrototypeFactory prototype_register (PrototypeManager this, void *base, size_t base_length, prototype_factory_method_t *factory_method)
 Register PrototypeFactory class. More...
 
void prototype_unregister (PrototypeManager this, PrototypeFactory factory)
 Unregister PrototypeFactory class. More...
 
void * prototype_clone (PrototypeFactory this)
 Clone base pointer by using PrototypeFactory class. More...
 
void prototype_free (PrototypeFactory this, void *cloned_data)
 Free cloned pointer. More...
 

Detailed Description

This is API for Prototype design pattern.

Definition in file prototype.h.

Macro Definition Documentation

◆ PROTOTYPE_FAILED

#define PROTOTYPE_FAILED   (-1)

Definition at line 23 of file prototype.h.

◆ PROTOTYPE_SUCCESS

#define PROTOTYPE_SUCCESS   (0)

Definition at line 22 of file prototype.h.

Typedef Documentation

◆ prototype_factory_method_t

Definition at line 54 of file prototype.h.

◆ PrototypeFactory

PrototypeFactory class definition, member is defined in prototype_factory_t.

Definition at line 20 of file prototype.h.

◆ PrototypeManager

PrototypeManager class definition, member is defined in prototype_manager_t.

Definition at line 13 of file prototype.h.

Function Documentation

◆ prototype_clone()

void* prototype_clone ( PrototypeFactory  this)

Clone base pointer by using PrototypeFactory class.

Parameters
[in]thisPrototypeFactory instance returned at prototype_register.
Returns
cloned data or NULL

Definition at line 114 of file prototype_manager.c.

Here is the call graph for this function:

◆ prototype_free()

void prototype_free ( PrototypeFactory  this,
void *  cloned_data 
)

Free cloned pointer.

Parameters
[in]thisPrototypeFactory instance returned at prototype_register.
[in]cloned_datafree data returned at prototype_clone.
Returns
none

Definition at line 126 of file prototype_manager.c.

Here is the call graph for this function:

◆ prototype_manager_free()

void prototype_manager_free ( PrototypeManager  this)

free class handle

Parameters
[in]thisPrototypeManager instance returned at prototype_manager_new,
Returns
none

Definition at line 55 of file prototype_manager.c.

Here is the call graph for this function:

◆ prototype_manager_new()

PrototypeManager prototype_manager_new ( int  is_threadsafe)

Create PrototypeManager class.

Parameters
[in]is_threadsafeif !=0, ensure threadsafe to create new class instace
Return values
!=NULLthis class handle
NULLerror

Definition at line 35 of file prototype_manager.c.

◆ prototype_register()

PrototypeFactory prototype_register ( PrototypeManager  this,
void *  base,
size_t  base_length,
prototype_factory_method_t factory_method 
)

Register PrototypeFactory class.

Parameters
[in]thisPrototypeManager instance returned at prototype_manager_new,
[in]basebase data.
[in]base_lengthbase data length
[in]factory_methodfactory method ( if NULL or member is NULL, use default. It's better to use free_basedata)
Return values
!NULLPrototypeFactory instance
NULLerror
Note
Please keep instance of base. This will free into prototype_unregister API by using free_basedata

Definition at line 74 of file prototype_manager.c.

Here is the call graph for this function:

◆ prototype_unregister()

void prototype_unregister ( PrototypeManager  this,
PrototypeFactory  factory 
)

Unregister PrototypeFactory class.

Parameters
[in]thisPrototypeManager instance returned at prototype_manager_new,
[in]factoryPrototypeFactory instance returned at prototype_register,
Returns
none

Definition at line 102 of file prototype_manager.c.

Here is the call graph for this function: