28 #if !defined(__SchemaUtils__) 29 #define __SchemaUtils__ 36 #include "SchemaTypes.h" 37 #include "SimpleLink.h" 43 #include "VersionID.h" 71 class IteratorSchemaInfo;
104 :
VersionID(kInvalidPlugin, -1, -1), fForced(kFalse)
112 :
VersionID(pluginID, format), fForced(forced)
115 bool16 WasForced()
const 138 : fFromVersion(from), fToVersion(to)
142 {
return fFromVersion;}
146 bool16 operator==(
const Conversion& other)
const 147 {
return (fFromVersion == other.fFromVersion) && (fToVersion == other.fToVersion);}
170 : fType(kInvalidField), fBuffer(nil), fBufferSize(0)
173 : fType(type), fBuffer(nil), fBufferSize(0)
176 : fType(other.fType), fBuffer(nil), fBufferSize(0)
182 int32 GetSize()
const 183 {
return fBufferSize;}
187 bool16 operator==(
const DataBlob& other)
const;
189 {Copy(other);
return *
this;}
192 static bool16 IsDataBlobType(FieldType t)
193 {
return ((t == kDataBlob16) || (t == kDataBlob32) || (t == kDataBlob8));}
196 void SetSize(int32 size);
209 : fType(kInvalidField)
210 {SetUnionType(fType, fValue);}
213 {SetUnionType(fType, fValue);}
214 FieldValue(FieldType type,
IPMStream *s);
215 FieldValue(
const FieldValue &other);
219 FieldType GetType()
const 222 bool16 GetBool8(bool8 &v)
const;
223 bool16 GetBool16(bool16 &v)
const;
224 bool16 GetInt8(int8 &v)
const;
225 bool16 GetUint8(uint8 &v)
const;
226 bool16 GetInt16(int16 &v)
const;
227 bool16 GetUint16(uint16 &v)
const;
228 bool16 GetInt32(int32 &v)
const;
229 bool16 GetUint32(uint32 &v)
const;
230 bool16 GetReal(
PMReal &v)
const;
231 bool16 GetClassID(
ClassID &v)
const;
233 bool16 GetInterfaceID(
PMIID &v)
const;
235 bool16 GetWidgetID(
WidgetID &v)
const;
236 bool16 GetPluginID(
PluginID &v)
const;
237 bool16 GetErrorID(ErrorCode &v)
const;
238 bool16 GetObject(
UID &v)
const;
239 bool16 GetReference(
UID &v)
const;
240 bool16 GetPMString(
PMString &v)
const;
241 bool16 GetPMPoint(
PMPoint &v)
const;
242 bool16 GetPMRect(
PMRect &v)
const;
243 bool16 GetPMMatrix(
PMMatrix &v)
const;
244 bool16 GetNameInfo(NameInfo &v)
const;
245 bool16 GetDataBlob(DataBlob **v)
const;
247 bool16 GetURI(
URI &v)
const;
249 void SetInt16(int16 v)
251 ASSERT(fType == kInt16);
256 bool16 CopyValue(
const FieldValue &other);
258 bool16 operator==(
const FieldValue& other)
const;
259 FieldValue & operator=(
const FieldValue &other);
278 NameInfo * dNameInfo;
279 DataBlob * dDataBlob;
285 static void SetUnionType(FieldType newT, ValueUnion &v, FieldType oldT = kInvalidField);
286 static void ClearUnion(FieldType t, ValueUnion &v)
287 {SetUnionType(kInvalidField, v, t);}
288 static bool16 ConvertValue(FieldType sType,
const ValueUnion &sValue, FieldType tType, ValueUnion &tValue);
289 static bool16 ConvertBool8(bool8 sValue, FieldType tType, ValueUnion &tValue);
290 static bool16 ConvertBool16(bool16 sValue, FieldType tType, ValueUnion &tValue);
291 static bool16 ConvertInt8(int8 sValue, FieldType tType, ValueUnion &tValue);
292 static bool16 ConvertUint8(uint8 sValue, FieldType tType, ValueUnion &tValue);
293 static bool16 ConvertInt16(int16 sValue, FieldType tType, ValueUnion &tValue);
294 static bool16 ConvertUint16(uint16 sValue, FieldType tType, ValueUnion &tValue);
295 static bool16 ConvertInt32(int32 sValue, FieldType tType, ValueUnion &tValue);
296 static bool16 ConvertUint32(uint32 sValue, FieldType tType, ValueUnion &tValue);
297 static bool16 ConvertReal(
const PMReal &sValue, FieldType tType, ValueUnion &tValue);
298 static bool16 ConvertID(uint32 sValue, FieldType tType, ValueUnion &tValue);
299 static bool16 ConvertPMString(
const PMString &sValue, FieldType tType, ValueUnion &tValue);
325 typedef uint32 InstanceValue;
332 : fValueList(other.fValueList)
335 void PushLevel(InstanceValue v = 0)
336 {fValueList.push_back(v);}
338 {fValueList.pop_back();}
339 void SetValue(InstanceValue v)
340 {fValueList.back() = v;};
342 bool16 operator==(
const Instance& other)
const 343 {
return (fValueList == other.fValueList);}
344 bool16 operator<(
const Instance& other)
const;
347 {fValueList = other.fValueList;
return *
this;}
368 FieldKey(FieldID
id = kInvalidFieldID)
369 : fID(
id), fInstance()
372 : fID(
id), fInstance(i)
375 : fID(other.fID), fInstance(other.fInstance)
378 FieldID GetID()
const 382 bool16 IsValid()
const 383 {
return fID != kInvalidFieldID;}
385 void SetID(FieldID
id)
390 {SetID(kInvalidFieldID);}
392 bool16 operator<(
const FieldKey &other)
const 393 {
return (fID == other.fID) ? (fInstance < other.fInstance) : (fID < other.fID);}
394 bool16 operator==(
const FieldKey &other)
const 395 {
return ((fID == other.fID) && (fInstance == other.fInstance));}
398 {fID = other.fID; fInstance = other.fInstance;
return *
this;}
420 : fKey(kInvalidFieldID), fType(kInvalidField)
423 : fKey(
id), fType(kInvalidField)
426 : fKey(kInvalidFieldID), fType(kInvalidField)
428 Field(FieldID
id,
const Instance &instance, FieldType type = kInvalidField)
429 : fKey(
id, instance), fType(type)
432 : fType(other.fType), fKey(other.fKey), fValueList(other.fValueList)
435 : fType(other.fType), fKey(other.fKey.GetID(), instance), fValueList(other.fValueList)
439 void ReadWrite(
IPMStream *s, uint32 skipCount = 0, uint32 getCount = kMaxUInt32);
440 bool16 CopyValue(
const Field &other, uint32 skipCount = 0, uint32 getCount = kMaxUInt32);
444 FieldType GetType()
const 447 uint32 GetValueCount()
const 448 {
return fValueList.size();}
449 ValueVector::const_iterator Begin()
const 450 {
return fValueList.begin();}
451 ValueVector::const_iterator End()
const 452 {
return fValueList.end();}
455 bool16 operator==(
const Field& other)
const 456 {
return ((fType == other.fType) && (fKey == other.fKey) && (fValueList == other.fValueList));}
458 {fType = other.fType; fKey = other.fKey; fValueList = other.fValueList;
return *
this;}
463 void ReadDefaultValue(FieldType t,
IPMStream *s);
488 : fFieldList(other.fFieldList)
493 FieldVector::const_iterator GetBeginIterator()
const 494 {
return fFieldList.begin();}
495 FieldVector::const_iterator GetEndIterator()
const 496 {
return fFieldList.end();}
498 bool16 IsEmpty()
const 499 {
return (fFieldList.size() < 2);}
500 bool16 ContainsFieldType(FieldType type)
const;
502 bool16 operator==(
const Schema& other)
const 503 {
return (fFieldList == other.fFieldList);}
504 bool16 operator!=(
const Schema& other)
const 505 {
return !(*
this == other);}
508 {fFieldList = other.fFieldList;
return *
this;}
511 void ProcessFields(int16 count,
IPMStream *s);
533 : fIsClass(kFalse), fIDValue(0)
536 : fIsClass(kTrue), fIDValue(
id.Get()), fVersion(version)
539 : fIsClass(kFalse), fIDValue(
id.Get()), fVersion(version)
544 bool16 AppliesTo(
ClassID id)
const 545 {
return AppliesTo(kTrue,
id.Get());}
547 {
return AppliesTo(kFalse,
id.Get());}
548 bool16 AppliesTo(bool16 isClass, uint32 idValue)
const 549 {
return (fIsClass == isClass) && (idValue == fIDValue);}
552 {
return Below(kTrue,
id.Get());}
554 {
return Below(kFalse,
id.Get());}
555 bool16 Below(bool16 isClass, uint32 idValue)
const 556 {
return (fIsClass == isClass) ? (fIDValue < idValue) : (fIsClass < isClass);}
559 {
return Above(kTrue,
id.Get());}
561 {
return Above(kFalse,
id.Get());}
562 bool16 Above(bool16 isClass, uint32 idValue)
const 563 {
return (fIsClass == isClass) ? (fIDValue > idValue) : (fIsClass > isClass);}
565 uint32 GetIDValue()
const 567 const Version &GetVersion()
const 569 const Schema &GetSchema()
const 576 bool16 operator==(
const SchemaInfo &other)
const;
577 bool16 operator<(
const SchemaInfo &other)
const;
581 {fIsClass = other.fIsClass; fIDValue = other.fIDValue;
582 fVersion = other.fVersion; fSchema = other.fSchema;}
607 : fIsClass(
false), fIDValue(0), fFormat(), fSchemaInfo(nil)
610 : fIsClass(
true), fIDValue(clsID.Get()), fFormat(format), fSchemaInfo(info)
613 : fIsClass(
false), fIDValue(implID.Get()), fFormat(format), fSchemaInfo(info)
616 : fIsClass(isClass), fIDValue(idValue), fFormat(format), fSchemaInfo(info)
621 const Schema * GetSchema()
const 622 {
return (fSchemaInfo == nil) ? nil : &fSchemaInfo->GetSchema();}
625 {
return ((fIsClass == other.fIsClass) && (fIDValue == other.fIDValue) && (fFormat == other.fFormat));}
628 {Copy(other);
return *
this;}
632 {fIsClass = other.fIsClass; fIDValue = other.fIDValue;
633 fFormat = other.fFormat; fSchemaInfo = other.fSchemaInfo;}
658 : fType(type), fVersion(version)
661 virtual int16 GetType()
const 663 virtual const Version & GetVersion()
const 689 :
Directive(type, version), fOldClassID(classID), fNewClassID(kInvalidClass)
692 :
Directive(type, version), fOldClassID(oldClassID), fNewClassID(newClassID)
696 {
return fOldClassID;}
698 {
return fOldClassID;}
700 {
return fNewClassID;}
723 :
Directive(type, version), fContext(context), fOldImplID(implID), fNewImplID(kInvalidImpl)
726 :
Directive(type, version), fContext(context), fOldImplID(oldImplID), fNewImplID(newImplID)
762 :
Directive(type, myVersion), fFromID(fromID), fFromVersion(fromVersion), fToID(toID), fToVersion(toVersion)
769 const Version & GetFromVersion()
const 770 {
return fFromVersion;}
771 const Version & GetToVersion()
const 775 {ASSERT_FAIL(
"appease K2Vector.Location");
return false;}
805 :
Directive(type, myVersion), fFromVersion(fromVersion), fToVersion(toVersion)
809 {
return fFromVersion.GetPluginID();}
831 PathStep(int32 version, int32 predecessor)
832 : fVersion(version), fPredecessor(predecessor)
835 int32 GetVersion()
const 837 int32 GetPredecessor()
const 838 {
return fPredecessor;}
840 bool16 operator==(
const PathStep& other)
const 841 {
return ((fVersion == other.fVersion) && (fPredecessor == other.fPredecessor));}
864 : fProvider(provider), fBoss(boss), fTag(tag)
867 : fProvider(d.GetVersion().GetPluginID()), fBoss(d.GetClassID()), fTag(kInvalidImpl)
870 : fProvider(d.GetVersion().GetPluginID()), fBoss(d.GetContext()), fTag(d.GetImplID())
881 {
return ((fProvider == other.fProvider) && (fBoss == other.fBoss) && (fTag == other.fTag));}
913 : fMode(kDontConvert), fIDValue(0), fContextValue(0), fConversionIndex(-1), fSourceInfo(), fTargetInfo(), fNewIDValue(0)
916 : fMode(kDontConvert), fIsClass(kFalse),fIDValue(impl.Get()), fContextValue(context.Get()), fConversionIndex(cIndex), fSourceInfo(), fTargetInfo(), fNewIDValue(0)
919 : fMode(kDontConvert), fIsClass(kTrue),fIDValue(cls.Get()), fContextValue(context.Get()), fConversionIndex(cIndex), fSourceInfo(), fTargetInfo(), fNewIDValue(0)
921 ConvertInfo(bool16 isClass, uint32 idValue, uint32 contextValue, int32 cIndex)
922 : fMode(kDontConvert), fIsClass(isClass),fIDValue(idValue), fContextValue(contextValue), fConversionIndex(cIndex), fSourceInfo(), fTargetInfo(), fNewIDValue(0)
926 const SchemaInfo * GetSourceSchemaInfo()
const 927 {
return fSourceInfo;}
928 const SchemaInfo * GetTargetSchemaInfo()
const 929 {
return fTargetInfo;}
930 uint32 GetNewID()
const 931 {
return fNewIDValue;}
935 void SetReplace(uint32 newIDValue)
936 {fMode = kReplace; fNewIDValue = newIDValue;}
938 {fMode = kConvert; fSourceInfo = sInfo; fTargetInfo = tInfo;}
939 bool16 NoConversion()
const 940 {
return (fMode == kDontConvert);}
941 bool16 ShouldRemove()
const 942 {
return (fMode == kRemove);}
943 bool16 ShouldReplace()
const 944 {
return (fMode == kReplace);}
945 bool16 ShouldConvert()
const 946 {
return (fMode == kConvert);}
957 uint32 fContextValue;
958 int32 fConversionIndex;
983 void AppendField(
const Field &f);
990 void AppendAttributeBossList(FieldID
id, FieldType countType,
993 bool16 IsEmpty()
const 994 {
return fFieldList.empty();}
996 FieldVector::iterator Begin()
997 {
return fFieldList.begin();}
998 FieldVector::iterator End()
999 {
return fFieldList.end();}
1001 bool16 HasError()
const 1002 {
return fErrorFieldKey.IsValid();}
1015 virtual ~ValueSource()
1018 virtual bool16 GetValue(
Field &f, uint32 skipCount = 0, uint32 getCount = kMaxUInt32) = 0;
1021 class StreamValueSource :
public ValueSource
1027 virtual ~StreamValueSource()
1030 virtual bool16 GetValue(
Field &f, uint32 skipCount, uint32 getCount);
1036 class DataValueSource :
public ValueSource
1042 virtual ~DataValueSource()
1045 virtual bool16 GetValue(
Field &f, uint32 skipCount, uint32 getCount);
1054 typedef std::map<FieldKey, const Field *> FieldIDMap;
1057 void Initialize(
const Schema &schema, ValueSource &vs);
1058 FieldVector::const_iterator ProcessFields(
Instance &inst, int16 count, FieldVector::const_iterator pF, ValueSource &vs);
1059 FieldVector::const_iterator ProcessSimpleField(
Instance &inst, FieldVector::const_iterator pF, ValueSource &vs);
1060 FieldVector::const_iterator ProcessFieldArray(
Instance &inst, FieldVector::const_iterator pF, ValueSource &vs);
1061 FieldVector::const_iterator ProcessAttributeBoss(
Instance &inst, FieldVector::const_iterator pF, ValueSource &vs);
1062 FieldVector::const_iterator ProcessAttributeBossList(
Instance &inst, FieldVector::const_iterator pF, ValueSource &vs);
1063 FieldVector::const_iterator SkipFields(int16 count, FieldVector::const_iterator pF);
1064 FieldVector::const_iterator SkipFieldArray(FieldVector::const_iterator pF);
1066 const Field *FindFieldInList(
Field &goal)
const;
1067 const Field *FindFieldInMap(
Field &goal)
const;
1072 bool16 fMappingDecisionMade;
1073 FieldIDMap fFieldMap;
1092 : fPluginID(kInvalidPlugin)
1095 {BuildSchemaList(p);}
1098 {BuildSchemaList(p);}
1104 bool16 HasSchemas(
ClassID id)
const 1105 {
return HasSchemas(kTrue,
id.Get());}
1107 {
return HasSchemas(kFalse,
id.Get());}
1108 bool16 HasSchemas(bool16 isClass, uint32 idValue)
const;
1111 {
return FindClosestSchema(kTrue,
id.Get(), version, path);}
1113 {
return FindClosestSchema(kFalse,
id.Get(), version, path);}
1121 bool IndividualSchemaStreamCallback(
IDResource r,
void* userData);
1122 bool SchemaListStreamCallback(
IDResource r,
void* userData);
1123 bool VersionListResourceCallback(
IDResource r,
void* userData);
1143 : fPluginID(kInvalidPlugin)
1146 {BuildDirectiveList(p);}
1148 {ClearDirectiveList();}
1151 {BuildDirectiveList(p);}
1158 {GetPluginVersions(kInvalidPlugin, dirType, v);}
1165 bool DirectiveListCallback(
IDResource r,
void* userData);
1166 void BuildDirectiveList(
PluginID p);
1167 void ClearDirectiveList();
1187 : fPluginID(kInvalidPlugin)
1198 {
return FindPath(fromVersion, toVersion, &list);}
1199 bool16 PathExists(int32 fromVersion, int32 toVersion)
const 1200 {
return FindPath(fromVersion, toVersion);}
1207 bool StepListCallback(
IDResource r,
void* userData);
1209 void AddImplicitSteps(int32 fromVersion, int32 toVersion)
const;
1210 bool16 ExplicitStepsExist(int32 version)
const;
1214 {
if (list != nil) list->clear();}
1216 {
if (list != nil) {
if (reversed) list->insert(list->begin(), step);
else list->push_back(step);}}
1218 {
if (list != nil) {
if (reversed) list->erase(list->begin());
else list->pop_back();}}
1221 static Schemas::MajorFormatVector::const_iterator FindInPath(Schemas::MajorFormatVector::const_iterator pStart,
1222 Schemas::MajorFormatVector::const_iterator pEnd, int32 majorVersion);
1244 {CollectPlugins(versions);}
1250 {CollectPlugins(versions);}
1252 {BuildDirectiveList(dm);}
1254 int32 CountPlugins()
const 1255 {
return fPluginList.size();}
1256 PluginID GetNthPlugin(int32 n)
const;
1259 int32 CountRemovedPlugins(
const VersionID &fromVersion,
const VersionID &toVersion)
const;
1261 int32 CountIgnoredPlugins(
const VersionID &fromVersion,
const VersionID &toVersion)
const;
1278 #endif // __SchemaUtils__