Quantum Fog  0.9.3
STRINGY.h
1 //******************************************
2 // Purpose: To define a class of string objects living in the heap.
3 //******************************************
4 #pragma once
5 
6 #include "QFog_constants.h"
7 #include "GLOBAL_FUN.h"
8 
9 #include <string.h>
10 #include <stdio.h>
11 #include <iostream.h>
12 #include <iomanip.h>
13 #include <fstream.h>
14 //******************************************
15 //******************************************
16 //We use:
17 //pstr ending for Pascal string (like Str255)
18 //cstr ending for C string
19 //no special ending for STRINGY or LStr255
20 //buf_p indeterminate sex (either C or Pascal)
21 //******************************************
22 class STRINGY
23 {
24 private:
25  CHAR * its_cstr;
26  USHORT its_len;
27  // len = length.
28  //"its_len" does NOT include the \0 termination character.
29 
30 public:
31  enum {stringy_max_len = 255};// 256 once include termination char
32 
33  VOID clear();
34  VOID copy(const STRINGY & s);
35  STRINGY();
36  STRINGY(CHAR ch, USHORT len);
37  STRINGY(const CHAR * cstr);
38  STRINGY(SHORT i);
39  STRINGY(USHORT i);
40  STRINGY(LONG i);
41  STRINGY(DOUBLE x);
42  STRINGY(const STRINGY & s);
43  STRINGY & operator= (const STRINGY & rhs);
44  virtual ~STRINGY();
45 
46  USHORT get_len() const;
47  const CHAR * get_string() const;
48  STRINGY get_sub_stringy(USHORT starting_pos, USHORT sub_str_len) const;
49 
50  BOOLEAN is_legal_name() const;
51 
52  friend BOOLEAN operator==(const STRINGY & s1, const STRINGY & s2);
53  friend BOOLEAN operator!=(const STRINGY & s1, const STRINGY & s2);
54 
55  friend BOOLEAN operator==(const STRINGY & s, const CHAR * cstr);
56  friend BOOLEAN operator!=(const STRINGY & s, const CHAR * cstr);
57 
58  friend BOOLEAN operator==(const CHAR * cstr, const STRINGY & s);
59  friend BOOLEAN operator!=(const CHAR * cstr, const STRINGY & s);
60 
61  friend BOOLEAN operator<(const STRINGY & s1, const STRINGY & s2);
62 
63  CHAR & operator[] (USHORT i);
64  const CHAR & operator[] (USHORT i) const;
65 
66  STRINGY operator &&(const STRINGY & rhs);
67 
68  friend OSTREAM & operator<<( OSTREAM & out_bd, const STRINGY & s);
69  friend ISTREAM & operator>>( ISTREAM & in_bd, STRINGY & s);
70  ISTREAM & copy_line(ISTREAM & in_bd, USHORT max_len, CHAR stop_char);
71 
72 
73 #ifdef _mac_gui_app //''''''''''''''''''''''''''''''''''''''''''''\\.
74 
75  VOID fill_LStr255(LStr255 & pstr) const;
76  STRINGY(const LStr255 & pstr);
77 
78  BOOLEAN is_double() const;
79  BOOLEAN is_double(DOUBLE & db) const;
80  BOOLEAN is_ushort() const;
81  BOOLEAN is_ushort(USHORT & n) const;
82  BOOLEAN is_ushort_pair() const;
83  BOOLEAN is_ushort_pair(USHORT & n1, USHORT & n2) const;
84 
85  friend LStream & operator<<( LStream & out_bd, const STRINGY & s);
86  friend LStream & operator>>( LStream & in_bd, STRINGY & s);
87 
88 #endif //_mac_gui_app \\............................................//
89 
90 
91 };
92 #pragma mark -
93 
94 //******************************************
95 inline
96 USHORT STRINGY::get_len() const
97 {
98  return its_len;
99 }
100 //******************************************
101 inline
102 const CHAR * STRINGY::get_string() const
103 {
104  return its_cstr;
105 }
106 //******************************************
107 inline
108 BOOLEAN operator!=(
109 const STRINGY & s1, //in
110 const STRINGY & s2) //in
111 {
112  return !(s1==s2);
113 }
114 //******************************************
115 inline
116 BOOLEAN operator!=(
117 const STRINGY & s, //in
118 const CHAR * cstr) //in
119 {
120  return !(s==cstr);
121 }
122 //******************************************
123 inline
124 BOOLEAN operator!=(
125 const CHAR * cstr, //in
126 const STRINGY & s) //in
127 {
128  return !(cstr==s);
129 }
130 //******************************************
131 inline
132 CHAR & STRINGY::operator[](
133 USHORT i) //in
134 {
135 // Returns alias to the ith character of a stringy so that
136 // the ith character can be changed.
137  ThrowIf_(i >= its_len);
138  return its_cstr[i];
139 }
140 //******************************************
141 inline
142 const CHAR & STRINGY::operator[](
143 USHORT i) //in
144 const
145 {
146 // Constant function that returns a constant alias to
147 // the ith character of a stringy.
148 // For use on constant objects. See, for example, the copy constructor.
149  ThrowIf_(i >= its_len);
150  return its_cstr[i];
151 }
152 
153 
Definition: STRINGY.h:22