logog
logger optimized for games
string.hpp
Go to the documentation of this file.
1 
4 #ifndef __LOGOG_STRING_HPP__
5 #define __LOGOG_STRING_HPP__
6 
12 #ifdef LOGOG_UNICODE
13 
14 typedef wchar_t LOGOG_CHAR;
20 #define L0 (const LOGOG_CHAR *)'\0'
21 #define LNULL (const LOGOG_CHAR *)'\0'
22 #define L__null (const LOGOG_CHAR *)'\0'
23 
24 /* Two indirect references are necessary in order to expand a string and append the L to it. */
25 #define LOGOG_CONST_STRING_INDIRECT(x) L ## x
26 /* This macro will cause a const string to be stored as a Unicode string on a Unicode build. */
27 #define LOGOG_CONST_STRING(x) LOGOG_CONST_STRING_INDIRECT(x)
28 #define LOGOG_COUT std::wcout
29 #define LOGOG_CERR std::wcerr
30 
31 #else // LOGOG_UNICODE
32 
34 typedef char LOGOG_CHAR;
38 #define LOGOG_CONST_STRING(x) (x)
39 #define LOGOG_COUT std::cout
40 #define LOGOG_CERR std::cerr
41 #endif // LOGOG_UNICODE
42 
46 #ifndef LOGOG_USE_PREFIX
47 
53 #define _LG( x ) LOGOG_CONST_STRING( x )
54 #endif
55 
56 namespace logog
57 {
58  class String : public Object
59  {
60  public:
61 
62  static const size_t npos = (size_t) -1;
63 
64  String();
65  virtual ~String();
66  virtual void Free();
67  static size_t Length( const LOGOG_CHAR *chars );
68 
69  String( const String &other );
70  String( const LOGOG_CHAR *pstr );
71  String & operator =( const String & other);
72  String & operator =( const LOGOG_CHAR *pstr );
73  size_t size() const;
74  virtual void clear();
75  virtual size_t reserve( size_t nSize );
76  virtual size_t reserve_for_int();
77  virtual operator const LOGOG_CHAR *() const;
78  virtual size_t assign( const String &other );
79  virtual size_t append( const String &other );
80  virtual size_t append( const LOGOG_CHAR *other );
81  virtual void reverse( LOGOG_CHAR* pStart, LOGOG_CHAR* pEnd);
82  virtual size_t assign( const int value );
83  virtual size_t append( const LOGOG_CHAR c );
84  virtual bool is_valid() const;
85  virtual size_t assign( const LOGOG_CHAR *other, const LOGOG_CHAR *pEnd = NULL );
86 
87  virtual size_t find( String &other ) const;
88  virtual void format( const LOGOG_CHAR *cFormatString, ... );
89  virtual void format_va( const LOGOG_CHAR *cFormatString, va_list args );
90 
91  virtual const LOGOG_CHAR* c_str() const;
92 
93  protected:
94  virtual void Initialize();
95 
96  /* Code modified from http://www-igm.univ-mlv.fr/~lecroq/string/node8.html#SECTION0080 */
97  void preKmp(size_t m);
98 
99  size_t KMP( const LOGOG_CHAR *y, size_t n );
100 
101 #define LOGOG_MAX( a, b ) ( ( a > b ) ? a : b )
102 
103  size_t BM(LOGOG_CHAR *y, size_t n);
104 
108  size_t *m_pKMP;
110  };
111 }
112 
113 #define LOGOG_STRING ::logog::String
114 
115 #endif // __LOGOG_STRING_HPP_
virtual size_t assign(const String &other)
[Thread]
Definition: api.hpp:8
virtual ~String()
size_t * m_pKMP
Definition: string.hpp:108
size_t size() const
virtual void reverse(LOGOG_CHAR *pStart, LOGOG_CHAR *pEnd)
virtual void clear()
size_t BM(LOGOG_CHAR *y, size_t n)
static const size_t npos
Definition: string.hpp:62
size_t KMP(const LOGOG_CHAR *y, size_t n)
LOGOG_CHAR * m_pEndOfBuffer
Definition: string.hpp:107
virtual void format_va(const LOGOG_CHAR *cFormatString, va_list args)
LOGOG_CHAR * m_pOffset
Definition: string.hpp:106
Definition: string.hpp:58
static size_t Length(const LOGOG_CHAR *chars)
virtual const LOGOG_CHAR * c_str() const
wchar_t LOGOG_CHAR
Definition: string.hpp:14
virtual void Free()
virtual bool is_valid() const
void preKmp(size_t m)
String & operator=(const String &other)
bool m_bIsConst
Definition: string.hpp:109
virtual size_t find(String &other) const
virtual size_t reserve(size_t nSize)
virtual void format(const LOGOG_CHAR *cFormatString,...)
virtual size_t append(const String &other)
Definition: object.hpp:47
virtual void Initialize()
LOGOG_CHAR * m_pBuffer
Definition: string.hpp:105
virtual size_t reserve_for_int()