1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * umlformalparameter.c : refactored from uml.c, class.c to final use StdProps
5 * PROP_TYPE_DARRAY, a list where each element is a set
6 * of properies described by the same StdPropDesc
7 * Copyright (C) 2005 Hans Breuer
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #include "properties.h"
33 static PropDescription umlformalparameter_props
[] = {
34 { "name", PROP_TYPE_STRING
, PROP_FLAG_VISIBLE
| PROP_FLAG_OPTIONAL
,
35 N_("Name"), NULL
, NULL
},
36 { "type", PROP_TYPE_STRING
, PROP_FLAG_VISIBLE
| PROP_FLAG_OPTIONAL
,
37 N_("Type"), NULL
, NULL
},
42 static PropOffset umlformalparameter_offsets
[] = {
43 { "name", PROP_TYPE_STRING
, offsetof(UMLFormalParameter
, name
) },
44 { "type", PROP_TYPE_STRING
, offsetof(UMLFormalParameter
, type
) },
48 PropDescDArrayExtra umlformalparameter_extra
= {
49 { umlformalparameter_props
, umlformalparameter_offsets
, "umlformalparameter" },
50 (NewRecordFunc
)uml_formalparameter_new
,
51 (FreeRecordFunc
)uml_formalparameter_destroy
55 uml_formalparameter_new(void)
57 UMLFormalParameter
*param
;
59 param
= g_new0(UMLFormalParameter
, 1);
60 param
->name
= g_strdup("");
67 uml_formalparameter_copy(UMLFormalParameter
*param
)
69 UMLFormalParameter
*newparam
;
71 newparam
= g_new0(UMLFormalParameter
, 1);
73 newparam
->name
= g_strdup(param
->name
);
74 if (param
->type
!= NULL
) {
75 newparam
->type
= g_strdup(param
->type
);
77 newparam
->type
= NULL
;
84 uml_formalparameter_destroy(UMLFormalParameter
*param
)
87 if (param
->type
!= NULL
)
93 uml_formalparameter_write(AttributeNode attr_node
, UMLFormalParameter
*param
)
97 composite
= data_add_composite(attr_node
, "umlformalparameter");
99 data_add_string(composite_add_attribute(composite
, "name"),
101 data_add_string(composite_add_attribute(composite
, "type"),
106 uml_get_formalparameter_string (UMLFormalParameter
*parameter
)
111 /* Calculate length: */
112 len
= strlen (parameter
->name
);
114 if (parameter
->type
!= NULL
) {
115 len
+= 1 + strlen (parameter
->type
);
118 /* Generate string: */
119 str
= g_malloc (sizeof (char) * (len
+ 1));
120 strcpy (str
, parameter
->name
);
121 if (parameter
->type
!= NULL
) {
123 strcat (str
, parameter
->type
);
126 g_assert (strlen (str
) == len
);