casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TBArray.h
Go to the documentation of this file.
1 //# TBArray.h: Holds a potentially multi-dimensional array.
2 //# Copyright (C) 2005
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: $
27 #ifndef TBARRAY_H_
28 #define TBARRAY_H_
29 
30 #include <casa/BasicSL/String.h>
31 
32 #include <vector>
33 
34 namespace casa {
35 
36 //# Forward Declarations
37 class TBTable;
38 
39 // <summary>
40 // Holds a potentially multi-dimensional array.
41 // <summary>
42 //
43 // <synopsis>
44 // A TBArray holds a array object as used by the table browser. The data
45 // is represented by casacore::String values, while the array structure is represented by
46 // vectors of void*s. For all but the "last" dimension, the void*s point to
47 // other vector<void*>s, and on the last dimension the void*s point to Strings.
48 // NOTE: this class is mostly obsolete now that the browser uses the TBData
49 // structure.
50 // </synopsis>
51 
52 class TBArray {
53 public:
54  // Constructor for a data array (in other words, an array found in the data
55  // of a table). Takes as input the row and column of the array in table,
56  // the type of table, and the casacore::String holding the values of the array which
57  // need to be parsed.
59 
60  // Constructor for a table keyword array (in other words, an array found in
61  // the table keywords). Takes as input the index of the keyword in the
62  // table keywords list, the type of the array, and the casacore::String holding the
63  // values of the array which need to be parsed.
64  TBArray(int keywordIndex, casacore::String type, casacore::String array);
65 
66  // Constructor for a field keyword array (in other words, an array found in
67  // the field keywords). Takes as input the name of the field, the index of
68  // the keyword in the field keywords list, the type of the array, and the
69  // casacore::String holding the values of the array which need to be parsed.
70  TBArray(casacore::String col, int index, casacore::String type, casacore::String array);
71 
72  // Constructor for a non-specific array. Takes as input the type of the
73  // array and the casacore::String holding the values of the array which need to be
74  // parsed.
76 
77  ~TBArray();
78 
79 
80  // Returns true if the array is valid, false otherwise.
81  bool isValid();
82 
83  // Returns the dimensions of the array in list format.
84  std::vector<int> getDimensions();
85 
86  // Returns the dimensionality of the array. For example, a 4x4 array
87  // would return 2 while a 4x4x4 array would return 3.
88  unsigned int dim();
89 
90  // If the dimensions are thought of as a list (e.g., 2x4x2), then this
91  // method returns the ith dimension in the list.
92  int dimensionAt(unsigned int i);
93 
94  // Returns true if the array is one-dimensional, false otherwise.
95  bool isOneDimensional();
96 
97  // Returns the type of the array.
99 
100  // Returns the data representation. In all but the last dimension, the
101  // void*s point to vector<void*>s; in the last dimension the void*s point
102  // to Strings.
103  std::vector<void*>* getData();
104 
105  // Returns the row of the table where the array is located. This is only
106  // valid for data arrays.
107  int getRow();
108 
109  // Returns the column of the table where the array is located. This is
110  // only valid for data arrays.
111  int getCol();
112 
113 
114  // Returns true if the given array is in the same location as this array,
115  // false otherwise.
116  // For data arrays: true if the row and col values are equal;
117  // for table keyword arrays: true if they refer to the same keyword index;
118  // for field keyword arrays: true if the fields are the same and the
119  // keyword indices are the same.
120  bool sameLocationAs(TBArray* array);
121 
122  // Returns the name of this array, assuming that it belongs to the given
123  // table. For data arrays: "[table name][[row],[col]]";
124  // for table keyword arrays: "[table name] [keyword name]";
125  // for field keyword arrays: "[table name] [field name, keyword name]".
127 
128  // Returns the data at the given coordinates, or blank if the coordinates
129  // are invalid.
130  casacore::String dataAt(std::vector<int> d);
131 
132  // Sets the data at the given coordinates to the given value. This call
133  // does NOT write through to the underlying table; it only updates the data
134  // representation.
135  void setDataAt(std::vector<int> d, casacore::String newVal);
136 
137  // Returns true if the given coordinates are valid for this array, false
138  // otherwise.
139  bool dimensionIsValid(std::vector<int> d);
140 
141  // Returns a "flattened" casacore::String representation of this array. Each cell
142  // is appended to the casacore::String separated by a space.
144 
145  // Returns true if this array contains the given value, false otherwise.
147 
148  // Returns true if this array contains any value that is between the two
149  // given values, false otherwise.
151 
152  // Returns true if this array contains any value that is less than the
153  // given value, false otherwise.
155 
156  // Returns true if this array contains any value that is greater than the
157  // given value, false otherwise.
159 
160 private:
161  // Holds the dimensions of this array.
162  std::vector<int> dimensions;
163 
164  // casacore::Data representation.
165  std::vector<void*> data;
166 
167  // Indicates whether the array is valid or not.
168  bool valid;
169 
170  // The type of the array.
172 
173  // The row of the array for data arrays, or the keyword index for other
174  // arrays.
175  int row;
176 
177  // The column of the array for data arrays, invalid for other arrays.
178  int col;
179 
180  // Indicates whether this array is one-dimensional or not.
181  bool oneDim;
182 
183  // Indicates whether this is a data array or not.
184  bool isData;
185 
186  // Indicates whether this is a field keyword array or not.
188 
189  // Holds the field name for a field keyword array, empty otherwise.
191 
192 
193  // Parses the given casacore::String into the array.
194  void parseArray(casacore::String* table);
195 
196  // Helper for parseArray(). Parses a single row into the given vector.
197  casacore::String parseRow(casacore::String& str, std::vector<void*>* r, std::vector<int> d, int x);
198 
199  // Helper for parseArray(). Parses a table with dimension > 1.
201 
202  // Helper for parseArray(). Creates placeholder objects (such as empty
203  // Strings and vectors) into the given row.
204  void insertPlaceholders(std::vector<void*>* r, std::vector<int> d, int x);
205 
206  // Helper method for toFlattenedString();
207  casacore::String toFlattenedString(std::vector<void*>* row, int d);
208 
209  // Helper method for contains().
210  bool contains(std::vector<void*>* data, int n, casacore::String v);
211 
212  // Helper method for containsBetween().
213  bool containsBetween(std::vector<void*>* data, int n, double v1, double v2);
214 
215  // Helper method for containsLessThan().
216  bool containsLessThan(std::vector<void*>* data, int n, double v);
217 
218  // Helper method for containsGreaterThan().
219  bool containsGreaterThan(std::vector<void*>* data, int n, double v);
220 
221  // Deletes the data in the given row.
222  void deleteData(std::vector<void*>* data, int n);
223 };
224 
225 }
226 
227 #endif /* TBARRAY_H_ */
void deleteData(std::vector< void * > *data, int n)
Deletes the data in the given row.
casacore::String getName(TBTable *table)
Returns the name of this array, assuming that it belongs to the given table.
bool valid
Indicates whether the array is valid or not.
Definition: TBArray.h:168
casacore::String getType()
Returns the type of the array.
int getRow()
Returns the row of the table where the array is located.
bool containsGreaterThan(casacore::String value)
Returns true if this array contains any value that is greater than the given value, false otherwise.
void parseArray(casacore::String *table)
Parses the given casacore::String into the array.
TableExprNode array(const TableExprNode &values, const TableExprNodeSet &shape)
Create an array of the given shape and fill it with the values.
Definition: ExprNode.h:1886
bool containsLessThan(casacore::String value)
Returns true if this array contains any value that is less than the given value, false otherwise...
casacore::String parseRow(casacore::String &str, std::vector< void * > *r, std::vector< int > d, int x)
Helper for parseArray().
casacore::String toFlattenedString()
Returns a &quot;flattened&quot; casacore::String representation of this array.
void setDataAt(std::vector< int > d, casacore::String newVal)
Sets the data at the given coordinates to the given value.
int col
The column of the array for data arrays, invalid for other arrays.
Definition: TBArray.h:178
TBArray(int row, int col, casacore::String type, casacore::String array)
Constructor for a data array (in other words, an array found in the data of a table).
bool isData
Indicates whether this is a data array or not.
Definition: TBArray.h:184
bool isValid()
Returns true if the array is valid, false otherwise.
Primary interface for the rest of the browser to a table.
Definition: TBTable.h:152
int getCol()
Returns the column of the table where the array is located.
bool sameLocationAs(TBArray *array)
Returns true if the given array is in the same location as this array, false otherwise.
std::vector< void * > data
casacore::Data representation.
Definition: TBArray.h:165
casacore::String dataAt(std::vector< int > d)
Returns the data at the given coordinates, or blank if the coordinates are invalid.
unsigned int dim()
Returns the dimensionality of the array.
casacore::String type
The type of the array.
Definition: TBArray.h:171
bool contains(casacore::String value)
Returns true if this array contains the given value, false otherwise.
std::vector< int > getDimensions()
Returns the dimensions of the array in list format.
int dimensionAt(unsigned int i)
If the dimensions are thought of as a list (e.g., 2x4x2), then this method returns the ith dimension ...
casacore::String field
Holds the field name for a field keyword array, empty otherwise.
Definition: TBArray.h:190
String: the storage and methods of handling collections of characters.
Definition: String.h:223
void parseMultidimensionalTable(casacore::String str)
Helper for parseArray().
std::vector< void * > * getData()
Returns the data representation.
std::vector< int > dimensions
Holds the dimensions of this array.
Definition: TBArray.h:162
void insertPlaceholders(std::vector< void * > *r, std::vector< int > d, int x)
Helper for parseArray().
bool oneDim
Indicates whether this array is one-dimensional or not.
Definition: TBArray.h:181
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
bool containsBetween(casacore::String value1, casacore::String value2)
Returns true if this array contains any value that is between the two given values, false otherwise.
int row
The row of the array for data arrays, or the keyword index for other arrays.
Definition: TBArray.h:175
bool isColKeyword
Indicates whether this is a field keyword array or not.
Definition: TBArray.h:187
bool isOneDimensional()
Returns true if the array is one-dimensional, false otherwise.
Holds a potentially multi-dimensional array.
Definition: TBArray.h:52
bool dimensionIsValid(std::vector< int > d)
Returns true if the given coordinates are valid for this array, false otherwise.