USGS

Isis 3.0 Application Source Code Reference

Home

Column.cpp

Go to the documentation of this file.
00001 /**
00002  * @file
00003  * $Revision: 1.1 $
00004  * $Date: 2007/08/09 18:24:24 $
00005  *
00006  *   Unless noted otherwise, the portions of Isis written by the USGS are public
00007  *   domain. See individual third-party library and package descriptions for
00008  *   intellectual property information,user agreements, and related information.
00009  *
00010  *   Although Isis has been used by the USGS, no warranty, expressed or implied,
00011  *   is made by the USGS as to the accuracy and functioning of such software
00012  *   and related material nor shall the fact of distribution constitute any such
00013  *   warranty, and no responsibility is assumed by the USGS in connection
00014  *   therewith.
00015  *
00016  *   For additional information, launch
00017  *   $ISISROOT/doc//documents/Disclaimers/Disclaimers.html in a browser or see
00018  *   the Privacy & Disclaimers page on the Isis website,
00019  *   http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on
00020  *   http://www.usgs.gov/privacy.html.
00021  */
00022 #include <vector>
00023 #include <string>
00024 #include <iostream>
00025 
00026 #include "Column.h"
00027 #include "iException.h"
00028 
00029 namespace Isis{
00030 
00031   /**
00032    * Constructor. Sets the precision for decimal-aligned columns to 4
00033    */
00034   Column::Column(){
00035     p_precision = 4;
00036     p_width = 0;
00037     p_name = "";
00038     SetAlignment(Column::NoAlign);
00039     SetType(Column::NoType);
00040   }
00041 
00042   /**
00043    * Constructor with parameter
00044    * 
00045    * @param name The name of the column, used as the header
00046    * @param width The width (in characters) to make the column
00047    * @param type The type of information the column is to represent
00048    * @param align The alignment, within the column, the data is to conform to
00049    */
00050   Column::Column( std::string name, int width, Column::Type type, Column::Align align) {
00051     //Set the parameters with function calls, to make use of pre-existing error checks
00052     SetWidth(width);
00053     SetName(name);
00054     SetType(type);
00055     SetAlignment(align);
00056 
00057     p_precision = 4;
00058   }
00059 
00060   /**
00061    * Sets the Column name, or header
00062    * 
00063    * @param name The name of the Column
00064    */
00065   void Column::SetName (std::string name) {
00066     if (p_width != 0 && name.length() > p_width) {
00067       std::string message = "Name[" + name + "] is wider than width";
00068       throw iException::Message(iException::User,message,_FILEINFO_);
00069     }
00070     p_name = name;
00071   }
00072 
00073   /**
00074    * Sets the width of the Column, in text columns
00075    * 
00076    * @param width The number of text columns the Column will hold
00077    */
00078   void Column::SetWidth (unsigned int width) {
00079     if (p_name.size() > 0 && p_name.size() > width) {
00080       std::string message = "Width is insufficient to contain name[";
00081       message += p_name + "]";
00082       throw iException::Message(iException::User,message,_FILEINFO_);
00083     }
00084     p_width = width;
00085   }
00086 
00087   /**
00088    * Sets the data type of the Column
00089    * 
00090    * @param type The data type for the Column
00091    */
00092   void Column::SetType (Column::Type type) {
00093     if (p_align == Column::Decimal && 
00094         (type == Column::Integer || type == Column::String)) {
00095         std::string message = "Integer or string type is not sensible if ";
00096         message += "alignment is Decimal.";
00097         throw iException::Message(iException::User,message,_FILEINFO_);
00098     }
00099     p_type = type;
00100   }
00101 
00102   /**
00103    * Sets the alignment of the Column
00104    * 
00105    * The text in the Column will be aligned according to this parameter,
00106    * which is Right, Left, or, possible only with real-number values,
00107    * aligned by the decimal point
00108    * 
00109    * @param alignment The alignment of the text in the Column
00110    */
00111   void Column::SetAlignment (Column::Align alignment) {
00112     if (alignment == Column::Decimal && 
00113         (p_type == Column::Integer || p_type == Column::String)) {
00114         std::string message = "Decimal alignment does not make sense for ";
00115         message += "integer or string values.";
00116         throw iException::Message(iException::Programmer,message,_FILEINFO_);
00117     }
00118     p_align = alignment;
00119   }
00120 
00121   /**
00122    * Sets the precision of the Column, for real number values
00123    * 
00124    * This sets the number of digits after the decimal point, for decimal aligned
00125    * values. If the Column's alignment is anything else, an error is thrown.
00126    * 
00127    * @param precision The number of digits after the decimal point to be shown
00128    */
00129   void Column::SetPrecision(unsigned int precision) {
00130     if (DataType() != Column::Real &&
00131         DataType() != Column::Pixel) {
00132       std::string message = "Setting precision only makes sense for Decimal Alignment";
00133       throw iException::Message(iException::User,message,_FILEINFO_);
00134     }
00135     p_precision = precision;
00136   }
00137 
00138   /**
00139    * Returns the type of data this column will contain
00140    * 
00141    * @return Column::Type The data type of this column
00142    */
00143   Column::Type Column::DataType() {
00144 
00145     if (p_type == 0) {
00146       std::string message = "Type has not been set yet!";
00147       throw iException::Message(iException::User,message,_FILEINFO_);
00148     }
00149 
00150     return p_type;
00151   }
00152 }