Isis 3 Programmer Reference
Column.cpp
Go to the documentation of this file.
1 
22 #include <vector>
23 #include <string>
24 #include <iostream>
25 
26 #include "Column.h"
27 #include "IException.h"
28 #include "IString.h"
29 
30 namespace Isis {
31 
36  p_precision = 4;
37  p_width = 0;
38  p_name = "";
40  p_type = Column::NoType;
41  }
42 
51  Column::Column(QString name, int width, Column::Type type, Column::Align align) {
52  p_precision = 4;
53  p_width = 0;
54  p_name = "";
56  p_type = Column::NoType;
57 
58  //Set the parameters with function calls, to make use of pre-existing error checks
59  SetWidth(width);
60  SetName(name);
61  SetType(type);
62  SetAlignment(align);
63  }
64 
70  void Column::SetName(QString name) {
71  if (p_width != 0 && name.length() > (int)p_width) {
72  QString message = "Name [" + name + "] is wider than width";
73  throw IException(IException::User, message, _FILEINFO_);
74  }
75  p_name = name;
76  }
77 
83  void Column::SetWidth(unsigned int width) {
84  if (p_name.size() > 0 && p_name.size() > (int)width) {
85  QString message = "Width is insufficient to contain name[";
86  message += p_name + "]";
87  throw IException(IException::User, message, _FILEINFO_);
88  }
89  p_width = width;
90  }
91 
98  if (p_align == Column::Decimal &&
99  (type == Column::Integer || type == Column::String)) {
100  QString message = "Integer or string type is not sensible if ";
101  message += "alignment is Decimal.";
102  throw IException(IException::User, message, _FILEINFO_);
103  }
104  p_type = type;
105  }
106 
117  if (alignment == Column::Decimal &&
119  QString message = "Decimal alignment does not make sense for ";
120  message += "integer or string values.";
122  }
123  p_align = alignment;
124  }
125 
134  void Column::SetPrecision(unsigned int precision) {
135  if (DataType() != Column::Real &&
136  DataType() != Column::Pixel) {
137  QString message = "Setting precision only makes sense for Decimal Alignment";
138  throw IException(IException::User, message, _FILEINFO_);
139  }
140  p_precision = precision;
141  }
142 
148  QString Column::Name() const {
149  return p_name;
150  }
151 
157  unsigned int Column::Width() const {
158  return p_width;
159  }
160 
161 
168  return p_type;
169  }
170 
171 
178  return p_align;
179  }
180 
181 
187  unsigned int Column::Precision() const {
188  return p_precision;
189  }
190 }
void SetWidth(unsigned int width)
Sets the width of the Column, in text columns.
Definition: Column.cpp:83
Integer data type.
Definition: Column.h:73
unsigned int p_precision
Precision of the data in the Column.
Definition: Column.h:107
unsigned int Precision() const
Get the Column&#39;s precision.
Definition: Column.cpp:187
unsigned int Width() const
Get the Column&#39;s width.
Definition: Column.cpp:157
void SetName(QString name)
Sets the Column name, or header.
Definition: Column.cpp:70
Column::Align p_align
Alignment of the data in the Column.
Definition: Column.h:104
Column()
Constructor.
Definition: Column.cpp:35
void SetAlignment(Column::Align alignment)
Sets the alignment of the Column.
Definition: Column.cpp:116
void SetPrecision(unsigned int precision)
Sets the precision of the Column, for real number values.
Definition: Column.cpp:134
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:162
Column::Type DataType() const
Returns the type of data this column will contain.
Definition: Column.cpp:167
Real data type.
Definition: Column.h:74
String data type.
Definition: Column.h:75
Align
Alignment of data in the Column.
Definition: Column.h:60
Column::Align Alignment() const
Get the Column&#39;s alignment.
Definition: Column.cpp:177
Column::Type p_type
Type of the data in the Column.
Definition: Column.h:101
QString p_name
Name of the Column.
Definition: Column.h:95
Type
Type of data in the Column.
Definition: Column.h:70
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
unsigned int p_width
Width of the Column.
Definition: Column.h:98
decimal alignment
Definition: Column.h:64
A type of error that could only have occurred due to a mistake on the user&#39;s part (e...
Definition: IException.h:142
no alignment
Definition: Column.h:61
QString Name() const
Get the Column&#39;s name.
Definition: Column.cpp:148
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
void SetType(Column::Type type)
Sets the data type of the Column.
Definition: Column.cpp:97
No data type.
Definition: Column.h:72