34 template <
class contents>
57 bool member(
const contents &to_test)
const;
60 bool add(
const contents &to_add);
66 {
add(to_add);
return *
this; }
72 bool remove(
const contents &to_remove);
77 {
remove(to_zap);
return *
this; }
114 int find(
const contents &to_find)
const;
124 {
return this->
zap(index, index) == basis::common::OKAY; }
130 template <
class contents>
134 for (
int i = 0; i < to_pack.
elements(); i++) to_pack[i].
pack(packed_form);
138 template <
class contents>
145 for (
int i = 0; i < (int)len; i++) {
146 if (!to_fill.unpack(packed_form))
return false;
147 to_unpack.
add(to_fill);
155 class int_set :
public set<int>,
public virtual basis::root_object
176 for (
int i = 0; i < to_copy.
length(); i++)
183 for (
int i = 0; i <
elements(); i++)
184 if (
get(i) != compare.
get(i))
return false;
190 for (
int i = 0; i <
length(); i++)
200 int to_return =
sizeof(int) * 2;
201 for (
int i = 0; i <
length(); i++)
222 template <
class contents>
225 for (
int i = 0; i < elements(); i++)
226 if (to_test == this->get(i))
231 template <
class contents>
234 if (member(to_add))
return false;
235 this->concatenate(to_add);
239 template <
class contents>
242 for (
int i = 0; i < elements(); i++)
243 if (to_find == this->get(i))
245 return basis::common::NOT_FOUND;
248 template <
class contents>
251 for (
int i = 0; i < elements(); i++)
252 if (to_remove == this->get(i)) {
259 template <
class contents>
263 const set *smaller =
this;
264 const set *larger = &intersect_with;
265 if (elements() > intersect_with.
elements()) {
267 smaller = &intersect_with;
270 for (
int i = 0; i < smaller->
length(); i++)
276 template <
class contents>
280 for (
int i = 0; i < union_with.
elements(); i++)
281 created.
add(union_with.
get(i));
285 template <
class contents>
288 for (
int i = 0; i < union_with.
elements(); i++)
289 add(union_with.
get(i));
292 template <
class contents>
296 for (
int i = 0; i < differ_with.
elements(); i++) {
297 if (created.
member(differ_with[i]))
298 created.
remove(differ_with[i]);
303 template <
class contents>
306 for (
int i = 0; i < differ_with.
elements(); i++) {
307 if (member(differ_with[i]))
308 remove(differ_with[i]);
Represents a sequential, ordered, contiguous collection of objects.
int flags() const
Provides the raw flags value, without interpreting what it means.
void reset(int number=0, const contents *initial_contents=NULL_POINTER)
Resizes this array and sets the contents from an array of contents.
array & concatenate(const array &to_concatenate)
Appends the array "to_concatenate" onto "this" and returns "this".
const basis::astring & get(int index) const
Accesses individual objects stored in "this" at the "index" position.
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".
array(int number=0, const contents *init=NULL_POINTER, int flags=EXPONENTIAL_GROWTH|FLUSH_INVISIBLE)
Constructs an array with room for "number" objects.
int length() const
Returns the current length of the 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 simple object that wraps a templated set of ints.
DEFINE_CLASS_NAME("int_set")
int_set()
Constructs an empty set of ints.
int_set(const set< int > &to_copy)
Constructs a copy of the "to_copy" array.
A set of pointers that hides the platform's pointer size.
pointer_set()
Constructs an empty set of void pointers.
pointer_set(const set< void * > &to_copy)
Constructs a copy of the "to_copy" array.
Emulates a mathematical set, providing several standard set operations.
~set()
Destroys any storage held for the set.
int elements() const
Returns the number of elements in this set.
set(int num=0, const contents *init=NULL_POINTER, basis::un_short flags=basis::array< contents >::EXPONE)
Constructs a set with "num" elements, copying them from "init".
set difference(const set &differ_with) const
Returns the difference of this with "differ_with".
set set_union(const set &union_with) const
Implements the set union of "this" with "union_with".
set intersection(const set &intersect_with) const
Returns the intersection of "this" with the set in "intersect_with".
set & operator+=(const contents &to_add)
An algebraic operator synonym for add() that operates on the contents.
bool member(const contents &to_test) const
Returns true if the item "to_test" is a member of this set.
set operator*(const set &iw) const
A synonym for intersection.
bool remove_index(int index)
Zaps the entry at the specified "index".
set & operator-=(const contents &to_zap)
An algebraic operator synonym for remove that operates on the contents.
bool add(const contents &to_add)
Adds a new element "to_add" to the set.
bool remove(const contents &to_remove)
Removes the item "to_remove" from the set.
void differentiate(const set &differ_with)
Makes "this" set equal to the difference of "this" and "differ_with".
bool non_empty() const
Returns true if the set has some elements.
void unionize(const set &union_with)
Makes "this" set a union of "this" and "union_with".
set operator-(const set &dw) const
A synonym for difference.
int find(const contents &to_find) const
Returns the integer index of the item "to_find" in this set.
bool empty() const
Returns true if the set has no elements.
set operator+(const set &uw) const
A synonym for set_union.
void clear()
Empties out this set.
An array of strings with some additional helpful methods.
A simple object that wraps a templated set of strings.
virtual bool unpack(basis::byte_array &packed_form)
Restores the packable from the "packed_form".
virtual int packed_size() const
Estimates the space needed for the packed structure.
DEFINE_CLASS_NAME("string_set")
virtual void pack(basis::byte_array &packed_form) const
Creates a packed form of the packable object in "packed_form".
string_set()
Constructs an empty set of strings.
bool operator==(const string_set &compare) const
string_set(const set< basis::astring > &to_copy)
Constructs a copy of the "to_copy" array.
string_set(const string_array &to_copy)
Constants and objects used throughout HOOPLE.
#define NULL_POINTER
The value representing a pointer to nothing.
The guards collection helps in testing preconditions and reporting errors.
unsigned int un_int
Abbreviated name for unsigned integers.
unsigned short un_short
Abbreviated name for unsigned short integers.
A dynamic container class that holds any kind of object via pointers.
bool unpack(basis::byte_array &packed_form, set< contents > &to_unpack)
provides a way to unpack any set that stores packable objects.
bool obscure_detach(byte_array &packed_form, un_int &to_detach)
shifts the number back and checks validity, false returned if corrupted.
void obscure_attach(byte_array &packed_form, un_int to_attach)
like the normal attach but shifts in some recognizable sentinel data.
void pack(basis::byte_array &packed_form, const set< contents > &to_pack)
provides a way to pack any set that stores packable objects.
string_array(1, math_list))) const char *addr_list[]