InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
UIDList.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Robin_Briggs
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //========================================================================================
23 
24 #ifndef __UIDLIST__
25 #define __UIDLIST__
26 //#pragma export on
27 #include "IPMUnknown.h"
28 
29 #include "K2Vector.h"
30 #include "UIDRef.h"
31 #include "PersistUtils.h"
32 #include "UIDListInternal.h"
33 #include "index_based_iterator.h"
34 
35 // ==================================================================================
36 // * * * C L A S S U I D L i s t * * * *
37 // ==================================================================================
41 class UIDList
42 {
43  // Traits
44 public:
45  typedef object_type data_type;
46  typedef UIDListInternal::value_type value_type;
47  typedef UIDListInternal::size_type size_type;
48  typedef UIDListInternal::const_reference const_reference;
49  typedef UIDListInternal::reference reference;
50  typedef UIDListInternal::difference_type difference_type;
51  typedef UIDListInternal::pointer pointer;
52  typedef UIDListInternal::const_pointer const_pointer;
53 
54 private:
55  friend class SortedUIDList;
56  UIDListInternal * fUIDList;
57 
58 public:
59  // Defines iterators
60  // Because of COW optimization these iterators use indexes instead of pointers.
63  typedef std::reverse_iterator<iterator> reverse_iterator;
64  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
65 
66  // Constructors
67 
71  UIDList();
72 
76  explicit UIDList(IDataBase *db);
77 
81  UIDList(const UIDList &copy);
82 
83  UIDList(UIDList &&other) noexcept :
84  fUIDList(other.fUIDList)
85  {
86  other.fUIDList = nil;
87  }
88 
93  UIDList(IDataBase *db, const UID singleEntry);
94 
98  UIDList(const IPMUnknown *object);
99 
103  UIDList(const UIDRef &ref);
104 
106  ~UIDList();
107 
108 
112  UIDList& operator=(const UIDList& other);
113 
114  UIDList& operator=(UIDList&& other) noexcept
115  {
116  using std::swap;
117  swap(*this, other);
118  return *this;
119  }
120 
121  friend inline void swap(UIDList &a, UIDList &b) noexcept
122  {
123  std::swap(a.fUIDList, b.fUIDList);
124  }
125 
130  bool16 operator==(const UIDList& other) const;
131 
136  bool16 operator!=(const UIDList& other) const;
137 
142  {
143  return fUIDList ? const_iterator(*this, 0) : const_iterator();
144  }
145 
150  {
151  // No PreModify() called here (only when dereferencing the iterator)
152  return fUIDList ? iterator(*this, 0) : iterator();
153  }
154 
158  const_reverse_iterator rbegin() const
159  {
160  return const_reverse_iterator(this->end());
161  }
162 
166  reverse_iterator rbegin()
167  {
168  return reverse_iterator(this->end());
169  }
170 
175  {
176  return fUIDList ? const_iterator(*this, fUIDList->Length()) : const_iterator();
177  }
178 
183  {
184  // No PreModify() called here (only when dereferencing the iterator)
185  return fUIDList ? iterator(*this, fUIDList->Length()) : iterator();
186  }
187 
191  const_reverse_iterator rend() const
192  {
193  return const_reverse_iterator(this->begin());
194  }
195 
199  reverse_iterator rend()
200  {
201  return reverse_iterator(this->begin());
202  }
203 
208  UID operator[](int32 i) const
209  {
210  //ASSERT(fUIDList && i > -1 && i < fUIDList->fArray.size());
211  return (fUIDList && (i > -1)) ? fUIDList->fArray[i] : kInvalidUID;
212  }
213 
214  // Modifier methods - allocate new fUIDListInternal if the current
215  // UIDList is not the sole owner
216 
221  UID& At(int32 i);
222 
227  UID At(int32 i) const
228  { return (*this)[i]; }
229 
233  void SetChunkSize(int32 chunk);
234 
239  bool16 Preallocate(int32 newlen);
240 
242  void Clear();
243 
247  void Insert(const UID t);
248 
253  void Insert(const UIDList &list, int32 before);
254 
259  void Insert(const UID t, int32 before);
260 
264  void Append(const UID t);
265 
270  void Append(const UID t, int32 after);
271 
275  void Append(const UIDList& list);
276 
280  void Remove(int32 at);
281 
288  iterator erase(iterator i);
289 
297  iterator erase(iterator first, iterator last);
298 
303  void push_back(const_reference value);
304 
307  size_type size() const
308  {
309  return fUIDList ? fUIDList->fArray.size() : 0;
310  }
311 
316  void Replace(int32 at, const UID t);
317 
322  int32 Location(UID t) const
323  {
324  return fUIDList? fUIDList->Location(t) : - 1;
325  }
326 
331  bool16 Contains(UID t) const
332  {
333  return Location(t) != -1;
334  }
335 
340  bool16 DoesNotContain(UID t) const
341  {
342  return Location(t) == -1;
343  }
344 
346  void AddRef()
347  {
348  if(fUIDList)
349  fUIDList->AddRef();
350  }
351 
353  void Release();
354 
355  // Fetch
357  int32 ChunkSize() const
358  {
359  return fUIDList? 8 : 0; } //AW_TODO: Possibly deprecate this?
360 
362  int32 Length() const
363  {
364  return fUIDList? fUIDList->Length() : 0;
365  }
366 
368  bool16 IsEmpty() const
369  {
370  return fUIDList? fUIDList->IsEmpty(): kTrue;
371  }
372 
374  UID First() const;
375 
377  UID& First();
378 
380  UID Last() const;
381 
383  UID& Last();
384 
386  IDataBase *GetDataBase() const;
387 
392  UIDRef GetRef(int32 at) const;
393 
399  void ReadWriteXferObject(IPMStream* stream);
400 
406  void ReadWriteXferReference(IPMStream* stream);
407 
408 private:
409  // Iterators need access to the private methods.
410  friend class index_based_iterator<UIDList, UIDList::value_type>;
411  friend class index_based_iterator<UIDList, UIDList::value_type const>;
412 
416  void PreModify();
417 
420  void Replicate();
421 
422  enum EXferType { eXferObject, eXferReference };
425  void ReadWrite(IPMStream* s, const EXferType xfer);
426 
428  const_reference get_const_ref(difference_type pos) const
429  {
430  ASSERT(fUIDList);
431  return fUIDList->operator[](pos);
432  }
433 
435  reference get_ref(difference_type pos)
436  {
437  // If a copy of the container occurs between two calls to this operator
438  // we will be modifying shared data (because of the COW optimization)
439  // so we have to call PreModify() every time;
440  PreModify();
441  return fUIDList->operator[](pos);
442  }
443 
444 #ifdef DEBUG
445 
446  bool IsValidIterator(const_iterator const& it) const
447  {
448  // Checks if the iterator is from this container (uidlist) and within legal range
449  return ((it.get_container() == this) && it.is_valid());
450  }
451 #endif
452 } ;
453 
454 //L1 and L2 have items common to both removed from each (and as a side effect, items are sorted and distinct)
455  void Disjoin( UIDList& L1, UIDList& L2);
456 
457 //L1 receives the union of the two and L2 receives the intersection (and as a side effect, items are sorted and distinct)
458  void Join( UIDList& L1, UIDList& L2);
459 
460 //L1 receives L1\L2 and L2 receives the intersection (and as a side effect, items are sorted and distinct)
461 //That is, after the call to Difference, L1 has members _also_ in L2 removed, and L2 has members _not_ in L1 removed.
462  void Difference( UIDList& L1, UIDList& L2);
463 
464 /*
465 // Arithmetical operators
466 inline UIDList::difference_type operator-(const_iterator const& lhs, const_iterator const& rhs)
467 {
468  return lhs.base() - rhs.base();
469 }
470 
471 inline UIDList::iterator operator+(UIDList::difference_type offset, iterator const& rhs)
472 {
473  return (rhs + offset);
474 }
475 
476 inline UIDList::const_iterator operator+(UIDList::difference_type offset, const_iterator const& rhs)
477 {
478  return (rhs + offset);
479 }
480 
481 // Comparison operators
482 inline bool operator==(UIDList::const_iterator const& lhs, UIDList::const_iterator const& rhs)
483 {
484  return (lhs.compare(rhs) == 0);
485 }
486 
487 inline bool operator!=(UIDList::const_iterator const& lhs, UIDList::const_iterator const& rhs)
488 {
489  return !(lhs == rhs);
490 }
491 
492 inline bool operator<(UIDList::const_iterator const& lhs, UIDList::const_iterator const& rhs)
493 {
494  return (lhs.compare(rhs) < 0);
495 }
496 
497 inline bool operator>(UIDList::const_iterator const& lhs, UIDList::const_iterator const& rhs)
498 {
499  return rhs < lhs;
500 }
501 
502 inline bool operator<=(UIDList::const_iterator const& lhs, UIDList::const_iterator const& rhs)
503 {
504  return !(rhs < lhs);
505 }
506 
507 inline bool operator>=(UIDList::const_iterator const& lhs, UIDList::const_iterator const& rhs)
508 {
509  return !(lhs < rhs);
510 }
511 */
512 //#pragma export off
513 
514 #endif // __UIDLIST__