00001 00010 /* 00011 * Copyright (c) 2003, Matt Beard 00012 * Portions Copyright (c) 2003, Metaglue Corporation 00013 * 00014 * This software is provided 'as-is', without any express or implied warranty. 00015 * In no event will the authors be held liable for any damages arising from 00016 * the use of this software. 00017 * 00018 * Permission is granted to anyone to use this software for any purpose, 00019 * including commercial applications, and to alter it and redistribute it 00020 * freely, subject to the following restrictions: 00021 * 00022 * 1. The origin of this software must not be misrepresented; you must 00023 * not claim that you wrote the original software. If you use this 00024 * software in a product, an acknowledgment in the product 00025 * documentation would be appreciated but is not required. 00026 * 00027 * 2. Altered source versions must be plainly marked as such, and must 00028 * not be misrepresented as being the original software. 00029 * 00030 * 3. This notice may not be removed or altered from any source 00031 * distribution. 00032 */ 00033 #ifndef MXFLIB__PARTITION_H 00034 #define MXFLIB__PARTITION_H 00035 00036 #include <mxflib/primer.h> 00037 00038 #include <list> 00039 00040 namespace mxflib 00041 { 00042 // Forward declare so the class can include pointers to itself 00043 class Partition; 00044 class PartitionPtr; 00045 00047 class PartitionPtr : public SmartPtr<Partition> 00048 { 00049 public: 00050 PartitionPtr() : SmartPtr<Partition>() {}; 00051 // PartitionPtr(Partition * ptr) : SmartPtr<Partition>(ptr) {}; 00052 // PartitionPtr(MDObjectPtr ptr) : SmartPtr<Partition>((Partition *)ptr.GetPtr()) {}; 00053 PartitionPtr(IRefCount<Partition> * ptr) : SmartPtr<Partition>(ptr) {}; 00054 00056 MDObjectPtr operator[](const char *ChildName); 00057 MDObjectPtr operator[](MDOTypePtr ChildType); 00058 MDObjectPtr operator[](const UL &ChildType); 00059 MDObjectPtr operator[](ULPtr &ChildType); 00060 }; 00061 00063 class PartitionParent : public ParentPtr<Partition> 00064 { 00065 public: 00066 PartitionParent() : ParentPtr<Partition>() {}; 00067 PartitionParent(IRefCount<Partition> * ptr) : ParentPtr<Partition>(ptr) {}; 00068 00070 MDObjectPtr operator[](const char *ChildName); 00071 MDObjectPtr operator[](MDOTypePtr ChildType); 00072 MDObjectPtr operator[](const UL &ChildType); 00073 MDObjectPtr operator[](ULPtr &ChildType); 00074 }; 00075 00077 typedef std::list<PartitionPtr> PartitionList; 00078 } 00079 00080 namespace mxflib 00081 { 00083 class Partition : public ObjectInterface, public RefCount<Partition> 00084 { 00085 public: 00086 PrimerPtr PartitionPrimer; 00087 00092 MDObjectList AllMetadata; 00093 MDObjectList TopLevelMetadata; 00094 00095 private: 00096 std::map<UUID, MDObjectPtr> RefTargets; 00097 std::multimap<UUID, MDObjectPtr> UnmatchedRefs; 00098 00099 public: 00100 Partition(const char *BaseType) { Object = new MDObject(BaseType); }; 00101 Partition(MDOTypePtr BaseType) { Object = new MDObject(BaseType); }; 00102 Partition(const UL &BaseUL) { Object = new MDObject(BaseUL); }; 00103 Partition(ULPtr BaseUL) { Object = new MDObject(*BaseUL); }; 00104 00106 void UpdateMetadata(ObjectInterface *NewObject) { ClearMetadata(); AddMetadata(NewObject->Object); }; 00107 00109 void UpdateMetadata(MDObjectPtr NewObject) { ClearMetadata(); AddMetadata(NewObject); }; 00110 00112 00113 void AddMetadata(ObjectInterface *NewObject) { AddMetadata(NewObject->Object); }; 00114 void AddMetadata(MDObjectPtr NewObject); 00115 00117 void ClearMetadata(void) 00118 { 00119 PartitionPrimer = NULL; 00120 AllMetadata.clear(); 00121 TopLevelMetadata.clear(); 00122 RefTargets.clear(); 00123 UnmatchedRefs.clear(); 00124 } 00125 00127 Length ReadMetadata(void); 00128 00130 Length ReadMetadata(MXFFilePtr File, Length Size); 00131 00133 MetadataPtr ParseMetadata(void); 00134 00136 MDObjectListPtr ReadIndex(void); 00137 00139 MDObjectListPtr ReadIndex(MXFFilePtr File, UInt64 Size); 00140 00142 00144 bool ReadIndex(IndexTablePtr Table); 00145 00147 DataChunkPtr ReadIndexChunk(void); 00148 00150 void SetKAG(UInt64 KAG) 00151 { 00152 MDObjectPtr Ptr = Object[KAGSize_UL]; 00153 ASSERT(Ptr); 00154 Ptr->SetUInt64(KAG); 00155 } 00156 00157 // Access functions for the reference resolving properties 00158 // DRAGONS: These should be const, but can't make it work! 00159 std::map<UUID, MDObjectPtr>& GetRefTargets(void) { return RefTargets; }; 00160 std::multimap<UUID, MDObjectPtr>& GetUnmatchedRefs(void) { return UnmatchedRefs; }; 00161 00163 bool IsComplete(void); 00164 00166 bool IsClosed(void); 00167 00169 00173 bool IsMetadataComplete(void) 00174 { 00175 warning("Partition::IsMetadataComplete() not yet implemented\n"); 00176 return false; 00177 } 00178 00180 bool SeekEssence(void); 00181 00183 MDObjectParent FindLinkParent(MDObjectPtr &Child); 00184 00186 MDObjectParent FindLinkParent(MDObjectParent &Child) 00187 { 00188 MDObjectPtr Obj = &(*Child); 00189 return FindLinkParent(Obj); 00190 } 00191 00192 // Sequential access to the Elements of the Body 00193 00194 public: 00195 // goto start of body...set the member variables _BodyLocation, _NextBodyLocation 00196 bool StartElements(); 00197 // goto _NextBodyLocation 00198 KLVObjectPtr NextElement(); 00199 // skip over a KLV packet 00200 00201 protected: 00202 UInt64 Skip( UInt64 start ); 00203 // skip over any KLVFill 00204 // DRAGONS: does not iterate - only copes with single KLVFill 00205 UInt64 SkipFill( UInt64 start ); 00206 00207 private: 00208 UInt64 _BodyLocation; // file position for current Element 00209 UInt64 _NextBodyLocation; // file position for Element after this 00210 00211 private: 00212 void ProcessChildRefs(MDObjectPtr ThisObject); 00213 }; 00214 } 00215 00216 // These simple inlines need to be defined after Partition 00217 namespace mxflib 00218 { 00219 inline MDObjectPtr PartitionPtr::operator[](const char *ChildName) { return GetPtr()->Object[ChildName]; } 00220 inline MDObjectPtr PartitionPtr::operator[](MDOTypePtr ChildType) { return GetPtr()->Object[ChildType]; } 00221 inline MDObjectPtr PartitionPtr::operator[](const UL &ChildType) { return GetPtr()->Object[ChildType]; } 00222 inline MDObjectPtr PartitionPtr::operator[](ULPtr &ChildType) { return GetPtr()->Object[*ChildType]; } 00223 } 00224 00225 #endif // MXFLIB__PARTITION_H