blob: d0b90d1d8512664d75674dcee8e5ea9c30ba15bd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
// Copyright (C) 1999-2018
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"
#include <string.h>
#include <iostream>
#include <sstream>
#include <iomanip>
using namespace std;
#include "vectorstr.h"
#include "vector.h"
#include "vector3d.h"
static char* dupstr(const char* str)
{
char* copy;
if (str) {
copy=new char[strlen(str)+1];
strcpy(copy,str);
}
else
copy=NULL;
return copy;
}
// VectorStr
VectorStr::~VectorStr()
{
if (c[0])
delete [] c[0];
if (c[1])
delete [] c[1];
}
VectorStr::VectorStr(const char* aa, const char* bb)
{
c[0] = dupstr(aa);
c[1] = dupstr(bb);
}
VectorStr::VectorStr(const VectorStr& vv)
{
c[0] = dupstr(vv.c[0]);
c[1] = dupstr(vv.c[1]);
}
VectorStr::VectorStr(const Vector& vv)
{
ostringstream str0;
str0 << vv[0];
c[0] = dupstr(str0.str().c_str());
ostringstream str1;
str1 << vv[1];
c[1] = dupstr(str1.str().c_str());
}
VectorStr& VectorStr::operator=(const VectorStr& vv)
{
if (c[0])
delete [] c[0];
c[0]=dupstr(vv.c[0]);
if (c[1])
delete [] c[1];
c[1]=dupstr(vv.c[1]);
return *this;
}
VectorStr& VectorStr::operator=(const Vector& vv)
{
if (c[0])
delete [] c[0];
ostringstream str0;
str0 << vv[0];
c[0] = dupstr(str0.str().c_str());
if (c[1])
delete [] c[1];
ostringstream str1;
str1 << vv[1];
c[1] = dupstr(str1.str().c_str());
return *this;
}
ostream& operator<<(ostream& os, const VectorStr& vv)
{
unsigned char sep = (unsigned char)os.iword(Vector::separator);
if (!sep)
sep = ' ';
unsigned char unit = (unsigned char)os.iword(Vector::unit);
if (!unit)
os << vv.c[0] << sep << vv.c[1];
else
os << vv.c[0] << unit << sep << vv.c[1] << unit;
// reset unit
os.iword(Vector::unit) = '\0';
return os;
}
// VectorStr3d
VectorStr3d::~VectorStr3d()
{
if (c[0])
delete [] c[0];
if (c[1])
delete [] c[1];
if (c[2])
delete [] c[2];
}
VectorStr3d::VectorStr3d(const char* aa, const char* bb, const char* cc)
{
c[0] = dupstr(aa);
c[1] = dupstr(bb);
c[2] = dupstr(cc);
}
VectorStr3d::VectorStr3d(const VectorStr3d& vv)
{
c[0] = dupstr(vv.c[0]);
c[1] = dupstr(vv.c[1]);
c[2] = dupstr(vv.c[2]);
}
VectorStr3d::VectorStr3d(const Vector3d& vv)
{
ostringstream str0;
str0 << vv[0];
c[0] = dupstr(str0.str().c_str());
ostringstream str1;
str1 << vv[1];
c[1] = dupstr(str1.str().c_str());
ostringstream str2;
str2 << vv[2];
c[2] = dupstr(str2.str().c_str());
}
VectorStr3d& VectorStr3d::operator=(const VectorStr3d& vv)
{
if (c[0])
delete [] c[0];
c[0]=dupstr(vv.c[0]);
if (c[1])
delete [] c[1];
c[1]=dupstr(vv.c[1]);
if (c[2])
delete [] c[2];
c[2]=dupstr(vv.c[2]);
return *this;
}
VectorStr3d& VectorStr3d::operator=(const Vector3d& vv)
{
if (c[0])
delete [] c[0];
ostringstream str0;
str0 << vv[0];
c[0] = dupstr(str0.str().c_str());
if (c[1])
delete [] c[1];
ostringstream str1;
str1 << vv[1];
c[1] = dupstr(str1.str().c_str());
if (c[2])
delete [] c[2];
ostringstream str2;
str2 << vv[2];
c[2] = dupstr(str2.str().c_str());
return *this;
}
ostream& operator<<(ostream& os, const VectorStr3d& vv)
{
unsigned char sep = (unsigned char)os.iword(Vector::separator);
if (!sep)
sep = ' ';
unsigned char unit = (unsigned char)os.iword(Vector::unit);
if (!unit)
os << vv.c[0] << sep << vv.c[1] << sep << vv.c[2];
else
os << vv.c[0] << unit << sep << vv.c[1] << unit << sep << vv.c[2] << unit;
// reset unit
os.iword(Vector::unit) = '\0';
return os;
}
|