Yurttas/PL/OOL/Cplusplus/F/03/02/01/00/05/S.cpp

From ZCubes Wiki
Jump to navigation Jump to search
 1/*
 2   Copyright(C) 1998
 3   All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
 4
 5   Permission to use, copy, modify, and distribute this
 6   software and its documentation for EDUCATIONAL purposes
 7   and without fee is hereby granted provided that this
 8   copyright notice appears in all copies.
 9
10   date   : January 1, 1998.
11   author : Salih Yurttas.
12
13   S.cpp
14*/
15
16
17#include <cstring>
18
19using namespace std;
20
21#include "S.h"
22
23S::
24S(const char *a) {
25  if(a) {
26    l = strlen(a);
27    s = new char[l+1];
28    strcpy(s,a);
29  }
30  else {
31    l = 0;
32    s = new char[l+1];
33    *s = '\0';
34  }
35}
36
37S::
38S(const S& a) {
39  if(a.s) {
40    l = strlen(a.s);
41    s = new char[l+1];
42    strcpy(s,a.s);
43  }
44  else {
45    l = 0;
46    s = new char[l+1];
47    *s = '\0';
48  }
49}
50
51S::
52~S() {
53  delete [] s;
54}
55
56S&
57S::
58operator=(const S& a) {
59  if(a.s) {
60    l = strlen(a.s);
61    s = new char[l+1];
62    strcpy(s,a.s);
63  }
64  else {
65    l = 0;
66    s = new char[l+1];
67    *s = '\0';
68  }
69}
70
71bool
72S::
73operator==(const S& a) {
74  return(strcmp(s, a.s)==0);
75}
76
77ostream&
78operator<<(ostream& os,
79           const S& a) {
80  os << a.s << endl;
81
82  return os;
83}