1 //////////////////////////////////////////////////////////////////////////////
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
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
18 // This software is still under development and we welcome any suggestions
19 // and help from the users.
23 //////////////////////////////////////////////////////////////////////////////
26 #include <AD/contain/bytearry.h>
28 ByteArray::ByteArray(int length
)
30 units
= (length
+ sizeof(LongWord
) - 1) / sizeof(LongWord
);
31 array
= new LongWord
[units
];
34 ByteArray::ByteArray(const Byte A
[], int len
)
36 units
= (len
+ sizeof(LongWord
) - 1) / sizeof(LongWord
);
37 array
= new LongWord
[units
];
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)
51 void ByteArray :: operator = (const ByteArray
& A
)
56 array
= new LongWord
[units
];
57 memcpy(array
,A
.array
,units
);
61 // Concatenation between two byte arrays
63 ByteArray
ByteArray :: operator || (const ByteArray
&) const
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
&)
93 void ByteArray :: operator += (const ByteArray
&)
96 void ByteArray :: operator -= (const ByteArray
&)
99 void ByteArray :: onesComplement()
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
&)
116 Bool
operator >= (const ByteArray
&, const ByteArray
&)
119 Bool
operator <= (const ByteArray
&, const ByteArray
&)