CLAM-Development  1.4.0
SDIFType.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #ifndef __SDIFType__
23 #define __SDIFType__
24 
25 
26 #include <string.h>
27 #include "DataTypes.hxx"
28 
29 namespace SDIF
30 {
31 
36  class TypeId
37  {
38  friend class File;
39  protected:
42  public:
46  TypeId(const char* str = "\0\0\0\0")
47  {
48  memcpy(mData,str,4);
49  }
54  bool operator == (const TypeId& cmp) { return !memcmp(mData,cmp.mData,4); }
55 
58  const char* String(void) const
59  {
60  static char str[5];
61  memcpy(str,mData,4);
62  str[4]='\0';
63  return str;
64  }
65 
66  static TypeId sDefault;
67  };
68 
69  enum DataType
70  {
71  eUnknown = 0,
72  eFloat32 = 0x4, // 32-bit big-endian IEEE 754 float, 4 bytes
73  eFloat64 = 0x8, // 64-bit big-endian IEEE 754 float, 8 bytes
74  eInt32 = 0x104, // 32-bit big-endian two's complement integer, 4 bytes
75  eInt64 = 0x108, // 64-bit big-endian two's complement integer, 8 bytes
76  eUint42 = 0x204, // 32-bit big-endian unsigned integer, 4 bytes
77  eUTF8byte = 0x301, // Byte of UTF8-encoded text, 1 bytes
78  eByte = 0x401 // Arbitrary byte, 1 bytes
79  };
80 
81  template <class T> class GetType
82  {
83  public:
84  static DataType Get(void) { return eUnknown; }
85  };
86 
87  class TUTF8byte
88  {
89  public:
90  char c;
91  };
92 
93  template <> class GetType<CLAM::TFloat32>{public:static DataType Get(void){return eFloat32;}};
94  template <> class GetType<CLAM::TFloat64>{public:static DataType Get(void){return eFloat64;}};
95  template <> class GetType<CLAM::TInt32>{public:static DataType Get(void){return eInt32;}};
96  template <> class GetType<CLAM::TInt64>{public:static DataType Get(void){return eInt64;}};
97  template <> class GetType<TUTF8byte>{public:static DataType Get(void){return eUTF8byte;}};
98  template <> class GetType<CLAM::TByte>{public:static DataType Get(void){return eByte;}};
99 
100 }
101 #endif
102