7 #include "TableField.h" 
    9 #include "IException.h" 
   11 #include "PvlKeyword.h" 
   30     if (m_type == TableField::Integer) {
 
   32       m_ivalues.resize(m_size);
 
   34     else if (m_type == TableField::Double) {
 
   36       m_dvalues.resize(m_size);
 
   38     else if (m_type == TableField::Text) {
 
   40       m_svalue.resize(m_size);
 
   42     else if (m_type == TableField::Real) {
 
   44       m_rvalues.resize(m_size);
 
   60     m_name = (QString) field[
"Name"];
 
   61     m_size = (int) field[
"Size"];
 
   62     if ((QString) field[
"Type"] == 
"Integer") {
 
   63       m_type = TableField::Integer;
 
   65       m_ivalues.resize(m_size);
 
   67     else if ((QString) field[
"Type"] == 
"Double") {
 
   68       m_type = TableField::Double;
 
   70       m_dvalues.resize(m_size);
 
   72     else if ((QString) field[
"Type"] == 
"Text") {
 
   73       m_type = TableField::Text;
 
   75       m_svalue.resize(m_size);
 
   77     else if ((QString) field[
"Type"] == 
"Real") {
 
   78       m_type = TableField::Real;
 
   80       m_rvalues.resize(m_size);
 
   83       QString msg = 
"Field [" + m_name + 
"] has invalid type.";
 
   84       throw IException(IException::Programmer, msg, _FILEINFO_);
 
   89   TableField::~TableField() {
 
   97   QString TableField::name()
 const {
 
  122   bool TableField::isInteger()
 const {
 
  123     return (m_type == TableField::Integer);
 
  132   bool TableField::isDouble()
 const {
 
  133     return (m_type == TableField::Double);
 
  141   bool TableField::isText()
 const {
 
  142     return (m_type == TableField::Text);
 
  150   bool TableField::isReal()
 const {
 
  151     return (m_type == TableField::Real);
 
  159   int TableField::bytes()
 const {
 
  168   int TableField::size()
 const {
 
  188   TableField::operator int()
 const {
 
  189     if (m_type != TableField::Integer) {
 
  190       QString msg = 
"Field [" + m_name + 
"] is not Integer.";
 
  191       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  193     if (m_ivalues.size() > 1) {
 
  194       QString msg = 
"Field [" + m_name + 
"] has multiple Integer values. " 
  195                    "Use std::vector<int>().";
 
  196       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  217   TableField::operator double()
 const {
 
  218     if (m_type != TableField::Double) {
 
  219       QString msg = 
"Field [" + m_name + 
"] is not a Double.";
 
  220       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  222     if (m_dvalues.size() > 1) {
 
  223       QString msg = 
"Field [" + m_name + 
"] has multiple Double values. " 
  224                    "Use std::vector<double>().";
 
  225       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  246   TableField::operator float()
 const {
 
  247     if (m_type != TableField::Real) {
 
  248       QString msg = 
"Field [" + m_name + 
"] is not Real.";
 
  249       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  251     if (m_rvalues.size() > 1) {
 
  252       QString msg = 
"Field [" + m_name + 
"] has multiple Real values. " 
  253                    "Use std::vector<float>().";
 
  254       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  273   TableField::operator QString()
 const {
 
  274     if (m_type != TableField::Text) {
 
  275       QString msg = 
"Field [" + m_name + 
"] is not Text.";
 
  276       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  278     return QString(m_svalue.toLatin1().data());
 
  293   TableField::operator std::vector<int>()
 const {
 
  294     if (m_type != TableField::Integer) {
 
  295       QString msg = 
"Field [" + m_name + 
"] is not an Integer array.";
 
  296       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  313   TableField::operator std::vector<double>()
 const {
 
  314     if (m_type != TableField::Double) {
 
  315       QString msg = 
"Field [" + m_name + 
"] is not a Double array.";
 
  316       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  333   TableField::operator std::vector<float>()
 const {
 
  334     if (m_type != TableField::Real) {
 
  335       QString msg = 
"Field [" + m_name + 
"] is not a Real array.";
 
  336       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  350   void TableField::operator=(
const int value) {
 
  351     if (m_type != TableField::Integer) {
 
  352       QString msg = 
"Unable to set field to the given int value. Field ["  
  353                    + m_name + 
"] Type is not Integer.";
 
  354       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  357       QString msg = 
"Unable to set field to the given int value. " 
  359                     "Integer values. Use operator=(vector<int>).";
 
  360       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  362     m_ivalues[0] = value;
 
  374   void TableField::operator=(
const double value) {
 
  375     if (m_type != TableField::Double) {
 
  376       QString msg = 
"Unable to set field to the given double value. Field ["  
  377                    + m_name + 
"] Type is not Double.";
 
  378       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  381       QString msg = 
"Unable to set field to the given double value. " 
  383                     "Double values. Use operator=(vector<double>).";
 
  384       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  386     m_dvalues[0] = value;
 
  398   void TableField::operator=(
const float value) {
 
  399     if (m_type != TableField::Real) {
 
  400       QString msg = 
"Unable to set field to the given float value. Field ["  
  401                    + m_name + 
"] Type is not Real.";
 
  402       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  405       QString msg = 
"Unable to set field to the given float value. " 
  407                     "Real values. Use operator=(vector<float>).";
 
  408       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  410     m_rvalues[0] = value;
 
  420   void TableField::operator=(
const QString &value) {
 
  422     if (m_type != TableField::Text) {
 
  423       QString msg = 
"Unable to set field to the given string value. Field ["  
  424                     + m_name + 
"] Type is not Text.";
 
  425       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  427     if (m_size < (
int) val.size()) {
 
  428       for (
int i = m_size; i < val.size(); i++) {
 
  430         if (val[i] != 
' ' && val[i] != 
'\0') {
 
  431           QString msg = 
"Unable to set the Text TableField to the given string. " 
  432                         "The number of bytes allowed for this field value ["  
  434                         "given string [" + value + 
"].";
 
  435           throw IException(IException::Unknown, msg, _FILEINFO_);
 
  453   void TableField::operator=(
const std::vector<int> &values) {
 
  454     if (m_type != TableField::Integer) {
 
  455       QString msg = 
"Unable to set field to the given vector of int values. " 
  456                     "Field [" + m_name + 
"] Type is not Integer.";
 
  457       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  459     else if ((
int) values.size() != m_size) {
 
  460       QString msg = 
"Unable to set field to the given vector of int values. " 
  461                     "Field [" + m_name + 
"] values has size ["  
  463       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  477   void TableField::operator=(
const std::vector<double> &values) {
 
  478     if (m_type != TableField::Double) {
 
  479       QString msg = 
"Unable to set field to the given vector of double values. " 
  480                     "Field [" + m_name + 
"] Type is not Double.";
 
  481       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  483     else if ((
int) values.size() != m_size) {
 
  484       QString msg = 
"Unable to set field to the given vector of double values. " 
  485                     "Field [" + m_name + 
"] values has size ["  
  487       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  502   void TableField::operator=(
const std::vector<float> &values) {
 
  503     if (m_type != TableField::Real) {
 
  504       QString msg = 
"Unable to set field to the given vector of float values. " 
  505                     "Field [" + m_name + 
"] Type is not Real.";
 
  506       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  508     else if ((
int) values.size() != m_size) {
 
  509       QString msg = 
"Unable to set field to the given vector of float values. " 
  510                     "Field [" + m_name + 
"] values has size ["  
  512       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  528   void TableField::operator=(
const void *ibuf) {
 
  529     char *buf = (
char *) ibuf;
 
  530     if (m_type == TableField::Double) {
 
  531       for (
unsigned int i = 0; i < m_dvalues.size(); i++) {
 
  534         memmove(&bufDouble, buf + i * 8, 8);
 
  535         m_dvalues[i] = bufDouble;
 
  538     else if (m_type == TableField::Integer) {
 
  539       for (
unsigned int i = 0; i < m_ivalues.size(); i++) {
 
  542         memmove(&bufInt, buf + i * 4, 4);
 
  543         m_ivalues[i] = bufInt;
 
  546     else if (m_type == TableField::Text) {
 
  547       m_svalue.resize(bytes());
 
  548       for (
int i = 0; i < bytes(); i++) {
 
  549         m_svalue[i] = buf[i];
 
  552     else if (m_type == TableField::Real) {
 
  553       for (
unsigned int i = 0; i < m_rvalues.size(); i++) {
 
  556         memmove(&bufFloat, buf + i * 4, 4);
 
  557         m_rvalues[i] = bufFloat;
 
  561       string msg = 
"Undefined field type [" + 
IString(m_type) + 
"].";
 
  562       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  575   void TableField::operator=(
const char *buf) {
 
  576     if (m_type != TableField::Text) {
 
  577       QString msg = 
"Unable to set field to the given string value. Field [" + m_name + 
"] Type is not Text.";
 
  578       throw IException(IException::Programmer, msg, _FILEINFO_);
 
  592     if (m_type == TableField::Double) {
 
  595     else if (m_type == TableField::Integer) {
 
  598     else if (m_type == TableField::Text) {
 
  601     else if (m_type == TableField::Real) {
 
  610   QString TableField::toString(
const TableField &field, QString delimiter){
 
  611     QString fieldValues = 
"";
 
  612     if (field.
size()== 1){
 
  614         fieldValues = (QString)field;
 
  629         fieldValues +=(QString)field;
 
  632         vector< int > currField = field;
 
  633         for (
int i = 0;i <(int)currField.size();i++){
 
  635           if (i <(
int)currField.size()- 1){
 
  637             fieldValues += delimiter;
 
  642         vector< double > currField = field;
 
  643         for (
int i = 0;i <(int)currField.size();i++){
 
  645           if (i <(
int)currField.size()- 1){
 
  646             fieldValues += delimiter;
 
  651         vector< float > currField = field;
 
  652         for (
int i = 0;i <(int)currField.size();i++){
 
  654           if (i <(
int)currField.size()- 1){
 
  655             fieldValues += delimiter;