Orbiter 2022
Combinatorial Objects
hollerith.cpp
Go to the documentation of this file.
1// hollerith.cpp
2//
3// Anton Betten
4// 24.04.2000
5// moved from D2 to ORBI Nov 15, 2007
6
8#include "discreta.h"
9
10using namespace std;
11
12
13namespace orbiter {
14namespace layer2_discreta {
15
16
17#undef HOLLERITH_COPY_VERBOSE
18
19
21{
22 k = HOLLERITH;
23 self.char_pointer = NULL;
24}
25
27{
28 k = HOLLERITH;
29 self.char_pointer = NULL;
30 init(p);
31}
32
34 // copy constructor: this := x
35{
36 // cout << "hollerith::copy constructor for object: " << const_cast<discreta_base &>(x) << "\n";
37 clearself();
38 const_cast<discreta_base &>(x).copyobject_to(*this);
39}
40
42 // copy assignment
43{
44 // cout << "hollerith::operator = (copy assignment)" << endl;
45 copyobject(const_cast<discreta_base &>(x));
46 return *this;
47}
48
50{
52
53 s = self;
54 new(this) hollerith;
55 k = HOLLERITH;
56 self = s;
57}
58
60{
62}
63
65{
66 // cout << "hollerith::freeself_hollerith()" << endl;
67 if (self.char_pointer == NULL)
68 return;
69 delete[] self.char_pointer;
70 self.char_pointer = NULL;
71}
72
74{
75 return HOLLERITH;
76}
77
79{
80#ifdef HOLLERITH_COPY_VERBOSE
81 cout << "in hollerith::copyobject_to()\n";
82#endif
83 x.freeself();
85 if (s() == NULL)
86 return;
87 xx.init(s());
88}
89
90ostream& hollerith::print(ostream& ost)
91{
92 if (s() == NULL)
93 ost << "(null)";
94 else
95 ost << s();
96 return ost;
97}
98
100{
101 char *p1, *p2;
102
103 if (a.s_kind() != HOLLERITH) {
104 cout << "hollerith::compare_with() a is not a hollerith object" << endl;
105 exit(1);
106 }
107 p1 = s();
108 p2 = a.as_hollerith().s();
109 return strcmp(p1, p2);
110}
111
112void hollerith::init(const char *p)
113{
114 int l;
115
116 // cout << "hollerith::init() for string \"" << p << "\"" << endl;
118 l = strlen(p);
119 self.char_pointer = (char *) new char[l + 1];
120 strcpy(s(), p);
121}
122
123void hollerith::append(const char *p)
124{
125 int l1, l2, l3;
126 char *q;
127
128 l1 = strlen(s());
129 l2 = strlen(p);
130 l3 = l1 + l2;
131 q = (char *) new char[l3 + 1];
132 strcpy(q, s());
133 strcat(q, p);
134 delete[] self.char_pointer;
135 self.char_pointer = q;
136}
137
139{
140 char str[1000];
141
142 sprintf(str, "%d", i);
143 append(str);
144}
145
146void hollerith::write_mem(memory & m, int debug_depth)
147{
148 int i, l;
149
150 if (s()) {
151 l = strlen(s());
152 for (i = 0; i < l; i++) {
153 m.write_char(s()[i]);
154 }
155 }
156 m.write_char((char) 0);
157}
158
159//#define BUFSIZE 1000
160
161void hollerith::read_mem(memory & m, int debug_depth)
162{
163 int l;
164 char buf[BUFSIZE + 1], c;
165
166 freeself();
167 l = 0;
168 while (TRUE) {
169 m.read_char(&c);
170 if (c == 0 || l == BUFSIZE) {
171 buf[l] = 0;
172 append(buf);
173 l = 0;
174 }
175 if (c == 0)
176 break;
177 buf[l++] = c;
178 }
179}
180
182{
183 if (s())
184 return strlen(s()) + 1;
185 else
186 return 1;
187}
188
190{
191 char *p = s();
192 int l1 = strlen(p);
193 int l2 = strlen(ext);
194
195 if (l1 > l2 && strcmp(p + l1 - l2, ext) == 0) {
196 p[l1 - l2] = 0;
197 }
198}
199
201{
202 char *p = s();
203 int i, l = strlen(p);
204
205 ext[0] = 0;
206 for (i = l - 1; i >= 0; i--) {
207 if (p[i] == '.') {
208 strcpy(ext, p + i);
209 }
210 }
211}
212
214{
215 char str[1000];
216
217 system("rm a");
218 system("date >a");
219 {
220 ifstream f1("a");
221 f1.getline(str, sizeof(str));
222 }
223 init(str);
224}
225
226}}
227
DISCRETA base class. All DISCRETA classes are derived from this class.
Definition: discreta.h:382
void copyobject(discreta_base &x)
Definition: base.cpp:194
DISCRETA string class.
Definition: discreta.h:626
std::ostream & print(std::ostream &)
Definition: hollerith.cpp:90
void read_mem(memory &m, int debug_depth)
Definition: hollerith.cpp:161
void chop_off_extension_if_present(char *ext)
Definition: hollerith.cpp:189
int compare_with(discreta_base &a)
Definition: hollerith.cpp:99
void get_extension_if_present(char *ext)
Definition: hollerith.cpp:200
void copyobject_to(discreta_base &x)
Definition: hollerith.cpp:78
void write_mem(memory &m, int debug_depth)
Definition: hollerith.cpp:146
hollerith & operator=(const discreta_base &x)
Definition: hollerith.cpp:41
DISCRETA class to serialize data structures.
Definition: discreta.h:582
#define TRUE
Definition: foundations.h:231
#define BUFSIZE
Definition: foundations.h:212
@ HOLLERITH
HOLLERITH.
Definition: discreta.h:71
the orbiter library for the classification of combinatorial objects
DISCRETA internal class.
Definition: discreta.h:353