2 Copyright (c) 2005-2006, John Hurst
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. The name of the author may not be used to endorse or promote products
14 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 /*! \file Identifier.h
29 \brief strings of bytes that identify things
32 #ifndef _IDENTIFIER_H_
33 #define _IDENTIFIER_H_
37 // the base of all identifier classes
38 template <ui32_t SIZE>
39 class Identifier : public IArchive
46 memset(m_Value, 0, SIZE);
50 inline Result_t Set(const byte_t* value) {
51 ASDCP_TEST_NULL(value);
52 memcpy(m_Value, value, SIZE);
57 inline Result_t ReadFrom(ASDCP::MemIOReader& Reader) {
58 Reader.ReadRaw(m_Value, SIZE);
63 inline Result_t WriteTo(ASDCP::MemIOWriter& Writer) {
64 Writer.WriteRaw(m_Value, SIZE);
68 inline const byte_t* Data() const { return m_Value; }
70 inline ui32_t Size() const { return SIZE; }
73 inline bool operator<(const Identifier& rhs) const
75 for ( ui32_t i = 0; i < SIZE; i++ )
77 if ( m_Value[i] != rhs.m_Value[i] )
78 return m_Value[i] < rhs.m_Value[i];
85 inline bool operator==(const Identifier& rhs) const
87 if ( rhs.Size() != SIZE )
90 return ( memcmp(m_Value, rhs.m_Value, SIZE) == 0 );
94 // todo: refactor characrer insertion back to bin2hex()
95 const char* ToString(char* str_buf) const
99 for ( ui32_t i = 0; i < SIZE; i++ )
101 *p = (m_Value[i] >> 4) & 0x0f;
102 *p += *p < 10 ? 0x30 : 0x61 - 10;
105 *p = m_Value[i] & 0x0f;
106 *p += *p < 10 ? 0x30 : 0x61 - 10;
122 // UID - either a UL or a UUID
123 class UID : public Identifier<SMPTE_UL_LENGTH>
125 friend class ASDCP::UL;
126 friend class ASDCP::UUID;
130 UID(const UID& rhs) {
131 memcpy(m_Value, rhs.m_Value, SMPTE_UL_LENGTH);
136 class UL : public Identifier<SMPTE_UL_LENGTH>
141 memcpy(m_Value, rhs.m_Value, SMPTE_UL_LENGTH);
145 memcpy(m_Value, rhs.m_Value, SMPTE_UL_LENGTH);
148 UL(const byte_t* value) {
150 memcpy(m_Value, value, SMPTE_UL_LENGTH);
153 bool operator==(const UL& rhs) const {
154 return ( memcmp(m_Value, rhs.m_Value, SMPTE_UL_LENGTH) == 0 ) ? true : false;
159 class UUID : public Identifier<SMPTE_UL_LENGTH>
163 UUID(const UUID& rhs) {
164 memcpy(m_Value, rhs.m_Value, SMPTE_UL_LENGTH);
167 UUID(const UID& rhs) {
168 memcpy(m_Value, rhs.m_Value + 8, 8);
169 memcpy(m_Value + 8, rhs.m_Value, 8);
172 void GenRandomValue();
176 class UMID : public Identifier<SMPTE_UMID_LENGTH>
180 UMID(const UMID &rhs) {
181 memcpy(m_Value, rhs.m_Value, SMPTE_UMID_LENGTH);
184 void MakeUMID(int Type);
186 void MakeUMID(int Type, const UUID& ID);
188 void SetMaterial(UL& aUL);
190 void SetInstance(int Instance, int Method = -1);
192 ui32_t GetInstance(void) const
195 return ( m_Value[13] << 16 ) | ( m_Value[14] << 8 ) | m_Value[15];
199 } // namespace mxflib
201 #endif // _IDENTIFIER_H_