00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2006, 2007, 2008, 2009, Andrew W. Steiner 00005 00006 This file is part of O2scl. 00007 00008 O2scl is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 O2scl is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with O2scl. If not, see <http://www.gnu.org/licenses/>. 00020 00021 ------------------------------------------------------------------- 00022 */ 00023 #ifndef O2SCL_TABLE_UNITS_H 00024 #define O2SCL_TABLE_UNITS_H 00025 00026 #include <o2scl/table.h> 00027 #include <o2scl/convert_units.h> 00028 00029 #ifndef DOXYGENP 00030 namespace o2scl { 00031 #endif 00032 00033 /** 00034 \brief Data \table class with units 00035 00036 \future Make table methods virtual? (not necessary yet 00037 since delete_column() isn't referred to internally) 00038 */ 00039 class table_units : public table { 00040 public: 00041 00042 /** \brief Create a new table_units with space for nlines<=cmaxlines. 00043 */ 00044 table_units(int cmaxlines=0); 00045 00046 virtual ~table_units(); 00047 00048 /// \name Copy constructors 00049 //@{ 00050 table_units(const table_units &t); 00051 table_units(const table &t); 00052 table_units &operator=(const table_units &t); 00053 table_units &operator=(const table &t); 00054 //@} 00055 00056 /// Get the unit for column \c scol 00057 std::string get_unit(std::string scol) const; 00058 00059 /// Remove the unit for column \c scol 00060 int remove_unit(std::string scol); 00061 00062 /// Set the unit for column \c scol to \c unit 00063 int set_unit(std::string scol, std::string unit); 00064 00065 /// Convert the units of column \c scol to \c unit 00066 int convert_to_unit(std::string scol, std::string unit, 00067 bool err_on_fail=true); 00068 00069 /// Get the conversion factor from \c old_unit to \c new_unit 00070 double get_conv(std::string old_unit, std::string new_unit); 00071 00072 /// The default object for unit conversions 00073 convert_units def_cu; 00074 00075 /// Delete column named \c scol 00076 virtual int delete_column(std::string scol); 00077 00078 /// Return the type, \c "table_units". 00079 virtual const char *type() { return "table_units"; } 00080 00081 /// Output a summary of the information stored 00082 virtual int summary(std::ostream *out, int ncol=79) const; 00083 00084 /// Set the convert units object 00085 int set_convert(convert_units &c) { 00086 cup=&c; 00087 return 0; 00088 } 00089 00090 /// Show the units 00091 int show_units() { 00092 cup->print_cache(); 00093 return 0; 00094 } 00095 00096 protected: 00097 00098 #ifndef DOXYGEN_INTERNAL 00099 00100 friend class io_tlate<table_units>; 00101 00102 /// The pointer to the convert units object 00103 convert_units *cup; 00104 00105 /// \name Unit map iterator types 00106 //@{ 00107 typedef std::map<std::string,std::string, 00108 string_comp>::iterator uiter; 00109 typedef std::map<std::string,std::string, 00110 string_comp>::const_iterator uciter; 00111 //@} 00112 00113 /// Unit map 00114 std::map<std::string,std::string,string_comp> utree; 00115 00116 #endif 00117 00118 }; 00119 00120 /// Input specialization 00121 template<> int io_tlate<table_units>::input 00122 (cinput *co, o2scl::in_file_format *ins, table_units *ta); 00123 /// Output specialization 00124 template<> int io_tlate<table_units>::output 00125 (coutput *co, o2scl::out_file_format *outs, 00126 table_units *at); 00127 /// \fn Type specialization 00128 template<> const char *io_tlate<table_units>::type(); 00129 00130 typedef io_tlate<table_units> table_units_io_type; 00131 00132 #ifndef DOXYGENP 00133 } 00134 #endif 00135 00136 #endif
Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.
Project hosting provided by
,
O2scl Sourceforge Project Page