home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
SAMPLES
/
ICLCC
/
TOYSTRNG.H
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-07
|
3KB
|
93 lines
/******************************************************************************/
/* */
/* COPYRIGHT: */
/* ---------- */
/* Copyright (C) International Business Machines Corp., 1991,1992. */
/* */
/* DISCLAIMER OF WARRANTIES: */
/* ------------------------- */
/* The following [enclosed] code is sample code created by IBM */
/* Corporation. This sample code is not part of any standard IBM product */
/* and is provided to you solely for the purpose of assisting you in the */
/* development of your applications. The code is provided "AS IS", */
/* without warranty of any kind. IBM shall not be liable for any damages */
/* arising out of your use of the sample code, even if they have been */
/* advised of the possibility of such damages. */
/* */
/******************************************************************************/
/*-------------------------------------------------------------*\
| toystrng.h - ToyString Class for use with coding examples. |
| |
| Note: ToyString is kept as simple as possible to not |
| obscure the principles with details. |
| If you are using the Collection Classes with OS/2, |
| you might want to use the String Class from the base |
| class library for real. |
\*-------------------------------------------------------------*/
#ifndef _TOYSTRNG_H_
#define _TOYSTRNG_H_
#include <string.h>
#include <iostream.h>
// Definition of Boolean:
#include <iglobals.h>
class ToyString {
char* txt;
int lng;
public:
ToyString (char* atxt) {
init(atxt);
}
ToyString (ToyString const& aTS) {
init(aTS.txt);
}
ToyString& operator= (ToyString const& aTS) {
if (& aTS != this) {
deInit();
init(aTS.txt);
}
return *this;
}
~ToyString () { deInit(); }
Boolean operator== (ToyString const& aTS) const {
return strcmp(txt, aTS.txt) == 0;
}
Boolean operator== (char* acp) const {
return strcmp(txt, acp) == 0;
}
Boolean operator!= (ToyString const& aTS) const {
return strcmp(txt, aTS.txt) != 0;
}
char* const& text() const {return txt;}
int const& length() const {return lng;}
friend ostream& operator<< (ostream& os, ToyString const& aTS) {
return os << aTS.txt;
}
protected:
inline void init (char* const& atxt) {
lng = strlen(atxt);
txt = new char[lng + 1];
strcpy(txt, atxt);
}
inline void deInit() {
delete[] txt; }
};
#endif