]> jfr.im git - irc/gameservirc.git/blame_incremental - gameserv/myString.cpp
Implemented the myString class in the player and monster classes. This should make...
[irc/gameservirc.git] / gameserv / myString.cpp
... / ...
CommitLineData
1#include "myString.h"
2#include <iostream>
3using std::cout;
4using std::endl;
5
6myString::myString()
7{
8 string = NULL;
9}
10
11myString::myString(char *s)
12{
13 setString(s);
14}
15
16myString::myString(const myString &right)
17{
18 setString(&right);
19}
20
21myString::~myString()
22{
23 if (string)
24 delete [] string;
25
26 string = NULL;
27}
28
29void myString::setString(char *s)
30{
31 if (!s)
32 {
33 if (string)
34 delete [] string;
35
36 string = NULL;
37 }
38 else
39 {
40 delete []string;
41 string = new char[strlen(s) + 1];
42 memset(string, 0, (strlen(s) + 1));
43 strcpy(string, s);
44 }
45}
46void myString::setString(const char *s)
47{
48 if (!s)
49 {
50 if (string)
51 delete [] string;
52
53 string = NULL;
54 }
55 else
56 {
57 delete []string;
58 string = new char[strlen(s) + 1];
59 memset(string, 0, (strlen(s) + 1));
60 strcpy(string, s);
61 }
62}
63
64void myString::setString(const myString *right)
65{
66 setString(right->string);
67}
68
69myString &myString::operator=(myString &right)
70{
71 setString(right.string);
72 return *this;
73}
74
75myString &myString::operator=(char *right)
76{
77 setString(right);
78 return *this;
79}
80
81myString &myString::operator=(const char *right)
82{
83 setString(right);
84 return *this;
85}