aboutsummaryrefslogtreecommitdiff
path: root/src/staticstring.h
blob: 0d155c47e8490c3195d8047723410c9d9cec65d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef STATIC_STRING_H
#define STATIC_STRING_H

#include <string>
#include "serializable.h"
//#include "hashable.h"

/**
 * Simple string managing class.  Allows for dynamically allocated string data
 * along with some minor caching to speed things up when accessing your
 * string data.  Really designed for making copies of strings easy and safe,
 * and making accessing meta-info like length fast and reliable as well.
 *@author Mike Buland
 */
class StaticString : public Serializable/*, public Hashable*/
{
public:
	StaticString();
	StaticString( const char *lpNewStr, int nNewLen );
	StaticString( const char *lpNewStr );
	StaticString( StaticString &xSrcStr, int nNewLen );
	StaticString( StaticString &xSrcStr );
	StaticString( int nLength );
	virtual ~StaticString();

	char *getString();
	int getLength();
	void setLength( int nNewLength );

	void setString( const char *lpNewStr, int nNewLen=-1 );
	void setString( StaticString &sNewStr, int nNewLen=-1 );

	char getAt( unsigned int nIndex );
	void setAt( unsigned int nIndex, char cVal );

	class StaticString &operator=( class StaticString &lpOtherStr );
	class StaticString &operator=( std::string &lpOtherStr );
	class StaticString &operator=( const char *lpNewStr );
	operator const char *();
	char &operator[]( unsigned int nIndex );
	operator int();
	char *operator+( int nAmnt );
	char *operator-( int nAmnt );
	bool operator==( const char *str );
	bool operator==( StaticString &str );
	bool operator!=( const char *str );
	bool operator!=( StaticString &str );

	void clear();

	virtual void serialize( class Serializer &ar );

	//virtual unsigned long int getHashCode();
	//virtual bool compareForHash( Hashable &other );

private:
	char *lpStr;
	uint32_t nLen;
};

#endif