File: objarg_EmployeeArray_Impl.c

package info (click to toggle)
babel 0.10.2-1
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 43,932 kB
  • ctags: 29,707
  • sloc: java: 74,695; ansic: 73,142; cpp: 40,649; sh: 18,411; f90: 10,062; fortran: 6,727; python: 6,406; makefile: 3,866; xml: 118; perl: 48
file content (292 lines) | stat: -rw-r--r-- 9,077 bytes parent folder | download
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*
 * File:          objarg_EmployeeArray_Impl.c
 * Symbol:        objarg.EmployeeArray-v0.5
 * Symbol Type:   class
 * Babel Version: 0.10.2
 * Description:   Server-side implementation for objarg.EmployeeArray
 * 
 * WARNING: Automatically generated; only changes within splicers preserved
 * 
 * babel-version = 0.10.2
 */

/*
 * DEVELOPERS ARE EXPECTED TO PROVIDE IMPLEMENTATIONS
 * FOR THE FOLLOWING METHODS BETWEEN SPLICER PAIRS.
 */

/*
 * Symbol "objarg.EmployeeArray" (version 0.5)
 * 
 * This class manages a collection of employees.
 */

#include "objarg_EmployeeArray_Impl.h"

#line 26 "../../../../babel/regression/objarg/libC/objarg_EmployeeArray_Impl.c"
/* DO-NOT-DELETE splicer.begin(objarg.EmployeeArray._includes) */
#include <stdlib.h>
#include <string.h>
#include "sidl_String.h"
#include "objarg_Employee.h"
/* DO-NOT-DELETE splicer.end(objarg.EmployeeArray._includes) */
#line 33 "objarg_EmployeeArray_Impl.c"

/*
 * Static class initializer called exactly once before any user-defined method is dispatched
 */

#undef __FUNC__
#define __FUNC__ "impl_objarg_EmployeeArray__load"

void
impl_objarg_EmployeeArray__load(
  void)
{
#line 44 "../../../../babel/regression/objarg/libC/objarg_EmployeeArray_Impl.c"
  /* DO-NOT-DELETE splicer.begin(objarg.EmployeeArray._load) */
  /* Insert the implementation of the static class initializer method here... */
  /* DO-NOT-DELETE splicer.end(objarg.EmployeeArray._load) */
#line 50 "objarg_EmployeeArray_Impl.c"
}
/*
 * Class constructor called when the class is created.
 */

#undef __FUNC__
#define __FUNC__ "impl_objarg_EmployeeArray__ctor"

void
impl_objarg_EmployeeArray__ctor(
  /* in */ objarg_EmployeeArray self)
{
#line 59 "../../../../babel/regression/objarg/libC/objarg_EmployeeArray_Impl.c"
  /* DO-NOT-DELETE splicer.begin(objarg.EmployeeArray._ctor) */
  struct objarg_EmployeeArray__data *dptr =
    malloc(sizeof(struct objarg_EmployeeArray__data));
  if (dptr) {
    dptr->d_length = 0;
    dptr->d_capacity = 0;
    dptr->d_employees = NULL;
  }
  objarg_EmployeeArray__set_data(self, dptr);
  /* DO-NOT-DELETE splicer.end(objarg.EmployeeArray._ctor) */
#line 74 "objarg_EmployeeArray_Impl.c"
}

/*
 * Class destructor called when the class is deleted.
 */

#undef __FUNC__
#define __FUNC__ "impl_objarg_EmployeeArray__dtor"

void
impl_objarg_EmployeeArray__dtor(
  /* in */ objarg_EmployeeArray self)
{
#line 82 "../../../../babel/regression/objarg/libC/objarg_EmployeeArray_Impl.c"
  /* DO-NOT-DELETE splicer.begin(objarg.EmployeeArray._dtor) */
  struct objarg_EmployeeArray__data *dptr = 
    objarg_EmployeeArray__get_data(self);
  if (dptr) {
    int i;
    for(i = 0; i < dptr->d_length; ++i) {
      objarg_Employee employee = (dptr->d_employees)[i];
      (dptr->d_employees)[i] = NULL;
      objarg_Employee_deleteRef(employee);
    }
    if (dptr->d_employees) {
      free((void *)(dptr->d_employees));
    }
    memset(dptr, 0, sizeof(struct objarg_EmployeeArray__data));
    free((void *)dptr);
  }
  /* DO-NOT-DELETE splicer.end(objarg.EmployeeArray._dtor) */
#line 106 "objarg_EmployeeArray_Impl.c"
}

/*
 * Return the number of employees in the employee array.
 */

#undef __FUNC__
#define __FUNC__ "impl_objarg_EmployeeArray_getLength"

int32_t
impl_objarg_EmployeeArray_getLength(
  /* in */ objarg_EmployeeArray self)
{
#line 112 "../../../../babel/regression/objarg/libC/objarg_EmployeeArray_Impl.c"
  /* DO-NOT-DELETE splicer.begin(objarg.EmployeeArray.getLength) */
  struct objarg_EmployeeArray__data *dptr = 
    objarg_EmployeeArray__get_data(self);
  return dptr ? dptr->d_length : 0;
  /* DO-NOT-DELETE splicer.end(objarg.EmployeeArray.getLength) */
#line 126 "objarg_EmployeeArray_Impl.c"
}

/*
 * Return the employee in position <code>index</code> where
 * <code>index</code> ranges from 1 to the length of the array.
 * If <code>index</code> is outside the range of the array (i.e.
 * less than or equal to zero or greater than the current number
 * of elements in the array), this method returns a NULL
 * employee object.
 */

#undef __FUNC__
#define __FUNC__ "impl_objarg_EmployeeArray_at"

objarg_Employee
impl_objarg_EmployeeArray_at(
  /* in */ objarg_EmployeeArray self,
  /* in */ int32_t index)
{
#line 136 "../../../../babel/regression/objarg/libC/objarg_EmployeeArray_Impl.c"
  /* DO-NOT-DELETE splicer.begin(objarg.EmployeeArray.at) */
  struct objarg_EmployeeArray__data *dptr = 
    objarg_EmployeeArray__get_data(self);
  if (dptr && (index > 0) && (index <= dptr->d_length)) {
    objarg_Employee employee = (dptr->d_employees)[index-1];
    objarg_Employee_addRef(employee);
    return employee;
  }
  return NULL;
  /* DO-NOT-DELETE splicer.end(objarg.EmployeeArray.at) */
#line 157 "objarg_EmployeeArray_Impl.c"
}

/*
 * Add an employee onto the end of the array.  It is perfectly
 * legal to add the same employee multiple times.
 * <code>true</code> is returned when the append was successful;
 * otherwise, <code>false</code> is returned to indicate
 * failure.  This method will not add a NULL employee.
 */

#undef __FUNC__
#define __FUNC__ "impl_objarg_EmployeeArray_appendEmployee"

sidl_bool
impl_objarg_EmployeeArray_appendEmployee(
  /* in */ objarg_EmployeeArray self,
  /* in */ objarg_Employee e)
{
#line 164 "../../../../babel/regression/objarg/libC/objarg_EmployeeArray_Impl.c"
  /* DO-NOT-DELETE splicer.begin(objarg.EmployeeArray.appendEmployee) */
  struct objarg_EmployeeArray__data *dptr = 
    objarg_EmployeeArray__get_data(self);
  if (dptr && e) {
    if (dptr->d_length >= dptr->d_capacity) {
      /* expand array capacity */
      int32_t newcapacity = dptr->d_capacity + 4;
      objarg_Employee *newArray;
      if ((dptr->d_capacity / 10) > 4) {
        newcapacity = dptr->d_capacity + dptr->d_capacity/10;
      }
      newArray = malloc(newcapacity * sizeof(objarg_Employee));
      if (!newArray) return FALSE;
      if (newArray && dptr->d_employees) {
        memcpy(newArray, dptr->d_employees, dptr->d_length *
               sizeof(objarg_Employee));
        free(dptr->d_employees);
      }
      dptr->d_employees = newArray;
      dptr->d_capacity = newcapacity;
    }
    objarg_Employee_addRef(e);
    dptr->d_employees[dptr->d_length++] = e;
    return TRUE;
  }
  return FALSE;
  /* DO-NOT-DELETE splicer.end(objarg.EmployeeArray.appendEmployee) */
#line 204 "objarg_EmployeeArray_Impl.c"
}

/*
 * Find the first employee in the array that has a name matching
 * <code>name</code>.  If a match exists, the index is returned,
 * and the employee is returned in parameter <code>e</code>.
 * 
 * If no match exists, 0 is returned, and <code>e</code> is NULL.
 */

#undef __FUNC__
#define __FUNC__ "impl_objarg_EmployeeArray_findByName"

int32_t
impl_objarg_EmployeeArray_findByName(
  /* in */ objarg_EmployeeArray self,
  /* in */ const char* name,
  /* out */ objarg_Employee* e)
{
#line 210 "../../../../babel/regression/objarg/libC/objarg_EmployeeArray_Impl.c"
  /* DO-NOT-DELETE splicer.begin(objarg.EmployeeArray.findByName) */
  if (name && e) {
    struct objarg_EmployeeArray__data *dptr = 
      objarg_EmployeeArray__get_data(self);
    *e = NULL;
    if (dptr) {
      int32_t i;
      for(i = 0; i < dptr->d_length; ++i) {
        objarg_Employee tmp = (dptr->d_employees)[i];
        char *match = objarg_Employee_getName(tmp);
        const int equal = !strcmp(match, name);
        sidl_String_free(match);
        if (equal) {
          objarg_Employee_addRef(tmp);
          *e = tmp;
          return i + 1;
        }
      }
    }
  }
  return 0;
  /* DO-NOT-DELETE splicer.end(objarg.EmployeeArray.findByName) */
#line 247 "objarg_EmployeeArray_Impl.c"
}

/*
 * Determine the maximum salary in the array. If the maximum
 * salary in the array is greater than the current salary of
 * <code>e</code>, the salary of <code>e</code> will be 
 * increased to the maximum salary in the array.  If the
 * array is empty, no change will be made to <code>e</code>.
 * 
 * This method returns <code>true</code> iff the salary of
 * <code>e</code> is modified.
 */

#undef __FUNC__
#define __FUNC__ "impl_objarg_EmployeeArray_promoteToMaxSalary"

sidl_bool
impl_objarg_EmployeeArray_promoteToMaxSalary(
  /* in */ objarg_EmployeeArray self,
  /* inout */ objarg_Employee* e)
{
#line 253 "../../../../babel/regression/objarg/libC/objarg_EmployeeArray_Impl.c"
  /* DO-NOT-DELETE splicer.begin(objarg.EmployeeArray.promoteToMaxSalary) */
  if (*e) {
    struct objarg_EmployeeArray__data *dptr = 
      objarg_EmployeeArray__get_data(self);
    if (dptr && dptr->d_length) {
      float maxSalary = -1.0e30;
      int i;
      for(i = 0; i < dptr->d_length; ++i){
        float salary = objarg_Employee_getSalary(dptr->d_employees[i]);
        if (salary > maxSalary) {
          maxSalary = salary;
        }
      }
      if (maxSalary > objarg_Employee_getSalary(*e)) {
        objarg_Employee_setSalary(*e, maxSalary);
        return TRUE;
      }
    }
  }
  return FALSE;
  /* DO-NOT-DELETE splicer.end(objarg.EmployeeArray.promoteToMaxSalary) */
#line 291 "objarg_EmployeeArray_Impl.c"
}