Go to the documentation of this file.00001
00002
00003
00004
00005 #ifndef utilit_classes_h
00006 #define utilit_classes_h
00007
00008 #include "utilit.h"
00009
00010
00011
00012 template <class Type, int Size>
00013 struct CSmallVector {
00014 Type m_Items[Size];
00015 int m_ItemsCount;
00016 CSmallVector ()
00017 {
00018 m_ItemsCount = 0;
00019 }
00020 void Add (Type Item)
00021 {
00022
00023
00024 if (m_ItemsCount >= Size-1)
00025 return;
00026 m_Items[m_ItemsCount++] = Item;
00027 };
00028 void Insert (int No, Type Item)
00029 {
00030
00031
00032 if (m_ItemsCount >= Size-1)
00033 return;
00034
00035 for (long i = m_ItemsCount; i > No ; i--)
00036 m_Items[i] = m_Items[i-1];
00037 m_Items[No] = Item;
00038 m_ItemsCount++;
00039 };
00040 void Erase (int No)
00041 {
00042
00043 for (long i = No; i < m_ItemsCount-1 ; i++)
00044 m_Items[i] = m_Items[i+1];
00045 m_ItemsCount--;
00046 };
00047 void Clear ()
00048 {
00049 m_ItemsCount = 0;
00050 };
00051 BYTE size () const {
00052 return m_ItemsCount;
00053 };
00054 bool empty () const {
00055 return m_ItemsCount == 0;
00056 };
00057
00058 Type& back () {
00059 return m_Items[m_ItemsCount - 1];
00060 };
00061 Type& operator[](int No) { return m_Items[No]; };
00062
00063 const Type& operator[](int No) const { return m_Items[No]; };
00064
00065 size_t find_item (const Type& X) const { return find(m_Items, m_Items+m_ItemsCount, X) - m_Items; };
00066
00067 bool has (const Type& X) const { return find_item(X) != m_ItemsCount; };
00068
00069
00070 };
00071
00072
00073 template <class T>
00074 class _share_pointer_t
00075 {
00076 public:
00077 T m_Pointer;
00078 bool m_bOwnPointer;
00079
00080 _share_pointer_t()
00081 {
00082 m_bOwnPointer = true;
00083 m_Pointer = 0;
00084 };
00085 ~_share_pointer_t()
00086 {
00087 FreePointer();
00088 };
00089
00090 void SetPointer(T p, bool bOwnPointer)
00091 {
00092 if (m_bOwnPointer)
00093 if (m_Pointer)
00094 delete m_Pointer;
00095
00096 m_Pointer = p;
00097 m_bOwnPointer = bOwnPointer;
00098 }
00099 void FreePointer()
00100 {
00101 SetPointer(0, true);
00102 }
00103 };
00104
00105
00106
00107 class CShortString
00108 {
00109 vector<char>::const_iterator m_pStringPointer;
00110 public:
00111 CShortString(vector<char>::const_iterator pData);
00112
00113 BYTE GetLength() const;
00114 vector<char>::const_iterator GetData() const;
00115 const char* GetString() const;
00116
00117 };
00118
00119 class IsLessShortString : public std::binary_function<const CShortString&, const char*, bool>
00120 {
00121 public:
00122 bool operator()(const CShortString& Item1, const char* Item2) const;
00123 bool operator()(const char* Item1, const CShortString& Item2) const;
00124 bool operator()(const CShortString& Item1, const CShortString& Item2) const;
00125 };
00126
00127
00128 class CShortStringHolder : public vector<CShortString>
00129 {
00130 vector<char> m_Buffer;
00131 template<class T>
00132 bool CreateFromSequence(T begin, T end);
00133 public:
00134 void ReadShortStringHolder(string filename);
00135 bool WriteShortStringHolder(const string& FileName) const;
00136 bool CreateFromVector(const StringVector& in);
00137 bool CreateFromSet(const StringSet& in);
00138 };
00139
00140
00141
00142 struct CMyTimeSpan
00143 {
00144 clock_t m_StartTime;
00145 double m_TimeSpan;
00146 long m_InterfaceNestId;
00147 long m_SequenceId;
00148 long m_InvokeCount;
00149 CMyTimeSpan (long SequenceId = 0, long InterfaceNestId = 0);
00150 void GetStrRepresentation(const char* Name, char* buffer, double AllClocksCount) const;
00151 };
00152
00153
00154 class CMyTimeSpanHolder
00155 {
00156 map<string, CMyTimeSpan> m_TimeSpans;
00157 long m_SequenceId;
00158
00159 public:
00160 bool m_bTimeSpanHolderEnabled;
00161
00162 typedef map<string, CMyTimeSpan>::const_iterator ConstIterator;
00163 typedef map<string, CMyTimeSpan>::iterator Iterator;
00164
00165 CMyTimeSpanHolder();
00166 void StartTimer(const string& Name, long NestId);
00167 double EndTimer(const string& Name);
00168 string GetStrRepresentation (double AllClocksCount = 0) const;
00169 void ClearTimers();
00170 };
00171
00172
00188 class StringTokenizer{
00189 char *text_ptr;
00190 char *text;
00191 int i;
00192 string delims;
00193 char *_val;
00194
00195 bool is_delim(char ch) const;
00196 void initialize(const char *_text, const char *_delims);
00197 public:
00198
00199 StringTokenizer(const char *_text, const char *_delims);
00200 ~StringTokenizer();
00201 const char * operator ()();
00202 string next_token ();
00203
00204 const char * get_rest () const;
00205 const char *val() const;
00206 int count() const;
00207 bool has_next() const;
00208 void reinitialize(const char *_text, const char *_delims);
00209
00210 };
00211
00212
00213
00214 #endif