23 using namespace basis;
31 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
44 FUNCDEF(
"constructor [string_array]");
50 FUNCDEF(
"constructor [one string]");
51 *_classifier += class_1;
57 FUNCDEF(
"constructor [two strings]");
58 *_classifier += class_1;
59 *_classifier += class_2;
66 FUNCDEF(
"constructor [three strings]");
67 *_classifier += class_1;
68 *_classifier += class_2;
69 *_classifier += class_3;
80 {
WHACK(_classifier); }
83 { *_classifier = *to_copy._classifier;
return *
this; }
86 {
return *_classifier; }
90 bool to_return =
true;
91 if (!_classifier->
length())
93 for (
int i = 0; i < _classifier->
length(); i++) {
94 if (!(*_classifier)[i].length())
98 program_wide_logger::get().log(classname +
"::" + caller
99 +
": invalid classifier provided.", ALWAYS_PRINT);
107 FUNCDEF(
"set_classifier [string_array]");
109 *_classifier = new_classifier;
118 FUNCDEF(
"set_classifier [1 string]");
120 _classifier->
reset();
121 *_classifier += class_1;
130 FUNCDEF(
"set_classifier [2 strings]");
132 _classifier->
reset();
133 *_classifier += class_1;
134 *_classifier += class_2;
144 FUNCDEF(
"set_classifier [3 strings]");
146 _classifier->
reset();
147 *_classifier += class_1;
148 *_classifier += class_2;
149 *_classifier += class_3;
170 int len_prior = packed_form.
length();
174 to_pack.
pack(packed_form);
175 int added_len = packed_form.
length() -
sizeof(int) - len_prior;
180 packed_form[len_prior + i] =
abyte(temp % 0x100);
190 if (!packed_form.
length())
return false;
203 const void *zero_posn = packed_form.
observe() +
sizeof(int) * 2 + 1;
204 for (
int i = 0; i < (int)strings_held; i++) {
206 int index = int((
abyte *)zero_posn - packed_form.
observe());
207 zero_posn = memchr(packed_form.
observe() + index,
'\0',
208 packed_form.
length() - index);
218 int datalen_start = int((
abyte *)zero_posn - packed_form.
observe()) + 1;
220 datalen_start +
sizeof(
int) - 1);
222 packed_length += datalen_start +
sizeof(int);
233 abyte version_checking = 0;
239 if (len > packed_form.
length()) {
244 info = packed_form.
subarray(0, len - 1);
245 packed_form.
zap(0, len - 1);
void reset(int number=0, const contents *initial_contents=NULL_POINTER)
Resizes this array and sets the contents from an array of contents.
const contents * observe() const
Returns a pointer to the underlying C array of data.
array subarray(int start, int end) const
Returns the array segment between the indices "start" and "end".
int length() const
Returns the current reported length of the allocated C array.
outcome zap(int start, int end)
Deletes from "this" the objects inclusively between "start" and "end".
Provides a dynamically resizable ASCII character string.
A very common template for a dynamic array of bytes.
A clonable object knows how to make copy of itself.
A base class for objects that can pack into an array of bytes.
virtual const char * class_name() const =0
Returns the bare name of this class as a constant character pointer.
An infoton is an individual request parcel with accompanying information.
infoton & operator=(const infoton &to_copy)
assigns only the base class portion.
static void fast_pack(basis::byte_array &packed_form, const infoton &to_pack)
flattens an infoton "to_pack" into the byte array "packed_form".
static int fast_pack_overhead(const structures::string_array &classifier)
reports how much space is needed to pack the "classifier".
bool check_classifier(const basis::astring &class_name, const basis::astring &caller)
checks that the classifier seems valid.
static bool test_fast_unpack(const basis::byte_array &packed_form, int &packed_length)
checks that the "packed_form" could hold a valid packed infoton.
static bool fast_unpack(basis::byte_array &packed_form, structures::string_array &classifier, basis::byte_array &info)
undoes a previous fast_pack to restore the previous information.
const structures::string_array & classifier() const
this array of strings is the "name" for this infoton.
infoton(const structures::string_array &classifier)
creates an infoton with the "classifier".
void set_classifier(const structures::string_array &new_classifier)
sets the infoton's classifier to the "new_classifier".
virtual void pack(basis::byte_array &packed_form) const =0
stuffs the data in the infoton into the "packed_form".
An array of strings with some additional helpful methods.
virtual int packed_size() const
Returns the number of bytes this string array would consume if packed.
#define continuable_error(c, f, i)
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
The guards collection helps in testing preconditions and reporting errors.
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
unsigned char abyte
A fairly important unit which is seldom defined...
unsigned int un_int
Abbreviated name for unsigned integers.
A logger that sends to the console screen using the standard output device.
const abyte FAST_PACK_VERSION
A dynamic container class that holds any kind of object via pointers.
bool obscure_detach(byte_array &packed_form, un_int &to_detach)
shifts the number back and checks validity, false returned if corrupted.
void attach(byte_array &packed_form, const byte_array &to_attach)
Packs a byte_array "to_attach" into "packed_form".
bool unpack_array(basis::byte_array &packed_form, basis::array< contents > &to_unpack)
provides a way to unpack any array that stores packable objects.
void pack_array(basis::byte_array &packed_form, const basis::array< contents > &to_pack)
provides a way to pack any array that stores packable objects.
bool detach(byte_array &packed_form, byte_array &to_detach)
Unpacks a byte_array "to_detach" from "packed_form".
#define static_class_name()