versadac  1
versadac - Scalable Recorder Firmware
CString.h
1 #if !defined(__CSTRING_H__)
2 #define __CSTRING_H__
3 
4 #include <string.h>
5 
6 class CString
7 {
8 public:
9  // constructors and destructor
10  CString() { m_nLength = 0; m_pString = 0; }
11  CString(const char* str);
12  CString(const CString& str);
13  virtual ~CString() { if (m_pString) delete m_pString; }
14 
15  void Empty() { if (m_pString) delete m_pString; m_nLength = 0; m_pString = 0; }
16  CString& operator =(const char* str);
17  CString& operator =(const CString& str);
18  CString& operator +=(const char ch);
19  CString& operator +=(const char* str) { return *this += (CString)str; }
20  CString& operator +=(const CString& str);
21 
22  // add more logic comparison operators as following, for example, although not efficient
23  virtual bool operator !=(char* str) { return strcmp(str, m_pString) != 0; }
24 
25  // c type string conversion
26  operator char* () { return m_pString; }
27  operator const char* () const { return m_pString; }
28  char* GetChar() { return m_pString; }
29 
30  // search utilities
31  int Find(const char);
32 
33 protected:
34  // data block
35  int m_nLength;
36  char* m_pString;
37 };
38 
39 template <class T>
40 CString operator +(T var, const CString& str)
41 {
42  CString svar = var;
43  return svar += str;
44 }
45 
46 #endif
Definition: CString.h:6