StringArray.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __STRING_ARRAY_H__
00019 #define __STRING_ARRAY_H__
00020
00021 #include "StringBasics.h"
00022
00023 class StringArray
00024 {
00025 protected:
00026 String ** strings;
00027 int size, count;
00028
00029 public:
00030 static int alloc;
00031
00032 StringArray(int startsize = 0);
00033 StringArray(StringArray & original);
00034 virtual ~StringArray();
00035
00036
00037
00038
00039 void Read(FILE * f);
00040 void Write(FILE * f);
00041 void WriteLine(FILE * f);
00042 void Read(const char * filename);
00043 void Write(const char * filename);
00044 void WriteLine(const char * filename);
00045
00046 #ifdef __ZLIB_AVAILABLE__
00047 void Read(IFILE & f);
00048 #endif
00049
00050
00051 void Print();
00052 void PrintLine();
00053
00054 void Grow(int newsize);
00055 void Clear();
00056
00057 int Length() const
00058 {
00059 return count;
00060 }
00061 int Dimension(int newcount);
00062 int CharLength();
00063
00064 String & operator [](int i)
00065 {
00066 return *(strings[i]);
00067 }
00068 const String & operator [](int i) const
00069 {
00070 return *(strings[i]);
00071 }
00072
00073
00074
00075
00076
00077 int AddColumns(const String & s, char ch = '\t');
00078 int AddTokens(const String & s, char ch);
00079 int AddTokens(const String & s, const String & separators = " \t\r\n");
00080
00081 int ReplaceColumns(const String & s, char ch = '\t')
00082 {
00083 Clear();
00084 return AddColumns(s, ch);
00085 }
00086 int ReplaceTokens(const String & s, const String & separators = " \t\r\n")
00087 {
00088 Clear();
00089 return AddTokens(s, separators);
00090 }
00091
00092
00093
00094
00095 int Add(const String & s);
00096 void InsertAt(int position, const String & s);
00097 void Delete(int position);
00098
00099
00100
00101
00102 String & Last() const;
00103 int Push(const String & s)
00104 {
00105 return Add(s);
00106 }
00107 String Pop();
00108
00109
00110
00111
00112
00113 int Find(const String & s) const;
00114 int FastFind(const String & s) const;
00115 int SlowFind(const String & s) const;
00116
00117
00118
00119 void Sort();
00120
00121
00122 void Trim();
00123
00124 StringArray & operator = (const StringArray & rhs);
00125
00126 bool operator == (const StringArray & rhs);
00127 bool operator != (const StringArray & rhs)
00128 {
00129 return !(*this == rhs);
00130 }
00131
00132 void Swap(StringArray & s);
00133
00134 private:
00135 static int ComparisonForSort(const void * a, const void * b);
00136 };
00137
00138 #endif
00139