summaryrefslogtreecommitdiffstats
path: root/tksao/vector
diff options
context:
space:
mode:
authorWilliam Joye <wjoye@cfa.harvard.edu>2018-08-16 16:52:55 (GMT)
committerWilliam Joye <wjoye@cfa.harvard.edu>2018-08-16 16:52:55 (GMT)
commit33b8f9fd852477630addbf48a59d01849df5a096 (patch)
tree37188a077cc674a1afcd952bc8126283d9d918b3 /tksao/vector
parent2e9a4d3293f9a27883d525abaaa5459a67b063af (diff)
downloadblt-33b8f9fd852477630addbf48a59d01849df5a096.zip
blt-33b8f9fd852477630addbf48a59d01849df5a096.tar.gz
blt-33b8f9fd852477630addbf48a59d01849df5a096.tar.bz2
simplify wcs code
Diffstat (limited to 'tksao/vector')
-rw-r--r--tksao/vector/vectorstr.C83
-rw-r--r--tksao/vector/vectorstr.h8
2 files changed, 77 insertions, 14 deletions
diff --git a/tksao/vector/vectorstr.C b/tksao/vector/vectorstr.C
index c77ef16..7d0576c 100644
--- a/tksao/vector/vectorstr.C
+++ b/tksao/vector/vectorstr.C
@@ -28,14 +28,44 @@ VectorStr::VectorStr(const VectorStr& vv)
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;
}
@@ -57,12 +87,6 @@ ostream& operator<<(ostream& os, const VectorStr& vv)
return os;
}
-istream& operator>>(istream& ss, VectorStr& vv)
-{
- ss >> vv.c[0] >> vv.c[1];
- return ss;
-}
-
// VectorStr3d
VectorStr3d::~VectorStr3d()
@@ -89,17 +113,58 @@ VectorStr3d::VectorStr3d(const VectorStr3d& vv)
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;
}
@@ -120,9 +185,3 @@ ostream& operator<<(ostream& os, const VectorStr3d& vv)
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 36587ad..71181fb 100644
--- a/tksao/vector/vectorstr.h
+++ b/tksao/vector/vectorstr.h
@@ -5,6 +5,8 @@
#ifndef __vectorstr_h__
#define __vectorstr_h__
+#include "vector.h"
+
#include <iostream>
using namespace std;
@@ -17,14 +19,15 @@ class VectorStr {
~VectorStr();
VectorStr(const char*, const char*);
VectorStr(const VectorStr&);
+ VectorStr(const Vector&);
VectorStr& operator=(const VectorStr&);
+ VectorStr& operator=(const Vector&);
const char* operator[](int i) const {return c[i];} // return element
char** cc() {return c;} // return vector
};
ostream& operator<<(ostream&, const VectorStr&);
-istream& operator>>(istream&, VectorStr&);
class VectorStr3d {
public:
@@ -35,14 +38,15 @@ class VectorStr3d {
~VectorStr3d();
VectorStr3d(const char*, const char*, const char*);
VectorStr3d(const VectorStr3d&);
+ VectorStr3d(const Vector3d&);
VectorStr3d& operator=(const VectorStr3d&);
+ VectorStr3d& operator=(const Vector3d&);
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