summaryrefslogtreecommitdiffstats
path: root/tksao/vector
diff options
context:
space:
mode:
authorWilliam Joye <wjoye@cfa.harvard.edu>2018-08-15 19:47:24 (GMT)
committerWilliam Joye <wjoye@cfa.harvard.edu>2018-08-15 19:47:24 (GMT)
commitd51d3f66c47101fcaaf39f90d77950156fc05648 (patch)
tree528d26a58b1aa5518c2140a61ab7d5a9a50e6b27 /tksao/vector
parent9c929fe95cf992440ce00ab90a6abb210d2dab88 (diff)
downloadblt-d51d3f66c47101fcaaf39f90d77950156fc05648.zip
blt-d51d3f66c47101fcaaf39f90d77950156fc05648.tar.gz
blt-d51d3f66c47101fcaaf39f90d77950156fc05648.tar.bz2
simplify getInfo code
Diffstat (limited to 'tksao/vector')
-rw-r--r--tksao/vector/vectorstr.C64
-rw-r--r--tksao/vector/vectorstr.h18
2 files changed, 82 insertions, 0 deletions
diff --git a/tksao/vector/vectorstr.C b/tksao/vector/vectorstr.C
index 145bebc..c77ef16 100644
--- a/tksao/vector/vectorstr.C
+++ b/tksao/vector/vectorstr.C
@@ -62,3 +62,67 @@ istream& operator>>(istream& ss, VectorStr& vv)
ss >> vv.c[0] >> vv.c[1];
return ss;
}
+
+// 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::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;
+}
+
+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;
+}
+
+istream& operator>>(istream& ss, VectorStr3d& vv)
+{
+ ss >> vv.c[0] >> vv.c[1] >> vv.c[2];
+ return ss;
+}
diff --git a/tksao/vector/vectorstr.h b/tksao/vector/vectorstr.h
index dbf8d49..36587ad 100644
--- a/tksao/vector/vectorstr.h
+++ b/tksao/vector/vectorstr.h
@@ -25,6 +25,24 @@ class VectorStr {
ostream& operator<<(ostream&, const VectorStr&);
istream& operator>>(istream&, VectorStr&);
+
+class VectorStr3d {
+ public:
+ char* c[3];
+
+ public:
+ VectorStr3d() {c[0]=NULL; c[1]=NULL; c[2]=NULL;}
+ ~VectorStr3d();
+ VectorStr3d(const char*, const char*, const char*);
+ VectorStr3d(const VectorStr3d&);
+ VectorStr3d& operator=(const VectorStr3d&);
+
+ const char* operator[](int i) const {return c[i];} // return element
+ char** cc() {return c;} // return vector
+};
+
+ostream& operator<<(ostream&, const VectorStr3d&);
+istream& operator>>(istream&, VectorStr3d&);
#endif