initial
[prop.git] / lib-src / contain / bytearry.cc
blobe088033ace3100ca9c988b0e3bbe6aa213b37f22
1 //////////////////////////////////////////////////////////////////////////////
2 // NOTICE:
3 //
4 // ADLib, Prop and their related set of tools and documentation are in the
5 // public domain. The author(s) of this software reserve no copyrights on
6 // the source code and any code generated using the tools. You are encouraged
7 // to use ADLib and Prop to develop software, in both academic and commercial
8 // settings, and are free to incorporate any part of ADLib and Prop into
9 // your programs.
11 // Although you are under no obligation to do so, we strongly recommend that
12 // you give away all software developed using our tools.
14 // We also ask that credit be given to us when ADLib and/or Prop are used in
15 // your programs, and that this notice be preserved intact in all the source
16 // code.
18 // This software is still under development and we welcome any suggestions
19 // and help from the users.
21 // Allen Leung
22 // 1994
23 //////////////////////////////////////////////////////////////////////////////
25 #include <string.h>
26 #include <AD/contain/bytearry.h>
28 ByteArray::ByteArray(int length)
29 { size = length;
30 units = (length + sizeof(LongWord) - 1) / sizeof(LongWord);
31 array = new LongWord [units];
34 ByteArray::ByteArray(const Byte A[], int len)
35 { size = len;
36 units = (len + sizeof(LongWord) - 1) / sizeof(LongWord);
37 array = new LongWord [units];
38 memcpy(array,A,len);
41 ByteArray::ByteArray(const char string[])
42 { size = strlen(string) + 1;
43 units = (size + sizeof(LongWord) - 1) / sizeof(LongWord);
44 array = new LongWord [units];
45 memcpy(array,string,size);
48 ByteArray::ByteArray(const ByteArray& A) : array(0)
49 { *this = A; }
51 void ByteArray :: operator = (const ByteArray& A)
52 { if (this != &A) {
53 delete [] array;
54 size = A.size;
55 units = A.units;
56 array = new LongWord [units];
57 memcpy(array,A.array,units);
61 // Concatenation between two byte arrays
63 ByteArray ByteArray :: operator || (const ByteArray&) const
65 return *this;
68 // Destructive arithmetic and logical operations
70 void ByteArray :: operator <<= (int shift)
72 if (shift == 0) return;
73 else if (shift < 0) *this >>= -shift;
76 void ByteArray :: operator >>= (int shift)
78 if (shift == 0) return;
79 else if (shift < 0) *this <<= -shift;
82 void ByteArray :: operator |= (const ByteArray&)
86 void ByteArray :: operator &= (const ByteArray&)
90 void ByteArray :: operator ^= (const ByteArray&)
91 { }
93 void ByteArray :: operator += (const ByteArray&)
94 { }
96 void ByteArray :: operator -= (const ByteArray&)
97 { }
99 void ByteArray :: onesComplement()
100 { register int i;
101 for (i = units - 1; i >= 0; i--) array[i] ^= 0xffffffff;
104 void ByteArray :: twosComplement()
107 Bool ByteArray :: operator ! ()
108 { return false; } // is it all zeros??
110 // Arithmetic and logical operations
113 Bool operator == (const ByteArray&, const ByteArray&)
114 { return false; }
116 Bool operator >= (const ByteArray&, const ByteArray&)
117 { return false; }
119 Bool operator <= (const ByteArray&, const ByteArray&)
120 { return false; }