00001 #ifndef STRING_ARRAY_CLASS
00002 #define STRING_ARRAY_CLASS
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "array.cpp"
00019 #include "istring.h"
00020 #include "object_base.h"
00021 #include "packable.h"
00022
00024
00025 class string_array
00026 : public array<istring>, public packable, public virtual object_base
00027 {
00028 public:
00029 inline string_array(int number = 0, const istring *initial_contents = NIL)
00030 : array<istring>(number, initial_contents,
00031 EXPONE | FLUSH_INVISIBLE) {}
00033
00037
00038
00040 inline string_array(int number, const char *initial_contents[])
00041 : array<istring>(number, NIL, EXPONE | FLUSH_INVISIBLE) {
00042 for (int i = 0; i < number; i++) {
00043 put(i, istring(initial_contents[i]));
00044 }
00045 }
00046
00047 inline string_array(const array<istring> &to_copy)
00048 : array<istring>(to_copy) {}
00050
00051 IMPLEMENT_CLASS_NAME("string_array");
00052
00054 inline istring text_format(const istring &separator = ",",
00055 const istring &delimiter = "\"") const {
00056 istring to_return;
00057 for (int i = 0; i < length(); i++) {
00058 to_return += delimiter;
00059 to_return += get(i);
00060 to_return += delimiter;
00061 if (i < last())
00062 to_return += separator;
00063 }
00064 return to_return;
00065 }
00066
00067 inline istring text_form() const { return text_format(); }
00069
00070
00071
00073 inline bool operator == (const string_array &to_compare) const {
00074 if (length() != to_compare.length())
00075 return false;
00076 for (int i = 0; i < length(); i++)
00077 if (to_compare[i] != get(i))
00078 return false;
00079 return true;
00080 }
00082 inline bool operator != (const string_array &to_compare) const
00083 { return !(*this == to_compare); }
00084
00086 inline int find(const istring &to_find) const {
00087 for (int i = 0; i < length(); i++) {
00088 if (to_find == get(i)) return i;
00089 }
00090 return common::NOT_FOUND;
00091 }
00092
00094
00096 inline bool prefix_compare(const string_array &second) const {
00097 if (second.length() < length()) return false;
00098 if (!length()) return false;
00099 for (int i = 0; i < length(); i++)
00100 if ((*this)[i] != second[i]) return false;
00101 return true;
00102 }
00103
00105 inline virtual void pack(byte_array &packed_form) const
00106 { basis::pack(packed_form, *this); }
00107
00109 inline virtual bool unpack(byte_array &packed_form)
00110 { return basis::unpack(packed_form, *this); }
00111
00113 inline virtual int packed_size() const {
00114 int to_return = sizeof(int) * 2;
00115 for (int i = 0; i < length(); i++)
00116 to_return += get(i).length() + 1;
00117 return to_return;
00118 }
00119 };
00120
00121 #endif
00122