Implement of Flyweight design petten library API, defined in flyweight.h.
More...
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "flyweight.h"
#include "dp_util.h"
Go to the source code of this file.
|
static FlyweightInstance | flyweight_instance_new (size_t size) |
|
static void | flyweight_instance_free (FlyweightInstance instance) |
|
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...
|
|
|
static FlyweightInstance | flyweight_factory_get_storaged_instance (FlyweightFactory class_factory, void *constructor_parameter) |
| Check has instance. More...
|
|
static FlyweightInstance | flyweight_factory_instance_new (FlyweightFactory class_factory, void *constructor_parameter) |
| allocate. More...
|
|
static void | flyweight_factory_push_instance (FlyweightInstance instance, FlyweightFactory class_factory) |
| push instance into list. More...
|
|
static FlyweightInstance | flyweight_factory_pop_instance (FlyweightFactory class_factory) |
| pop instance from list. More...
|
|
static FlyweightInstance | flyweight_factory_get (FlyweightFactory class_factory, void *constructor_parameter) |
| Getter. More...
|
|
Implement of Flyweight design petten library API, defined in flyweight.h.
Definition in file flyweight.c.
◆ FLYWEIGHT_CLASS_LOCK
#define FLYWEIGHT_CLASS_LOCK |
( |
|
instance | ) |
DPUTIL_LOCK(instance->lock) |
◆ FLYWEIGHT_CLASS_UNLOCK
◆ FLYWEIGHT_FAILED
#define FLYWEIGHT_FAILED (-1) /*! error */ |
◆ FLYWEIGHT_SUCCESS
#define FLYWEIGHT_SUCCESS (0) /*! success */ |
◆ FlyweightInstance
◆ flyweight_class_default_constructor()
static void flyweight_class_default_constructor |
( |
void * |
this, |
|
|
size_t |
size, |
|
|
void * |
input_parameter |
|
) |
| |
|
inlinestatic |
◆ flyweight_class_default_equall_operand()
static int flyweight_class_default_equall_operand |
( |
void * |
this, |
|
|
size_t |
size, |
|
|
void * |
input_parameter |
|
) |
| |
|
inlinestatic |
◆ flyweight_class_default_setter()
static int flyweight_class_default_setter |
( |
void * |
this, |
|
|
size_t |
size, |
|
|
void * |
input_parameter |
|
) |
| |
|
inlinestatic |
◆ flyweight_class_set_methods()
◆ flyweight_factory_free()
clear class handle
- Parameters
-
[in] | this | FlyweightFactory instance returned at flyweight_factory_new, |
- Returns
- none
Definition at line 293 of file flyweight.c.
◆ flyweight_factory_get()
◆ flyweight_factory_get_storaged_instance()
◆ flyweight_factory_instance_new()
◆ flyweight_factory_new()
define class for flyweight
- Parameters
-
[in] | class_size | size of instance which defined in user side. |
[in] | is_threadsafe | if !=0, ensure threadsafe to create new class instace, please set !=0 if you want to use this API on multi thread |
[in] | methods | for 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
-
!=NULL | this class handle |
NULL | error |
Definition at line 212 of file flyweight.c.
◆ flyweight_factory_pop_instance()
◆ flyweight_factory_push_instance()
◆ flyweight_get()
getter
- Parameters
-
[in] | this | FlyweightFactory instance returned at flyweight_factory_new, first time to call get, allocate class, memset 0 and call constructor |
[in] | constructor_parameter | constructor parameter |
- Return values
-
!NULL | class instance |
NULL | id is invalid |
Definition at line 244 of file flyweight.c.
◆ flyweight_instance_free()
◆ flyweight_instance_new()
◆ 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] | this | FlyweightFactory instance returned at flyweight_factory_new, |
[in] | constructor_parameter | constructor parameter |
[in] | data | set data pointer |
[in] | setter | setter if you want to change setter ( if NULL, use setter related to flyweight_register_class input) |
Definition at line 264 of file flyweight.c.