Object-oriented Scientific Computing Library: Version 0.910
table_units.h
00001 /*
00002   -------------------------------------------------------------------
00003   
00004   Copyright (C) 2006-2012, 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   /** \brief Data \table class with units
00034 
00035       \future Make table methods virtual? (not necessary yet
00036       since delete_column() isn't referred to internally)
00037   */
00038   class table_units : public table {
00039 
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 unit cache as given by \ref convert_units::print_cache()
00091     int show_units() {
00092       cup->print_cache();
00093       return 0;
00094     }
00095 
00096     /// Return the number of columns with units
00097     size_t get_nunits() {
00098       return utree.size();
00099     }
00100 
00101   protected:
00102 
00103 #ifndef DOXYGEN_INTERNAL
00104     
00105     /// The pointer to the convert units object
00106     convert_units *cup;
00107 
00108     /// \name Unit map iterator types
00109     //@{
00110     typedef std::map<std::string,std::string,
00111       string_comp>::iterator uiter;
00112     typedef std::map<std::string,std::string,
00113       string_comp>::const_iterator uciter;
00114     //@}
00115   
00116     /// Unit map
00117     std::map<std::string,std::string,string_comp> utree;
00118   
00119 #endif
00120 
00121   };
00122 
00123 #ifndef DOXYGENP
00124 }
00125 #endif
00126 
00127 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).

Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads.