27 using namespace basis;
35 octopus_entity::octopus_entity()
43 int process_id,
int sequencer,
int add_in)
44 : _hostname(new
astring(hostname)),
46 _sequencer(sequencer),
66 byte_formatter::string_to_bytes(host, temp_form);
74 if (
this == &to_copy)
return *
this;
75 *_hostname = *to_copy._hostname;
77 _sequencer = to_copy._sequencer;
78 _add_in = to_copy._add_in;
97 { *_hostname = new_host; }
100 {
return !_sequencer && !_add_in && !_pid && _hostname->
empty(); }
103 {
return sizeof(int) * 3 + _hostname->
length() + 1; }
105 #define REPLACEMENT_CHARACTER '#'
110 astring chewed_host = *_hostname;
114 for (
int i = 0; i < chewed_host.
length(); i++) {
115 if (!parser_bits::is_printable_ascii(chewed_host[i]))
118 return a_sprintf(
"%d.%d.%d.%s", _add_in, _sequencer, _pid, chewed_host.
s());
125 byte_formatter::bytes_to_string(temp_form, hostdump,
false);
126 return a_sprintf(
"%d.%d.%d.%s", _add_in, _sequencer, _pid, hostdump.
s());
130 int &process_id,
int &sequencer,
int &add_in)
134 sscanf(dupe.
s(),
"%d", &
add_in);
145 return (_add_in == that._add_in)
146 && (_pid == that._pid)
147 && (_sequencer == that._sequencer)
148 && (*_hostname == *that._hostname);
153 _hostname->
pack(packed_form);
154 attach(packed_form, _pid);
155 attach(packed_form, _sequencer);
156 attach(packed_form, _add_in);
161 if (!_hostname->
unpack(packed_form))
return false;
162 if (!
detach(packed_form, _pid))
return false;
163 if (!
detach(packed_form, _sequencer))
return false;
164 if (!
detach(packed_form, _add_in))
return false;
195 int indy = to_convert.
find(
'/', to_convert.
end(),
true);
198 int req_id = to_convert.
substring(indy + 1, to_convert.
end()).convert(0);
a_sprintf is a specialization of astring that provides printf style support.
const contents * observe() const
Returns a pointer to the underlying C array of data.
Provides a dynamically resizable ASCII character string.
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
void pack(byte_array &target) const
stores this string in the "target". it can later be unpacked again.
virtual void zap(int start, int end)
Deletes the characters between "start" and "end" inclusively.
bool substring(astring &target, int start, int end) const
a version that stores the substring in an existing "target" string.
int end() const
returns the index of the last (non-null) character in the string.
bool empty() const
empty() reports if the string is empty, that is, of zero length().
int length() const
Returns the current length of the string.
bool unpack(byte_array &source)
retrieves a string (packed with pack()) from "source" into this string.
int find(char to_find, int position=0, bool reverse=false) const
Locates "to_find" in "this".
virtual const char * observe() const
observes the underlying pointer to the zero-terminated string.
A very common template for a dynamic array of bytes.
A base class for objects that can pack into an array of bytes.
a platform-independent way to acquire random numbers in a specific range.
int inclusive(int low, int high) const
< Returns a pseudo-random number r, such that "low" <= r <= "high".
Provides a way of identifying users of an octopus object.
int process_id() const
returns the process number in the id.
int packed_size() const
reports how large the packed entity will be.
virtual bool unpack(basis::byte_array &packed_form)
Restores the packable from the "packed_form".
basis::astring text_form() const
returns a readable form of the identifier.
octopus_entity & operator=(const octopus_entity &to_copy)
const basis::astring & hostname() const
returns the hostname portion of the id.
bool operator==(const octopus_entity &that) const
octopus_entity()
blank constructor.
int add_in() const
returns the random add-in from the id.
int sequencer() const
returns the sequencing number from the id.
virtual void pack(basis::byte_array &packed_form) const
Creates a packed form of the packable object in "packed_form".
static void breakout(const basis::astring &mangled_form, basis::astring &hostname, int &process_id, int &sequencer, int &add_in)
takes a "mangled_form" of an entity id and retrieves the components.
static octopus_entity from_text(const basis::astring &to_convert)
conversion from text format, parsing parameters out.
bool blank() const
true if the entity is blank, as constructed by default constructor.
basis::astring mangled_form() const
returns the combined string form of the identifier.
Identifies requests made on an octopus by users.
int packed_size() const
reports how large the packed id will be.
static octopus_request_id from_text(const basis::astring &to_convert)
basis::astring mangled_form() const
similar to entity id.
virtual void pack(basis::byte_array &packed_form) const
Creates a packed form of the packable object in "packed_form".
basis::astring text_form() const
human readable form of the request.
int _request_num
the item number from the entity.
octopus_entity _entity
the entity.
bool blank() const
returns true if this is a blank id (as constructed by default ctor).
static octopus_request_id randomized_id()
provides a pre-randomized request id.
virtual bool unpack(basis::byte_array &packed_form)
Restores the packable from the "packed_form".
#define MAXINT32
Maximum 32-bit integer value.
#define REPLACEMENT_CHARACTER
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...
void attach(byte_array &packed_form, const char *to_attach)
Packs a character string "to_attach" into "packed_form".
bool detach(byte_array &packed_form, astring &to_detach)
Unpacks a character string "to_attach" from "packed_form".
bool negative(const type &a)
negative returns true if "a" is less than zero.
An extension to floating point primitives providing approximate equality.
A dynamic container class that holds any kind of object via pointers.