#include "Col.ph" #ifdef __GNUG__ #pragma implementation #endif #include "ByteArray.h" #include "Class.h" #include "String.h" const char *cAtPutName= "AtPut"; //---- ByteArray --------------------------------------------------------------- NewMetaImpl(ByteArray,Object, (TV(cont,cap), T(cap))); ByteArray::ByteArray(const byte *s, int l) { AllocByteArray(s, l); } ByteArray::ByteArray(const char *s, int l) { AllocByteArray((byte*) s, l); } ByteArray::ByteArray(int size) { if (size <= 0) size= 10; cont= new byte[cap= size]; } ByteArray::~ByteArray() { SafeDelete(cont); } void ByteArray::AllocByteArray(const byte *s, int l) { if (s && l) { cont= (byte*) strsave((char*)s, l); cap= strlen((char*)cont); } else cont= new byte[cap= 10]; } const char *ByteArray::AsString() { return (char*)cont; } void ByteArray::SetString(const char *s, int l) { strreplace((char**)&cont, s, l); } u_long ByteArray::Hash() { return strhash(AsString()); } bool ByteArray::IsEqual(Object *o) { return o->IsKindOf(ByteArray) && strcmp(AsString(), o->AsString()) == 0; } int ByteArray::Compare(Object *b) { return strcmp(AsString(), Guard(b, ByteArray)->AsString()); } OStream& ByteArray::PrintOn(OStream &s) { Object::PrintOn(s); return s.PrintString(cont, cap); } IStream& ByteArray::ReadFrom(IStream &s) { Object::ReadFrom(s); SafeDelete(cont); return s.ReadString(&cont, &cap); }