Sample: cleaning up Inheritance
[io/quag.git] / libs / basekit / source / BStreamTag.c
blobd83f5f021996c49ab06695c8ad7d782945cbe7b9
1 /*#io
2 docCopyright("Steve Dekorte", 2004)
3 docLicense("BSD revised") *
4 */
6 #include "BStreamTag.h"
7 #include <stdio.h>
9 /*
10 unsigned int isArray : 1;
11 unsigned int type : 2;
12 unsigned int byteCount : 5;
13 */
15 BStreamTag BStreamTag_FromUnsignedChar(unsigned char c)
17 // we need to do this because bit fields are compiler dependent
18 BStreamTag t;
19 t.isArray = c >> 7;
20 t.type = ( c << 1) >> 6;
21 t.byteCount = ( c << 3 ) >> 3;
22 return t;
25 unsigned char BStreamTag_asUnsignedChar(BStreamTag *self)
27 BStreamTag t = *self;
28 unsigned char c = 0;
29 c = c | t.isArray << 7;
30 c = c | t.type << 5;
31 c = c | t.byteCount;
32 return c;
35 // -----------------------------------------------------
37 BStreamTag BStreamTag_TagArray_type_byteCount_(unsigned int a, unsigned int t, unsigned int b)
39 BStreamTag self;
40 self.isArray = a;
41 self.type = t;
42 self.byteCount = b;
43 return self;
46 int BStreamTag_isEqual_(BStreamTag *self, BStreamTag *other)
48 return (BStreamTag_asUnsignedChar(self) == BStreamTag_asUnsignedChar(other));
51 void BStreamTag_print(BStreamTag *self)
53 printf("[Tag ");
54 printf("isArray: %i ", self->isArray);
55 printf("type: %i ", self->type);
56 printf("byteCount: %i", self->byteCount);
57 printf("]");
60 char *BStreamTag_typeName(BStreamTag *self)
62 switch (self->type)
64 case BSTREAM_UNSIGNED_INT:
65 return "uint";
66 case BSTREAM_SIGNED_INT:
67 return "int";
68 case BSTREAM_FLOAT:
69 return "float";
70 case BSTREAM_POINTER:
71 return "pointer";
74 return "UNKNOWN TYPE";