-
Notifications
You must be signed in to change notification settings - Fork 17
/
ComponentFactory.c
71 lines (54 loc) · 2.16 KB
/
ComponentFactory.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/********************************************************************************
* Copyright (c) 2020 AVL List GmbH and others
*
* This program and the accompanying materials are made available under the
* terms of the Apache Software License 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
#include "components/ComponentFactory.h"
#include "CentralParts.h"
#include "core/Component_impl.h" // friend include
#include "util/string.h"
#include "components/comp_constant.h"
#include "components/comp_fmu.h"
#include "components/comp_integrator.h"
#include "components/comp_vector_integrator.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
static Component * _CreateComponent(ComponentFactory * factory, ComponentType * type, size_t id) {
Component * comp = NULL;
if (object_same_type(ComponentTypeFmu, type)) {
comp = (Component *) object_create(CompFMU);
} else if (object_same_type(ComponentTypeIntegrator, type)) {
comp = (Component *) object_create(CompIntegrator);
} else if (object_same_type(ComponentTypeVectorIntegrator, type)) {
comp = (Component *) object_create(CompVectorIntegrator);
} else if (object_same_type(ComponentTypeConstant, type)) {
comp = (Component *) object_create(CompConstant);
}
if (comp) {
comp->data->id = id;
comp->data->typeString = mcx_string_copy(type->ToString(type));
if (!comp->data->typeString) {
return NULL;
}
}
return comp;
}
static Component * CreateComponent(ComponentFactory * factory, ComponentType * type, size_t id) {
return factory->_CreateComponent(factory, type, id);
}
static void ComponentFactoryDestructor(ComponentFactory * factory) {
}
static ComponentFactory * ComponentFactoryCreate(ComponentFactory * factory) {
factory->CreateComponent = CreateComponent;
factory->_CreateComponent = _CreateComponent;
return factory;
}
OBJECT_CLASS(ComponentFactory, Object);
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endif /* __cplusplus */