2
0

CoEdTextVersion.C 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  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)
  10. * any later version.
  11. *
  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
  16. * details.
  17. *
  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
  22. */
  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 $
  28. /*
  29. * CoEdTextVersion.cc
  30. *
  31. * Copyright (c) 1991 by Sun Microsystems. All Rights Reserved.
  32. *
  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.
  44. *
  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.
  53. */
  54. #include "CoEdTextVersion.h"
  55. CoEdTextVersion::
  56. CoEdTextVersion() : SiteChangeList()
  57. {
  58. }
  59. CoEdTextVersion::
  60. CoEdTextVersion( unsigned char *data, int len, CoEdStatus &status )
  61. : SiteChangeList( data, len, status )
  62. {
  63. }
  64. void CoEdTextVersion::
  65. update( const CoEdSiteID &site, int numChanges )
  66. {
  67. SiteChange *curr = _head;
  68. int found = 0;
  69. while (curr != 0) {
  70. if ( *(CoEdSiteID *)curr == site ) {
  71. curr->_changeNum = numChanges;
  72. found = 1;
  73. }
  74. curr = (SiteChange *)curr->_next;
  75. }
  76. if (! found) {
  77. curr = new SiteChange( site, numChanges );
  78. insert( curr );
  79. }
  80. }
  81. CoEdTextVersion *CoEdTextVersion::
  82. copy() const
  83. {
  84. CoEdTextVersion *newVersion = new CoEdTextVersion;
  85. newVersion->SiteChangeList::copy( (const SiteChangeList *)this );
  86. return newVersion;
  87. }
  88. //
  89. // This method assumes that the CoEdSiteID of <change> is _not_ already
  90. // in the list of SiteChanges!
  91. //
  92. void CoEdTextVersion::
  93. insert( SiteChange *change )
  94. {
  95. SiteChange *curr = _head;
  96. int inserted = 0;
  97. while ((curr != 0) && (! inserted)) {
  98. if (*change < *curr) {
  99. insertBefore( change, curr );
  100. inserted = 1;
  101. }
  102. curr = (SiteChange *)curr->_next;
  103. }
  104. if (! inserted) {
  105. append( change );
  106. }
  107. }
  108. int CoEdTextVersion::
  109. knowsOfNewerChangesThan( const CoEdTextVersion &version ) const
  110. {
  111. SiteChange *curr1 = _head;
  112. SiteChange *curr2 = version._head;
  113. while ((curr1 != 0) && (curr2 != 0)) {
  114. int wait = 0;
  115. int diff = curr1->cmp( *curr2 );
  116. switch (diff) {
  117. case -2:
  118. // I know of a change from a site that he
  119. // has not even heard from.
  120. case 1:
  121. // I know of a change from this site that
  122. // is later than the one he knows.
  123. return 1;
  124. case -1:
  125. // He knows of a change from this site that
  126. // is later than the one I know. Big deal.
  127. break;
  128. case 2:
  129. // He knows of a change from a site that I
  130. // have not even heard from. So wait until
  131. // my next site comes up in his list.
  132. wait = 1;
  133. break;
  134. case 0:
  135. break;
  136. }
  137. if (! wait) {
  138. curr1 = (SiteChange *)curr1->_next;
  139. }
  140. curr2 = (SiteChange *)curr2->_next;
  141. }
  142. if ((curr1 != 0) && (curr2 == 0)) {
  143. //
  144. // I still have a change from a site that he has
  145. // never even heard from.
  146. //
  147. return 1;
  148. }
  149. return 0;
  150. }
  151. int CoEdTextVersion::
  152. knowsOf( const CoEdSiteID &site, int numChanges ) const
  153. {
  154. SiteChange *curr = _head;
  155. while (curr != 0) {
  156. if ( *(CoEdSiteID *)curr == site ) {
  157. return (curr->_changeNum >= numChanges);
  158. }
  159. curr = (SiteChange *)curr->_next;
  160. }
  161. return 0;
  162. }