Isis 3 Programmer Reference
Column.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include <vector>
8 #include <string>
9 #include <iostream>
10 
11 #include "Column.h"
12 #include "IException.h"
13 #include "IString.h"
14 
15 namespace Isis {
16 
21  p_precision = 4;
22  p_width = 0;
23  p_name = "";
25  p_type = Column::NoType;
26  }
27 
36  Column::Column(QString name, int width, Column::Type type, Column::Align align) {
37  p_precision = 4;
38  p_width = 0;
39  p_name = "";
41  p_type = Column::NoType;
42 
43  //Set the parameters with function calls, to make use of pre-existing error checks
44  SetWidth(width);
45  SetName(name);
46  SetType(type);
47  SetAlignment(align);
48  }
49 
55  void Column::SetName(QString name) {
56  if (p_width != 0 && name.length() > (int)p_width) {
57  QString message = "Name [" + name + "] is wider than width";
58  throw IException(IException::User, message, _FILEINFO_);
59  }
60  p_name = name;
61  }
62 
68  void Column::SetWidth(unsigned int width) {
69  if (p_name.size() > 0 && p_name.size() > (int)width) {
70  QString message = "Width is insufficient to contain name[";
71  message += p_name + "]";
72  throw IException(IException::User, message, _FILEINFO_);
73  }
74  p_width = width;
75  }
76 
83  if (p_align == Column::Decimal &&
84  (type == Column::Integer || type == Column::String)) {
85  QString message = "Integer or string type is not sensible if ";
86  message += "alignment is Decimal.";
87  throw IException(IException::User, message, _FILEINFO_);
88  }
89  p_type = type;
90  }
91 
102  if (alignment == Column::Decimal &&
104  QString message = "Decimal alignment does not make sense for ";
105  message += "integer or string values.";
106  throw IException(IException::Programmer, message, _FILEINFO_);
107  }
108  p_align = alignment;
109  }
110 
119  void Column::SetPrecision(unsigned int precision) {
120  if (DataType() != Column::Real &&
121  DataType() != Column::Pixel) {
122  QString message = "Setting precision only makes sense for Decimal Alignment";
123  throw IException(IException::User, message, _FILEINFO_);
124  }
125  p_precision = precision;
126  }
127 
133  QString Column::Name() const {
134  return p_name;
135  }
136 
142  unsigned int Column::Width() const {
143  return p_width;
144  }
145 
146 
153  return p_type;
154  }
155 
156 
163  return p_align;
164  }
165 
166 
172  unsigned int Column::Precision() const {
173  return p_precision;
174  }
175 }
Isis::Column::NoAlign
@ NoAlign
no alignment
Definition: Column.h:46
Isis::Column::Precision
unsigned int Precision() const
Get the Column's precision.
Definition: Column.cpp:172
Isis::Column::Pixel
@ Pixel
String data type.
Definition: Column.h:60
Isis::Column::Decimal
@ Decimal
decimal alignment
Definition: Column.h:49
Isis::Column::Column
Column()
Constructor.
Definition: Column.cpp:20
Isis::Column::p_type
Column::Type p_type
Type of the data in the Column.
Definition: Column.h:86
Isis::Column::Align
Align
Alignment of data in the Column.
Definition: Column.h:45
Isis::Column::Integer
@ Integer
No data type.
Definition: Column.h:57
Isis::Column::Width
unsigned int Width() const
Get the Column's width.
Definition: Column.cpp:142
Isis::Column::Real
@ Real
Integer data type.
Definition: Column.h:58
Isis::Column::p_precision
unsigned int p_precision
Precision of the data in the Column.
Definition: Column.h:92
Isis::Column::DataType
Column::Type DataType() const
Returns the type of data this column will contain.
Definition: Column.cpp:152
Isis::Column::SetAlignment
void SetAlignment(Column::Align alignment)
Sets the alignment of the Column.
Definition: Column.cpp:101
Isis::Column::SetPrecision
void SetPrecision(unsigned int precision)
Sets the precision of the Column, for real number values.
Definition: Column.cpp:119
Isis::Column::p_name
QString p_name
Name of the Column.
Definition: Column.h:80
Isis::Column::Name
QString Name() const
Get the Column's name.
Definition: Column.cpp:133
Isis::Column::Alignment
Column::Align Alignment() const
Get the Column's alignment.
Definition: Column.cpp:162
Isis::Column::SetType
void SetType(Column::Type type)
Sets the data type of the Column.
Definition: Column.cpp:82
Isis::Column::Type
Type
Type of data in the Column.
Definition: Column.h:55
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
Isis::Column::p_width
unsigned int p_width
Width of the Column.
Definition: Column.h:83
Isis::Column::String
@ String
Real data type.
Definition: Column.h:59
Isis::Column::SetName
void SetName(QString name)
Sets the Column name, or header.
Definition: Column.cpp:55
Isis::Column::p_align
Column::Align p_align
Alignment of the data in the Column.
Definition: Column.h:89
Isis::Column::SetWidth
void SetWidth(unsigned int width)
Sets the width of the Column, in text columns.
Definition: Column.cpp:68
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::IException::User
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition: IException.h:126