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 libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 //%% (c) Copyright 1993, 1994 Hewlett-Packard Company
24 //%% (c) Copyright 1993, 1994 International Business Machines Corp.
25 //%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
26 //%% (c) Copyright 1993, 1994 Novell, Inc.
27 //%% $XConsortium: CoEdTextVersion.C /main/3 1995/10/23 09:43:59 rswiston $
31 * Copyright (c) 1991 by Sun Microsystems. All Rights Reserved.
33 * Permission to use, copy, modify, distribute, and sell this software
34 * and its documentation for any purpose is hereby granted without
35 * fee, provided that the above copyright notice appear in all copies
36 * and that both that copyright notice and this permission notice
37 * appear in supporting documentation, and that the names of Sun
38 * Microsystems and its subsidiaries not be used in advertising or
39 * publicity pertaining to distribution of the software without
40 * specific, written prior permission. Sun Microsystems and its
41 * subsidiaries make no representations about the suitability of this
42 * software for any purpose. It is provided "as is" without express
43 * or implied warranty.
45 * Sun Microsystems and its subsidiaries disclaim all warranties with
46 * regard to this software, including all implied warranties of
47 * merchantability and fitness. In no event shall Sun Microsystems or
48 * its subsidiaries be liable for any special, indirect or
49 * consequential damages or any damages whatsoever resulting from loss
50 * of use, data or profits, whether in an action of contract,
51 * negligence or other tortious action, arising out of or in
52 * connection with the use or performance of this software.
55 #include "CoEdTextVersion.h"
58 CoEdTextVersion() : SiteChangeList()
63 CoEdTextVersion( unsigned char *data, int len, CoEdStatus &status )
64 : SiteChangeList( data, len, status )
68 void CoEdTextVersion::
69 update( const CoEdSiteID &site, int numChanges )
71 SiteChange *curr = _head;
74 if ( *(CoEdSiteID *)curr == site ) {
75 curr->_changeNum = numChanges;
78 curr = (SiteChange *)curr->_next;
81 curr = new SiteChange( site, numChanges );
86 CoEdTextVersion *CoEdTextVersion::
89 CoEdTextVersion *newVersion = new CoEdTextVersion;
90 newVersion->SiteChangeList::copy( (const SiteChangeList *)this );
95 // This method assumes that the CoEdSiteID of <change> is _not_ already
96 // in the list of SiteChanges!
98 void CoEdTextVersion::
99 insert( SiteChange *change )
101 SiteChange *curr = _head;
103 while ((curr != 0) && (! inserted)) {
104 if (*change < *curr) {
105 insertBefore( change, curr );
108 curr = (SiteChange *)curr->_next;
115 int CoEdTextVersion::
116 knowsOfNewerChangesThan( const CoEdTextVersion &version ) const
118 SiteChange *curr1 = _head;
119 SiteChange *curr2 = version._head;
120 while ((curr1 != 0) && (curr2 != 0)) {
122 int diff = curr1->cmp( *curr2 );
125 // I know of a change from a site that he
126 // has not even heard from.
128 // I know of a change from this site that
129 // is later than the one he knows.
132 // He knows of a change from this site that
133 // is later than the one I know. Big deal.
136 // He knows of a change from a site that I
137 // have not even heard from. So wait until
138 // my next site comes up in his list.
145 curr1 = (SiteChange *)curr1->_next;
147 curr2 = (SiteChange *)curr2->_next;
149 if ((curr1 != 0) && (curr2 == 0)) {
151 // I still have a change from a site that he has
152 // never even heard from.
159 int CoEdTextVersion::
160 knowsOf( const CoEdSiteID &site, int numChanges ) const
162 SiteChange *curr = _head;
164 if ( *(CoEdSiteID *)curr == site ) {
165 return (curr->_changeNum >= numChanges);
167 curr = (SiteChange *)curr->_next;