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 static bool lazyMemoryManagement;
00032
00033 StringArray(int startsize = 0);
00034 StringArray(StringArray & original);
00035 virtual ~StringArray();
00036
00037
00038
00039
00040 void Read(FILE * f);
00041 void Write(FILE * f);
00042 void WriteLine(FILE * f);
00043 void Read(const char * filename);
00044 void Write(const char * filename);
00045 void WriteLine(const char * filename);
00046
00047 void Read(IFILE & f);
00048
00049
00050 void Print();
00051 void PrintLine();
00052
00053
00054 void Print(FILE * f);
00055 void PrintLine(FILE * f);
00056
00057 void Grow(int newsize);
00058 void Clear();
00059
00060 int Length() const
00061 {
00062 return count;
00063 }
00064 int Dimension(int newcount);
00065 int CharLength();
00066
00067 String & operator [](int i)
00068 {
00069 return *(strings[i]);
00070 }
00071 const String & operator [](int i) const
00072 {
00073 return *(strings[i]);
00074 }
00075
00076
00077
00078
00079
00080 int AddColumns(const String & s, char ch = '\t');
00081 int AddColumns(const String & s, char ch, int maxColumns);
00082 int AddTokens(const String & s, char ch);
00083 int AddTokens(const String & s, const String & separators = " \t\r\n");
00084
00085 int ReplaceColumns(const String & s, char ch = '\t')
00086 {
00087 Clear();
00088 return AddColumns(s, ch);
00089 }
00090 int ReplaceTokens(const String & s, const String & separators = " \t\r\n")
00091 {
00092 Clear();
00093 return AddTokens(s, separators);
00094 }
00095
00096
00097
00098
00099 int Add(const String & s);
00100 void InsertAt(int position, const String & s);
00101 void Delete(int position);
00102
00103
00104
00105
00106 String & Last() const;
00107 int Push(const String & s)
00108 {
00109 return Add(s);
00110 }
00111 String Pop();
00112
00113
00114
00115
00116
00117 int Find(const String & s) const;
00118 int FastFind(const String & s) const;
00119 int SlowFind(const String & s) const;
00120
00121
00122
00123 void Sort();
00124
00125
00126 void Trim();
00127
00128 StringArray & operator = (const StringArray & rhs);
00129
00130 bool operator == (const StringArray & rhs) const;
00131 bool operator != (const StringArray & rhs) const
00132 {
00133 return !(*this == rhs);
00134 }
00135
00136 void Swap(StringArray & s);
00137
00138 private:
00139 static int ComparisonForSort(const void * a, const void * b);
00140 };
00141
00142 #endif
00143