summaryrefslogtreecommitdiff
path: root/src/MXFTypes.h
diff options
context:
space:
mode:
authorjhurst <jhurst@cinecert.com>2015-10-09 23:41:11 +0000
committerjhurst <>2015-10-09 23:41:11 +0000
commitf758bec505d45084d2563f20514ab4a81b27283a (patch)
treec04eca066f94030702476d1a2801e372658bf93c /src/MXFTypes.h
parent2bf9e844a7eb0e22e9fc4fe4d152ad9a4818dfcf (diff)
o General review of Batch/Array distinction throughout the project
o Fixed a bug that caused incorrect failure when parsing JPEG 2000 codestreams having fewer than five decomposition levels. o Fixed missing UUID generation in some instances of the MCALinkID property o Added -w option to asdcp-wrap to support use of WTF label with MCA
Diffstat (limited to 'src/MXFTypes.h')
-rwxr-xr-xsrc/MXFTypes.h186
1 files changed, 54 insertions, 132 deletions
diff --git a/src/MXFTypes.h b/src/MXFTypes.h
index f49ef8b..701dfa1 100755
--- a/src/MXFTypes.h
+++ b/src/MXFTypes.h
@@ -35,6 +35,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "KLV.h"
#include <list>
#include <vector>
+#include <set>
#include <map>
#include <wchar.h>
@@ -96,46 +97,32 @@ namespace ASDCP
};
//
- template <class T>
- class Batch : public std::vector<T>, public Kumu::IArchive
+ template <class ContainerType>
+ class FixedSizeItemCollection : public ContainerType, public Kumu::IArchive
{
public:
- Batch() {}
- virtual ~Batch() {}
+ FixedSizeItemCollection() {}
+ virtual ~FixedSizeItemCollection() {}
- inline virtual bool HasValue() const { return ! this->empty(); }
+ ui32_t ItemSize() const {
+ typename ContainerType::value_type tmp_item;
+ return tmp_item.ArchiveLength();
+ }
- virtual ui32_t ArchiveLength() const {
- ui32_t arch_size = sizeof(ui32_t) * 2;
- typename std::vector<T>::const_iterator i;
+ bool HasValue() const { return ! this->empty(); }
- for ( i = this->begin(); i != this->end(); ++i )
- {
- arch_size += i->ArchiveLength();
- }
-
- return arch_size;
+ ui32_t ArchiveLength() const {
+ return ( sizeof(ui32_t) * 2 ) + ( this->size() * this->ItemSize() );
}
- //
- virtual bool Archive(Kumu::MemIOWriter* Writer) const {
+ bool Archive(Kumu::MemIOWriter* Writer) const {
if ( ! Writer->WriteUi32BE(this->size()) ) return false;
- byte_t* p = Writer->CurrentData();
-
- if ( ! Writer->WriteUi32BE(0) ) return false;
+ if ( ! Writer->WriteUi32BE(this->ItemSize()) ) return false;
if ( this->empty() ) return true;
- typename std::vector<T>::const_iterator i = this->begin();
- assert(i != this->end());
-
- ui32_t ItemSize = Writer->Remainder();
- if ( ! i->Archive(Writer) ) return false;
- ItemSize -= Writer->Remainder();
- Kumu::i2p<ui32_t>(KM_i32_BE(ItemSize), p);
- ++i;
-
+ typename ContainerType::const_iterator i;
bool result = true;
- for ( ; i != this->end() && result; ++i )
+ for ( i = this->begin(); i != this->end() && result; ++i )
{
result = i->Archive(Writer);
}
@@ -144,141 +131,76 @@ namespace ASDCP
}
//
- virtual bool Unarchive(Kumu::MemIOReader* Reader) {
+ bool Unarchive(Kumu::MemIOReader* Reader) {
ui32_t item_count, item_size;
if ( ! Reader->ReadUi32BE(&item_count) ) return false;
if ( ! Reader->ReadUi32BE(&item_size) ) return false;
-
- if ( ( item_count > 65536 ) || ( item_size > 1024 ) )
- {
- return false;
- }
+ if ( this->ItemSize() != item_size ) return false;
bool result = true;
for ( ui32_t i = 0; i < item_count && result; ++i )
{
- T Tmp;
- result = Tmp.Unarchive(Reader);
+ typename ContainerType::value_type tmp_item;
+ result = tmp_item.Unarchive(Reader);
if ( result )
{
- this->push_back(Tmp);
+ this->push_back(tmp_item);
}
}
return result;
}
- //
- void Dump(FILE* stream = 0, ui32_t depth = 0)
- {
- char identbuf[IdentBufferLen];
+ void Dump(FILE* stream = 0, ui32_t depth = 0) {
+ char identbuf[IdentBufferLen];
- if ( stream == 0 )
- stream = stderr;
-
- typename std::vector<T>::iterator i = this->begin();
- for ( ; i != this->end(); i++ )
- fprintf(stream, " %s\n", (*i).EncodeString(identbuf, IdentBufferLen));
- }
- };
-
- //
- template <class T>
- class Array : public std::list<T>, public Kumu::IArchive
- {
- public:
- Array() {}
- virtual ~Array() {}
-
- inline virtual bool HasValue() const { return ! this->empty(); }
-
- virtual ui32_t ArchiveLength() const {
- ui32_t arch_size = sizeof(ui32_t) * 2;
- typename std::list<T>::const_iterator i;
-
- for ( i = this->begin(); i != this->end(); ++i )
+ if ( stream == 0 )
{
- arch_size += i->ArchiveLength();
+ stream = stderr;
}
-
- return arch_size;
- }
-
- //
- virtual bool Archive(Kumu::MemIOWriter* Writer) const {
- if ( ! Writer->WriteUi32BE(this->size()) ) return false;
- byte_t* p = Writer->CurrentData();
-
- if ( ! Writer->WriteUi32BE(0) ) return false;
- if ( this->empty() ) return true;
- typename std::list<T>::const_iterator i = this->begin();
- assert(i != this->end());
-
- ui32_t ItemSize = Writer->Remainder();
- if ( ! i->Archive(Writer) ) return false;
- ItemSize -= Writer->Remainder();
- Kumu::i2p<ui32_t>(KM_i32_BE(ItemSize), p);
- ++i;
-
- bool result = true;
- for ( ; i != this->end() && result; ++i )
+ typename ContainerType::const_iterator i;
+ for ( i = this->begin(); i != this->end(); ++i )
{
- result = i->Archive(Writer);
+ fprintf(stream, " %s\n", (*i).EncodeString(identbuf, IdentBufferLen));
}
-
- return result;
}
+ };
- //
- virtual bool Unarchive(Kumu::MemIOReader* Reader) {
- ui32_t item_count, item_size;
- if ( ! Reader->ReadUi32BE(&item_count) ) return false;
- if ( ! Reader->ReadUi32BE(&item_size) ) return false;
-
- if ( ( item_count > 65536 ) || ( item_size > 1024 ) )
- {
- return false;
- }
-
- bool result = true;
- for ( ui32_t i = 0; i < item_count && result; ++i )
- {
- T Tmp;
- result = Tmp.Unarchive(Reader);
-
- if ( result )
- {
- this->push_back(Tmp);
- }
- }
-
- return result;
- }
-
- //
- void Dump(FILE* stream = 0, ui32_t depth = 0)
- {
- char identbuf[IdentBufferLen];
+ template <class item_type>
+ class PushSet : public std::set<item_type>
+ {
+ public:
+ PushSet() {}
+ virtual ~PushSet() {}
+ void push_back(const item_type& item) { this->insert(item); }
+ };
- if ( stream == 0 )
- stream = stderr;
+ template <class ItemType>
+ class Batch : public FixedSizeItemCollection<PushSet<ItemType> >
+ {
+ public:
+ Batch() {}
+ virtual ~Batch() {}
+ };
- typename std::list<T>::iterator i = this->begin();
- for ( ; i != this->end(); i++ )
- fprintf(stream, " %s\n", (*i).EncodeString(identbuf, IdentBufferLen));
- }
- };
+ template <class ItemType>
+ class Array : public FixedSizeItemCollection<std::vector<ItemType> >
+ {
+ public:
+ Array() {}
+ virtual ~Array() {}
+ };
//
template <class T>
- class HeadlessArray : public std::list<T>, public Kumu::IArchive
+ class SimpleArray : public std::list<T>, public Kumu::IArchive
{
public:
- HeadlessArray() {}
- virtual ~HeadlessArray() {}
+ SimpleArray() {}
+ virtual ~SimpleArray() {}
//
virtual bool Unarchive(Kumu::MemIOReader* Reader)