2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
26 * $TOG: MsgHndArray.C /main/6 1998/09/02 15:54:28 mgreess $
28 * RESTRICTED CONFIDENTIAL INFORMATION:
30 * The information in this document is subject to special
31 * restrictions in a confidential disclosure agreement between
32 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
33 * document outside HP, IBM, Sun, USL, SCO, or Univel without
34 * Sun's specific written approval. This document and all copies
35 * and derivative works thereof must be returned or destroyed at
38 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
43 #include "MsgHndArray.hh"
44 #include "MemUtils.hh"
47 MsgHndArray::at(int indx)
49 return(_contents[indx]);
55 memset(_contents, 0, sizeof(MsgStruct *)*_size);
66 MsgHndArray::indexof(MsgStruct *a_msg_struct)
70 for (tmp = 0; tmp < _length; tmp++)
72 if ((_contents[tmp]->sessionNumber == a_msg_struct->sessionNumber) &&
73 (_contents[tmp]->message_handle == a_msg_struct->message_handle))
82 MsgHndArray::indexof(DtMailMessageHandle a_message_handle)
86 for (tmp = 0; tmp < _length; tmp++)
88 if (_contents[tmp]->message_handle == a_message_handle)
97 MsgHndArray::remove_entry(MsgStruct *ms)
99 for (int i=0; i<_length; i++)
101 if (ms == _contents[i])
111 MsgHndArray::remove_entry(int position)
114 FORCE_SEGV_DECL(MsgStruct, tmpMS);
116 if ((position < 0) || (position >= _length)) return;
118 tmpMS = _contents[position];
120 for (i=position; i<(_length-1); i++)
121 _contents[i] = _contents[i+1];
123 _contents[_length] = NULL;
131 MsgStruct *a_msg_struct
134 int i, j, orig_size, return_val;
137 FORCE_SEGV_DECL(MsgStruct, tmpMS1);
138 FORCE_SEGV_DECL(MsgStruct, tmpMS2);
141 sess_num = a_msg_struct->sessionNumber;
143 for(i = 0; i < _length; i++) {
144 tmpMS1 = _contents[i];
145 if (tmpMS1->sessionNumber > sess_num) {
146 _contents[i] = a_msg_struct;
155 // If we hit size, then grow by 25% to allow more entries.
156 // Zero out the added portion.
158 if (_length == _size) {
160 _size += (_size >> 2);
161 _contents = (MsgStruct **)realloc(_contents,
162 _size * sizeof(MsgStruct *));
163 memset(_contents+orig_size, 0, sizeof(MsgStruct *)*_size);
166 for (j = i + 1; j < _length; j++) {
167 tmpMS2 = _contents[j];
168 _contents[j] = tmpMS1;
173 _contents[_length] = a_msg_struct;
174 return_val = _length;
183 MsgStruct *a_msg_struct
188 _contents[_length] = a_msg_struct;
191 // If we hit size, then grow by 25% to allow more entries.
193 if (_length == _size) {
194 _size += (_size >> 2);
195 _contents = (MsgStruct **)realloc(_contents,
196 _size * sizeof(MsgStruct *));
202 MsgHndArray::mark_for_delete(int indx)
204 _contents[indx]->is_deleted = TRUE;
208 MsgHndArray::compact(
212 FORCE_SEGV_DECL(MsgStruct, tmpMS);
215 if ((_length <= 0) || (start_pos < 0) || (start_pos >= _length))
218 for (i = _length - 1; i >= start_pos; i--) {
219 tmpMS = _contents[i];
220 if (tmpMS->is_deleted) {
221 tmpMS->is_deleted = FALSE;
230 // Replace the MsgStruct at 'position' with the passed MsgStruct.
231 // The MsgStruct previously located at 'position' is *not* destroyed.
234 MsgHndArray::replace(
236 MsgStruct *a_msg_struct
239 if (position < 0 || position >= _length) {
243 _contents[position] = a_msg_struct;