InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SBOSReference.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Jianlan Song
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 
25 #include "IPMStream.h"
26 #include "SBOSRefInstantiate.h"
27 
45 template <class ISBOSObj>
47 {
48  public:
51 
52 
56  fBaseUIDRef(), fSubItem(kInvalidSBOSID)
57  {}
58 
59 
64  SBOSReference(const UIDRef& baseUIDRef, SBOSID subItemID = kInvalidSBOSID) :
65  fBaseUIDRef(baseUIDRef), fSubItem(subItemID)
66  {}
67 
68 
72  const UIDRef& GetUIDRef() const
73  { return fBaseUIDRef; }
74 
75 
79  UID GetUID() const
80  { return fBaseUIDRef.GetUID(); }
81 
82 
87  { return fBaseUIDRef.GetDataBase(); }
88 
89 
93  SBOSID GetLogicalID() const
94  { return fSubItem; }
95 
96 
100  void SetLogicalID(SBOSID newValue)
101  { fSubItem = newValue; }
102 
103 
107  ISBOSObj* Instantiate() const
108  {
109  IPMUnknown* obj = SBOSRefInstantiate::Instantiate(fBaseUIDRef, fSubItem, ISBOSObj::kDefaultIID);
110  if (obj)
111  return static_cast<ISBOSObj*>(obj);
112  else
113  return nil;
114  }
115 
120  void ReadWrite(IPMStream *s, IDataBase *db = nil)
121  {
122  if (s->IsReading()) {
123  // reset all values to default, in case this is a snapshot restore
124  fBaseUIDRef = UIDRef::gNull;
125  fSubItem = kInvalidSBOSID;
126  }
127 
128  UID uid = fBaseUIDRef.GetUID();
129 
130  s->XferReference(uid);
131  if (s->IsReading() && uid != kInvalidUID)
132  fBaseUIDRef = UIDRef(db, uid);
133 
134  s->XferInt32((int32&)fSubItem);
135  }
136 
141  bool16 operator == (const SBOSReference& other) const
142  { return fBaseUIDRef == other.fBaseUIDRef && fSubItem == other.fSubItem; }
143 
144 
149  inline bool16 operator != (const SBOSReference& compareAgainst) const
150  { return (!(*this == compareAgainst)); }
151 
156  bool16 operator < (const SBOSReference& compareAgainst) const
157  {
158  if (this->GetDataBase() == compareAgainst.GetDataBase())
159  {
160  if (this->GetUID() == compareAgainst.GetUID())
161  return this->GetLogicalID() < compareAgainst.GetLogicalID();
162  else
163  return this->GetUID() < compareAgainst.GetUID();
164  }
165 
166  return this->GetDataBase() < compareAgainst.GetDataBase();
167  }
168 
169  private:
170  UIDRef fBaseUIDRef;
171  SBOSID fSubItem;
172 };
173