Commit 1216eba79719e9a34d89b82c65c2489f70673e27

Authored by knodlseder
1 parent 749aadf6

new __str__method uses print() method

Showing 2 changed files with 145 additions and 133 deletions
pyext/GVector.i
@@ -12,7 +12,6 @@ @@ -12,7 +12,6 @@
12 ***************************************************************************/ 12 ***************************************************************************/
13 %{ 13 %{
14 /* Put headers and other declarations here that are needed for compilation */ 14 /* Put headers and other declarations here that are needed for compilation */
15 -#include "GException.hpp"  
16 #include "GVector.hpp" 15 #include "GVector.hpp"
17 %} 16 %}
18 17
@@ -23,23 +22,24 @@ @@ -23,23 +22,24 @@
23 class GVector { 22 class GVector {
24 public: 23 public:
25 24
26 - // Constructors and destructors  
27 - explicit GVector(int num);  
28 - GVector(const GVector& v);  
29 - ~GVector(); 25 + // Constructors and destructors
  26 + explicit GVector(int num);
  27 + GVector(const GVector& v);
  28 + virtual ~GVector(void);
30 29
31 - // Vector operators  
32 - GVector& operator+= (const GVector& v);  
33 - GVector& operator-= (const GVector& v);  
34 - GVector& operator+= (const double& v);  
35 - GVector& operator-= (const double& v);  
36 - GVector& operator*= (const double& v);  
37 - GVector& operator/= (const double& v);  
38 - GVector operator- () const; 30 + // Vector operators
  31 + GVector& operator+= (const GVector& v);
  32 + GVector& operator-= (const GVector& v);
  33 + GVector& operator+= (const double& v);
  34 + GVector& operator-= (const double& v);
  35 + GVector& operator*= (const double& v);
  36 + GVector& operator/= (const double& v);
  37 + GVector operator- () const;
39 38
40 - // Vector functions  
41 - int size() const; // Return dimension of vector  
42 - int non_zeros() const; // Returns # of non zeros in vector 39 + // Vector functions
  40 + void clear(void);
  41 + int size() const;
  42 + int non_zeros() const;
43 }; 43 };
44 44
45 45
@@ -47,118 +47,113 @@ public: @@ -47,118 +47,113 @@ public:
47 * GVector class SWIG extension * 47 * GVector class SWIG extension *
48 ***************************************************************************/ 48 ***************************************************************************/
49 %extend GVector { 49 %extend GVector {
50 - char *__str__() {  
51 - static char str_buffer[100001];  
52 - std::ostringstream buffer;  
53 - buffer << *self;  
54 - std::string str = buffer.str();  
55 - strncpy(str_buffer, (char*)str.c_str(), 100001);  
56 - str_buffer[100000] = '\0';  
57 - return str_buffer;  
58 - }  
59 - double __getitem__(int index) {  
60 - if (index >= 0 && index < (int)self->size())  
61 - return (*self)(index);  
62 - else  
63 - throw GException::out_of_range("__getitem__(int)", index, (int)self->size());  
64 - }  
65 - void __setitem__(int index, const double val) {  
66 - if (index>=0 && index < (int)self->size())  
67 - (*self)(index) = val;  
68 - else  
69 - throw GException::out_of_range("__setitem__(int)", index, (int)self->size());  
70 - }  
71 - GVector __add__(const GVector &a) {  
72 - return (*self) + a;  
73 - }  
74 - GVector __add__(const double &a) {  
75 - return (*self) + a;  
76 - }  
77 - GVector __sub__(const GVector &a) {  
78 - return (*self) - a;  
79 - }  
80 - GVector __sub__(const double &a) {  
81 - return (*self) - a;  
82 - }  
83 - double __mul__(const GVector &a) {  
84 - return (*self) * a;  
85 - }  
86 - GVector __mul__(const double &a) {  
87 - return (*self) * a;  
88 - }  
89 - GVector __div__(const double &a) {  
90 - return (*self) / a;  
91 - }  
92 - int __is__(const GVector &a) {  
93 - return (*self) == a;  
94 - }  
95 - GVector copy() {  
96 - return (*self);  
97 - }  
98 - GVector cross(const GVector &a) {  
99 - return cross(*self, a);  
100 - }  
101 - double norm() {  
102 - return norm(*self);  
103 - }  
104 - double min() {  
105 - return min(*self);  
106 - }  
107 - double max() {  
108 - return max(*self);  
109 - }  
110 - double sum() {  
111 - return sum(*self);  
112 - }  
113 - GVector acos() {  
114 - return acos(*self);  
115 - }  
116 - GVector acosh() {  
117 - return acosh(*self);  
118 - }  
119 - GVector asin() {  
120 - return asin(*self);  
121 - }  
122 - GVector asinh() {  
123 - return asinh(*self);  
124 - }  
125 - GVector atan() {  
126 - return atan(*self);  
127 - }  
128 - GVector atanh() {  
129 - return atanh(*self);  
130 - }  
131 - GVector cos() {  
132 - return cos(*self);  
133 - }  
134 - GVector cosh() {  
135 - return cosh(*self);  
136 - }  
137 - GVector exp() {  
138 - return exp(*self);  
139 - }  
140 - GVector abs() {  
141 - return fabs(*self);  
142 - }  
143 - GVector log() {  
144 - return log(*self);  
145 - }  
146 - GVector log10() {  
147 - return log10(*self);  
148 - }  
149 - GVector sin() {  
150 - return sin(*self);  
151 - }  
152 - GVector sinh() {  
153 - return sinh(*self);  
154 - }  
155 - GVector sqrt() {  
156 - return sqrt(*self);  
157 - }  
158 - GVector tan() {  
159 - return tan(*self);  
160 - }  
161 - GVector tanh() {  
162 - return tanh(*self);  
163 - } 50 + char *__str__() {
  51 + static std::string result = self->print();
  52 + return ((char*)result.c_str());
  53 + }
  54 + double __getitem__(int index) {
  55 + if (index >= 0 && index < (int)self->size())
  56 + return (*self)(index);
  57 + else
  58 + throw GException::out_of_range("__getitem__(int)", index, (int)self->size());
  59 + }
  60 + void __setitem__(int index, const double val) {
  61 + if (index>=0 && index < (int)self->size())
  62 + (*self)(index) = val;
  63 + else
  64 + throw GException::out_of_range("__setitem__(int)", index, (int)self->size());
  65 + }
  66 + GVector __add__(const GVector &a) {
  67 + return (*self) + a;
  68 + }
  69 + GVector __add__(const double &a) {
  70 + return (*self) + a;
  71 + }
  72 + GVector __sub__(const GVector &a) {
  73 + return (*self) - a;
  74 + }
  75 + GVector __sub__(const double &a) {
  76 + return (*self) - a;
  77 + }
  78 + double __mul__(const GVector &a) {
  79 + return (*self) * a;
  80 + }
  81 + GVector __mul__(const double &a) {
  82 + return (*self) * a;
  83 + }
  84 + GVector __div__(const double &a) {
  85 + return (*self) / a;
  86 + }
  87 + int __is__(const GVector &a) {
  88 + return (*self) == a;
  89 + }
  90 + GVector copy() {
  91 + return (*self);
  92 + }
  93 + GVector cross(const GVector &a) {
  94 + return cross(*self, a);
  95 + }
  96 + double norm() {
  97 + return norm(*self);
  98 + }
  99 + double min() {
  100 + return min(*self);
  101 + }
  102 + double max() {
  103 + return max(*self);
  104 + }
  105 + double sum() {
  106 + return sum(*self);
  107 + }
  108 + GVector acos() {
  109 + return acos(*self);
  110 + }
  111 + GVector acosh() {
  112 + return acosh(*self);
  113 + }
  114 + GVector asin() {
  115 + return asin(*self);
  116 + }
  117 + GVector asinh() {
  118 + return asinh(*self);
  119 + }
  120 + GVector atan() {
  121 + return atan(*self);
  122 + }
  123 + GVector atanh() {
  124 + return atanh(*self);
  125 + }
  126 + GVector cos() {
  127 + return cos(*self);
  128 + }
  129 + GVector cosh() {
  130 + return cosh(*self);
  131 + }
  132 + GVector exp() {
  133 + return exp(*self);
  134 + }
  135 + GVector abs() {
  136 + return fabs(*self);
  137 + }
  138 + GVector log() {
  139 + return log(*self);
  140 + }
  141 + GVector log10() {
  142 + return log10(*self);
  143 + }
  144 + GVector sin() {
  145 + return sin(*self);
  146 + }
  147 + GVector sinh() {
  148 + return sinh(*self);
  149 + }
  150 + GVector sqrt() {
  151 + return sqrt(*self);
  152 + }
  153 + GVector tan() {
  154 + return tan(*self);
  155 + }
  156 + GVector tanh() {
  157 + return tanh(*self);
  158 + }
164 }; 159 };
pyext/GWcs.i
@@ -42,9 +42,10 @@ public: @@ -42,9 +42,10 @@ public:
42 virtual ~GWcs(void); 42 virtual ~GWcs(void);
43 43
44 // Pure virtual methods (not implemented) 44 // Pure virtual methods (not implemented)
45 - virtual void clear(void) = 0;  
46 - virtual void read(const GFitsHDU* hdu) = 0;  
47 - virtual void write(GFitsHDU* hdu) const = 0; 45 + virtual void clear(void) = 0;
  46 + virtual GWcs* clone(void) const = 0;
  47 + virtual void read(const GFitsHDU* hdu) = 0;
  48 + virtual void write(GFitsHDU* hdu) const = 0;
48 49
49 // Virtual methods 50 // Virtual methods
50 virtual std::string type(void) const; 51 virtual std::string type(void) const;
@@ -57,3 +58,19 @@ public: @@ -57,3 +58,19 @@ public:
57 virtual GSkyDir xy2dir(const GSkyPixel& pix); 58 virtual GSkyDir xy2dir(const GSkyPixel& pix);
58 virtual GSkyPixel dir2xy(GSkyDir dir) const; 59 virtual GSkyPixel dir2xy(GSkyDir dir) const;
59 }; 60 };
  61 +
  62 +
  63 +
  64 +
  65 +/***********************************************************************//**
  66 + * @brief GWcs class extension
  67 + ***************************************************************************/
  68 +%extend GWcs {
  69 + char *__str__() {
  70 + static std::string result = self->print();
  71 + return ((char*)result.c_str());
  72 + }
  73 + bool __is__(const GWcs &a) {
  74 + return (*self) == a;
  75 + }
  76 +};