00001 #ifndef BYTE_ARRAY_CLASS
00002 #define BYTE_ARRAY_CLASS
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "array.cpp"
00019 #include "object_base.h"
00020
00021 #include <memory.h>
00022
00024
00031 class byte_array : public array<byte>, public virtual object_base
00032 {
00033 public:
00034 inline byte_array(int number = 0, const byte *initial_contents = NIL)
00035 : array<byte>(number, initial_contents, SIMPLE_COPY | EXPONE) {}
00037 byte_array(const byte_array &to_copy);
00039 inline byte_array(const array<byte> &to_copy) : array<byte>(to_copy) {}
00041
00042 IMPLEMENT_CLASS_NAME("byte_array");
00043
00044 static const byte_array &empty_array();
00046
00050
00051 bool operator == (const byte_array &to_compare) const {
00052 if (length() != to_compare.length()) return false;
00053 return !memcmp(observe(), to_compare.observe(), length());
00054 }
00056 bool operator != (const byte_array &tc) const { return !(*this == tc); }
00057 };
00058
00060
00061
00062
00063
00064
00065
00067 template <class contents>
00068 void attach_flat(byte_array &target, const contents &attachment)
00069 { target.concatenate(byte_array(sizeof(attachment), (byte *)&attachment)); }
00070
00072 template <class contents>
00073 bool detach_flat(byte_array &source, contents &detached)
00074 {
00075 if (sizeof(detached) > source.length()) return false;
00076 detached = *(contents *)source.observe();
00077 source.zap(0, sizeof(detached) - 1);
00078 return true;
00079 }
00080
00081 #endif
00082