Design Pattern Examples
Overview of object-oriented design patterns
Mediator_User.c
Go to the documentation of this file.
1
5
6#include <stdlib.h>
7#include <string.h>
8#include <memory.h>
9
10#include "helpers/strdup.h"
11
12#include "Mediator_User.h"
13
15// User_Create()
17User* User_Create(const char* userName)
18{
19 User* user = NULL;
20
21 if (userName != NULL)
22 {
23 user = calloc(1, sizeof(User));
24 if (user != NULL)
25 {
26 user->Name = (const char*)STRDUP(userName);
27 if (user->Name == NULL)
28 {
29 free(user);
30 user = NULL;
31 }
32 }
33 }
34
35 return user;
36}
37
39// User_Destroy()
41void User_Destroy(User* user)
42{
43 if (user != NULL)
44 {
45 free((char*)user->Name);
46 user->Name = NULL;
47 free(user);
48 }
49}
void User_Destroy(User *user)
Destroy the given User object, releasing any associated memory resources. After this function returns...
Definition: Mediator_User.c:41
User * User_Create(const char *userName)
Create a User object with the specified name.
Definition: Mediator_User.c:17
Declaration of the User structure and the associated support functions as used in the Mediator Patter...
Declaration of the STRDUP macro that hides the differences between how strdup() is declared in differ...
#define STRDUP
Define STRDUP to be the operating system-specific version of strdup().
Definition: strdup.h:17
Represents a user with a name.
Definition: Mediator_User.h:14
const char * Name
The name of the user.
Definition: Mediator_User.h:18