design_pattern_for_c  V 1.00
flyweight.h File Reference

This is API as Flyweight design petten. More...

#include <stddef.h>
#include "dp_util.h"
Include dependency graph for flyweight.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  flyweight_methods_t
 Flyweight methods interface definition, to set flyweight_factory_new. More...
 

Typedefs

typedef struct flyweight_methods_t flyweight_methods_t
 FlyweightMethodsInterface class definition, member is defined in flyweight_methods_t,. More...
 
typedef struct flyweight_methods_tFlyweightMethodsIF
 
typedef struct flyweight_factory_tFlyweightFactory
 FlyweightFactory definition. More...
 

Functions

FlyweightFactory flyweight_factory_new (size_t class_size, int is_threadsafe, FlyweightMethodsIF methods)
 define class for flyweight More...
 
void * flyweight_get (FlyweightFactory this, void *constructor_parameter)
 getter More...
 
int flyweight_set (FlyweightFactory this, void *constructor_parameter, void *data, int(*setter)(void *this, size_t size, void *input_parameter))
 setter More...
 
void flyweight_factory_free (FlyweightFactory this)
 clear class handle More...
 

Detailed Description

This is API as Flyweight design petten.

Definition in file flyweight.h.

Typedef Documentation

◆ flyweight_methods_t

FlyweightMethodsInterface class definition, member is defined in flyweight_methods_t,.

Definition at line 52 of file flyweight.h.

◆ FlyweightFactory

FlyweightFactory definition.

Definition at line 60 of file flyweight.h.

◆ FlyweightMethodsIF

Definition at line 52 of file flyweight.h.

Function Documentation

◆ flyweight_factory_free()

void flyweight_factory_free ( FlyweightFactory  this)

clear class handle

Parameters
[in]thisFlyweightFactory instance returned at flyweight_factory_new,
Returns
none

Definition at line 293 of file flyweight.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ flyweight_factory_new()

FlyweightFactory flyweight_factory_new ( size_t  class_size,
int  is_threadsafe,
FlyweightMethodsIF  methods 
)

define class for flyweight

Parameters
[in]class_sizesize of instance which defined in user side.
[in]is_threadsafeif !=0, ensure threadsafe to create new class instace, please set !=0 if you want to use this API on multi thread
[in]methodsfor generating class instance If NULL, use defautlt. If not NULL, override methods. override NULL, this method is no effect. destructor is called at free
Return values
!=NULLthis class handle
NULLerror

Definition at line 212 of file flyweight.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ flyweight_get()

void* flyweight_get ( FlyweightFactory  this,
void *  constructor_parameter 
)

getter

Parameters
[in]thisFlyweightFactory instance returned at flyweight_factory_new, first time to call get, allocate class, memset 0 and call constructor
[in]constructor_parameterconstructor parameter
Return values
!NULLclass instance
NULLid is invalid

Definition at line 244 of file flyweight.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ flyweight_set()

int flyweight_set ( FlyweightFactory  this,
void *  constructor_parameter,
void *  data,
int(*)(void *this, size_t size, void *input_parameter)  setter 
)

setter

Parameters
[in]thisFlyweightFactory instance returned at flyweight_factory_new,
[in]constructor_parameterconstructor parameter
[in]dataset data pointer
[in]settersetter if you want to change setter ( if NULL, use setter related to flyweight_register_class input)

Definition at line 264 of file flyweight.c.

Here is the call graph for this function:
Here is the caller graph for this function: