table.h

00001 /*
00002   -------------------------------------------------------------------
00003   
00004   Copyright (C) 2006, 2007, 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_H
00024 #define O2SCL_TABLE_H
00025 
00026 #include <iostream>
00027 #include <fstream>
00028 #include <string>
00029 #include <cmath>
00030 #include <sstream>
00031 #include <o2scl/misc.h>
00032 #include <o2scl/err_hnd.h>
00033 #include <o2scl/multi_funct.h>
00034 #include <o2scl/collection.h>
00035 #include <o2scl/search_vec.h>
00036 #include <o2scl/ovector_tlate.h>
00037 #include <o2scl/smart_interp.h>
00038 
00039 #ifndef DOXYGENP
00040 namespace o2scl {
00041 #endif
00042 
00043   /** \brief Data table
00044     
00045       A class to contain and manipulate several equally-sized 
00046       columns of data. 
00047 
00048       <B> Data representation </b> \n
00049 
00050       Each individual column is just an ovector_view (or any
00051       descendant of an ovector_view) The columns can be referred to in
00052       one of two ways:
00053       - A numerical index from 0 to C-1 (where C is the number of
00054       columns). For example, data can be accessed through \ref
00055       table::get(size_t c, size_t r) and \ref table::set(size_t c, size_t r,
00056       double val), or the overloaded [] operator, table[c][r]. 
00057       - A name of the column which is a string with no whitespace.
00058       For example, data can be accessed with table::get(string cname,
00059       int r) and table::set(string cname, int r, double val).
00060       
00061       The columns are organized in a both a <map> and a <vector>
00062       structure so that finding a column by its index ( string 
00063       table::get_column_name(int index), and double
00064       *table::get_column(int index) ) takes only constant time, and
00065       finding a column by its name ( int \ref lookup_column() and
00066       double * \ref table::get_column() ) is O(log(C)). Insertion of a
00067       column ( \ref new_column() ) is O(log(C)), but deletion ( \ref
00068       delete_column() )is O(C). Adding a row of data can be either
00069       O(1) or O(C), but row insertion and deletion is slow, since the
00070       all of the columns must be shifted accordingly.
00071 
00072       Ownership of any column may be changed at any time, but care
00073       must be taken to ensure that memory allocation errors do not
00074       occur. These errors should not occur when no columns are 
00075       owned by the user.
00076 
00077       Because of the structure, this class is not suitable for the
00078       matrix manipulation. The classes \ref omatrix and \ref umatrix
00079       are better used for that purpose.
00080 
00081       \b Column \b size \n 
00082 
00083       The columns grow automatically (similar to the STL <vector>)
00084       in reponse to an attempt to call set() for a row that does not
00085       presently exist or in a call to line_of_data() when the table is
00086       already full. However, this forces memory rearrangments that are
00087       O(R*C). Columns which are not owned by the table are not
00088       modified, so the table will not allow an increase in the number
00089       of lines beyond the size of the smallest user-owned column. If
00090       the user has a good estimate of the number of rows beforehand,
00091       it is best to either specify this in the constructor, or in an
00092       explicit call to inc_maxlines().
00093 
00094       <B> Lookup, differentiation, integration, and interpolation </b>
00095       \n Lookup, differentiation, integration, and interpolation are
00096       automatically implemented using splines from the class
00097       smart_interp_vecp. A caching mechanism is implemented so that
00098       successive interpolations, derivative evaluations or
00099       integrations over the same two columns are fast.
00100 
00101       <B> Sorting </b>\n
00102 
00103       The columns are automatically sorted by name for speed, the
00104       results can be accessed by table::get_sorted_name(i). Individual
00105       columns can be sorted, or the entire table can be sorted by one
00106       column.
00107 
00108       <B> Allowable column names</b> \n
00109 
00110       In general, column names may be of any form as long as they
00111       don't contain whitespace, e.g. \c 123".#@$%xy~  is a
00112       legitmate column name. The column name should be restricted to contain
00113       only letters, numbers, and underscores and may not begin with a
00114       digit.
00115 
00116       <B> Thread-safety </b> \n
00117 
00118       Generally, the member functions are thread-safe in the sense
00119       that one would expect. Simple get() and set() functions are
00120       thread-safe, while insertion and deletion operations are not. It
00121       makes little sense to try to make insertion and deletion
00122       thread-safe. The interpolation routines are not thread-safe.
00123 
00124       \b I/O \b and \b command-line \b manipulation \n
00125 
00126       When data from an object of type \ref table is output to 
00127       a file through the \ref collection class, the table
00128       can be manipulated on the command-line through
00129       the acol utility.
00130 
00131       \todo Move the discussion above to the user guide?
00132       \todo Add interp() and related functions which avoid caching and can
00133       thus be const (This has been started with interp_const() )
00134 
00135       \future The nlines vs. maxlines and automatic resizing of
00136       table-owned vs. user-owned vectors could be reconsidered,
00137       especially now that ovectors can automatically resize on their
00138       own.
00139   */
00140   class table {
00141   public:
00142   
00143     /** \brief Create a new table with space for nlines<=cmaxlines.
00144      */
00145     table(int cmaxlines=0);
00146 
00147     virtual ~table();
00148 
00149     // --------------------------------------------------------
00150     /** \name Basic get and set methods */
00151     //@{
00152     /** \brief Set row \c row of column named \c col to value \c val - 
00153         O(log(C)).
00154 
00155         This function adds the column \c col if it does not
00156         already exist and adds rows using inc_maxlines() and
00157         set_nlines() to create at least \c (row+1) rows if they do not
00158         already exist.
00159      */
00160     int set(std::string col, size_t row, double val);
00161 
00162     /** \brief Set row \c row of column number \c icol to value \c val - O(1).
00163      */
00164     int set(size_t icol, size_t row, double val);
00165   
00166     /** \brief Get value from row \c row of column named \c col - O(log(C)).
00167      */
00168     double get(std::string col, size_t row) const;
00169 
00170     /** \brief Get value from row \c row of column number \c icol - O(1).
00171      */
00172     double get(size_t icol, size_t row);
00173 
00174     /** \brief Return the number of columns
00175      */
00176     int get_ncolumns() const {return atree.size();};
00177     
00178     /** \brief Return the number of lines
00179      */
00180     size_t get_nlines() const {return nlines;};
00181 
00182     /** 
00183         \brief Set the number of lines
00184 
00185         This function is stingy about increasing the table memory space
00186         and will only increase it enough to fit \c il lines, which
00187         is useful if you have columns not owned by the table.
00188      */
00189     int set_nlines(size_t il);
00190 
00191     /** 
00192         \brief Set the number of lines
00193 
00194         \todo Resolve whether set() should really use this approach.
00195         Also, resolve whether this should replace set_nlines() (It could
00196         be that the answer is no, because as the documentation
00197         in the other version states, the other version is useful if
00198         you have columns not owned by the table.)
00199     */
00200     int set_nlines_auto(size_t il);
00201 
00202     /** \brief Return the maximum number of lines
00203      */
00204     int get_maxlines() {return maxlines;};
00205 
00206     /** \brief Returns a pointer to the column named \c col - O(log(C))
00207      */
00208     ovector_view *get_column(std::string col);
00209 
00210     /** \brief Returns a pointer to the column named \c col - O(log(C))
00211      */
00212     const ovector_view *get_column_const(std::string col) const;
00213     
00214     /** 
00215         \brief Returns a pointer to the column of index \c icol - O(1).
00216 
00217         Note that several of the methods require reallocation 
00218         of memory and pointers previously returned by this function
00219         will be incorrect.
00220     */
00221     ovector_view *get_column(size_t icol) {
00222       return (alist[icol]->second.dat);
00223     }
00224 
00225     /** 
00226         \brief Returns a pointer to the column of index \c icol - O(1).
00227 
00228         Note that several of the methods require reallocation 
00229         of memory and pointers previously returned by this function
00230         will be incorrect.
00231     */
00232     const ovector_view *get_column(size_t icol) const {
00233       return (alist[icol]->second.dat);
00234     }
00235 
00236     /** 
00237         \brief Returns the column of index \c icol - O(1) (const version)
00238 
00239         This does not do any sort of bounds checking and is 
00240         quite fast. 
00241 
00242         Note that several of the methods require reallocation of
00243         memory and refereces previously returned by this function will
00244         be incorrect.
00245     */
00246     const ovector_view &operator[] (size_t icol) const {
00247       return (*alist[icol]->second.dat);
00248     }
00249 
00250     /** 
00251         \brief Returns the column of index \c icol - O(1).
00252 
00253         This does not do any sort of bounds checking and is 
00254         quite fast. 
00255 
00256         Note that several of the methods require reallocation of
00257         memory and refereces previously returned by this function will
00258         be incorrect.
00259     */
00260     ovector_view &operator[] (size_t icol) {
00261       return (*alist[icol]->second.dat);
00262     }
00263 
00264     /** 
00265         \brief Returns the column named \c scol - O(log(C)) (const version)
00266 
00267         No error checking is performed.
00268 
00269         Note that several of the methods require reallocation of
00270         memory and refereces previously returned by this function will
00271         be incorrect.
00272     */
00273     const ovector_view &operator[](std::string scol) const {
00274       aciter it=atree.find(scol);
00275       return *(it->second.dat);
00276     }
00277 
00278     /** 
00279         \brief Returns the column named \c scol - O(log(C))
00280 
00281         No error checking is performed.
00282 
00283         Note that several of the methods require reallocation of
00284         memory and refereces previously returned by this function will
00285         be incorrect.
00286     */
00287     ovector_view &operator[](std::string scol) {
00288       aiter it=atree.find(scol);
00289       return *(it->second.dat);
00290     }
00291 
00292     /** \brief Returns a pointer to a copy of the row with value \c val 
00293         in column \c col - O(R*C) */
00294     int get_row(std::string col, double val, ovector &row) const;
00295     
00296     /** \brief Returns a pointer to a copy of row number \c irow - O(C)
00297      */
00298     int get_row(size_t irow, ovector &row) const;
00299     //@}
00300   
00301     // --------------------------------------------------------
00302     /** \name Column manipulation */
00303     //@{
00304 
00305     /** \brief Returns the name of column \c col - O(1).
00306      */
00307     std::string get_column_name(size_t col) const;
00308 
00309     /** \brief Returns the name of column \c col in sorted order - O(1).
00310      */
00311     std::string get_sorted_name(size_t col);
00312 
00313     /** \brief Add a new column owned by the table - O(log(C)).
00314      */
00315     int new_column(std::string name);
00316 
00317     /** 
00318         \brief Add a new column owned by the user - O(log(C)).
00319 
00320         This function does not modify the number of lines of data in 
00321         the table. 
00322 
00323         \todo We've got to figure out what to do if ldat is too small.
00324         If it's smaller than nlines, obviously we should just 
00325         fail, but what if it's size is between nlines and maxlines?
00326     */
00327     int new_column(std::string name, ovector_view *ldat);
00328 
00329     /** 
00330         \brief Find the index for column named \c name - O(log(C)).
00331 
00332         If the column is not present, this does not call the error
00333         handler, but quietly sets \c ix to zero and returns \ref
00334         gsl_notfound.
00335      */
00336     int lookup_column(std::string name, int &ix);
00337 
00338     /** 
00339         \brief Rename column named \c olds to \c news - O(C). 
00340 
00341         This is slow since we have to delete the column and re-insert
00342         it. This process in turn mangles all of the 
00343         iterators in the list.
00344     */
00345     int rename_column(std::string olds, std::string news);
00346 
00347     /** \brief Make a new column named \c dest equal to \c src - O(log(C)*R).
00348      */
00349     int copy_column(std::string src, std::string dest);
00350 
00351     /// Create (using \c new) a generic array from column \c col
00352     double *create_array(std::string col) const;
00353 
00354     /** \brief Initialize all values of column named \c scol to \c val - 
00355         O(log(C)*R). 
00356 
00357         Note that this does not initialize elements beyond
00358         nlines so that if the number of rows is increased afterwards, the
00359         new rows will have uninitialized values.
00360     */
00361     int init_column(std::string scol, double val);
00362 
00363     /** 
00364         \brief Modify ownership - O(log(C)). 
00365 
00366         Warning: columns allocated using
00367         malloc() should never be owned by the table object since it 
00368         uses delete instead of free().
00369     */
00370     int ch_owner(std::string name, bool ow);
00371 
00372     /** \brief Get ownership - O(log(C)). 
00373      */
00374     bool get_owner(std::string name) const;
00375 
00376     /** 
00377         \brief Get a gsl_vector from column \c name - O(log(C)). 
00378     */
00379     const gsl_vector *get_gsl_vector(std::string name) const;
00380   
00381     /** \brief Return 0 if the tree and list are properly synchronized
00382      */
00383     int check_synchro() const;
00384     
00385     /** 
00386         \brief Insert a column from a separate table, interpolating
00387         it into a new column
00388         
00389         Given a pair of columns ( \c src_index, \c src_col ) in a
00390         separate table (\c source), this creates a new column in the
00391         present table named \c src_col which interpolates \c loc_index
00392         into \c src_index.  The interpolation type from the \c source
00393         table will be used and the interpolation type of the present
00394         table is ignored. If there is already a column in the 
00395         present table named \c src_col, then this will fail.
00396 
00397         If there is an error in the interpolation for any particular
00398         row, then the value of \c src_col in that row will be set to
00399         zero.
00400     */
00401     int add_col_from_table(std::string loc_index, table &source,
00402                            std::string src_index, std::string src_col,
00403                            std::string dest_col="");
00404     //@}
00405   
00406     // --------------------------------------------------------
00407     /** \name Row maninpulation and data input */
00408     //@{
00409 
00410     /** \brief Insert a row before row \c n 
00411      */
00412     int new_row(size_t n);
00413 
00414     /** \brief Copy the data in row \c src  to row \c dest 
00415      */
00416     int copy_row(size_t src, size_t dest);
00417 
00418     /** \brief Insert a row of data before row \c n 
00419      */
00420     int insert_data(size_t n, size_t nv, double *v);
00421 
00422     /** \brief Insert a row of data before row \c n 
00423      */
00424     int insert_data(size_t n, size_t nv, double **v);
00425 
00426     /** 
00427         \brief Read a new set of names from \c newheads
00428     */
00429     int line_of_names(std::string newheads);
00430 
00431     /** \brief Read a line of data from an array
00432      */
00433     template<class vec_t> int line_of_data(size_t nv, const vec_t &v) {
00434       if (maxlines==0) inc_maxlines(5);
00435       if (nlines>=maxlines) inc_maxlines(maxlines);
00436       
00437       if (intp_set) {
00438         intp_set=false;
00439         delete si;
00440       }
00441       
00442       if (nlines<maxlines && nv<=(atree.size())) {
00443         
00444         for(size_t i=0;i<nv;i++) {
00445           (*this)[i][nlines]=v[i];
00446         }
00447         nlines++;
00448         
00449         return 0;
00450       }
00451       
00452       set_err("Not enough lines or columns in line_of_data().",gsl_einval);
00453       return gsl_einval;
00454     }
00455     //@}
00456 
00457     // --------------------------------------------------------
00458     /** \name Lookup and search methods */
00459     //@{
00460 
00461     /** 
00462         \brief Look for a value in an ordered column
00463 
00464         O(log(C)*log(R))
00465      */
00466     size_t ordered_lookup(std::string col, double val);
00467 
00468     /// Exhaustively search column \c col for the value \c val - O(log(C)*R).
00469     size_t lookup(std::string col, double val) const;
00470 
00471     /// Search column \c col for the value \c val and return value in \c col2
00472     double lookup_val(std::string col, double val, std::string col2) const;
00473 
00474     /// Exhaustively search column \c col for the value \c val - O(log(C)*R).
00475     size_t lookup(int col, double val) const;
00476 
00477     /** \brief Exhaustively search column \c col for many occurences 
00478         of \c val - O(log(C)*R).
00479     */
00480     size_t mlookup(std::string col, double val, std::vector<double> &results,
00481                    double threshold=0.0) const;
00482     
00483     /** 
00484         \brief Search for row with maximum value of formula 
00485 
00486         This searches the table for the maximum value of the specified 
00487         formula. This is useful in several ways. For example, to 
00488         find the row for which the column \c mu is 2 and \c T is 3,
00489         you can call 
00490         \code
00491         table::lookup_form("-abs(mu-2)-abs(T-3)");
00492         \endcode
00493 
00494     */
00495     int lookup_form(std::string formula, double &maxval);
00496     //@}
00497 
00498     // --------------------------------------------------------
00499     /** \name Interpolation, differentiation, and integration, max, and min */
00500     //@{
00501 
00502     /** 
00503         \brief Interpolate \c x0 from \c sx into \c sy
00504 
00505         O(log(C)*log(R)) but can be as bad as O(log(C)*R) if 
00506         the relevant columns are not well ordered.
00507     */
00508     double interp(std::string sx, double x0, std::string sy);
00509 
00510     /** 
00511         \brief Interpolate \c x0 from \c sx into \c sy
00512 
00513         O(log(C)*log(R)) but can be as bad as O(log(C)*R) if 
00514         the relevant columns are not well ordered.
00515     */
00516     double interp_const(std::string sx, double x0, std::string sy) const;
00517     
00518     /** 
00519         \brief Interpolate \c x0 from \c ix into \c iy
00520 
00521         O(log(R)) but can be as bad as O(R) if 
00522         the relevant columns are not well ordered.
00523      */
00524     double interp(size_t ix, double x0, size_t iy);
00525 
00526     /** \brief Make a new column \c yp which is the derivative y'(x) - 
00527         O(log(C)*R).
00528      */
00529     int deriv(std::string x, std::string y, std::string yp);
00530 
00531     /** 
00532         \brief The first derivative of the function sy(sx) at sx=x0.
00533 
00534         O(log(C)*log(R)) but can be as bad as O(log(C)*R) if 
00535         the relevant columns are not well ordered.
00536     */
00537     double deriv(std::string sx, double x0, std::string sy);
00538 
00539     /** 
00540         \brief The first derivative of the function iy(ix) at ix=x0.
00541       
00542         O(log(R)) but can be as bad as O(R) if 
00543         the relevant columns are not well ordered.
00544     */
00545     double deriv(size_t ix, double x0, size_t iy);
00546 
00547     /** 
00548         \brief Make a new column \c yp which is 
00549         \f$ y^{\prime \prime}(x) \f$ - O(log(C)*R).
00550      */
00551     int deriv2(std::string x, std::string y, std::string yp);
00552 
00553     /** 
00554         \brief The second derivative of the function sy(sx) at sx=x0.
00555 
00556         O(log(C)*log(R)) but can be as bad as O(log(C)*R) if 
00557         the relevant columns are not well ordered.
00558     */
00559     double deriv2(std::string sx, double x0, std::string sy);
00560 
00561     /** 
00562         \brief The second derivative of the function iy(ix) at ix=x0.
00563 
00564         O(log(R)) but can be as bad as O(R) if 
00565         the relevant columns are not well ordered.
00566     */
00567     double deriv2(size_t ix, double x0, size_t iy);
00568 
00569     /** 
00570         \brief The integral of the function sy(sx) from sx=x1 to sx=x2.
00571         
00572         O(log(C)*log(R)) but can be as bad as O(log(C)*R) if 
00573         the relevant columns are not well ordered.
00574     */
00575     double integ(std::string sx, double x1, double x2, std::string sy);
00576   
00577     /** 
00578         \brief The integral of the function iy(ix) from ix=x1 to ix=x2.
00579 
00580         O(log(R)) but can be as bad as O(R) if 
00581         the relevant columns are not well ordered.
00582     */
00583     double integ(size_t ix, double x1, double x2, size_t iy);
00584 
00585     /** 
00586         \brief The integral of the function iy(ix) 
00587 
00588         O(log(R)) but can be as bad as O(R) if the relevant columns
00589         are not well ordered.
00590     */
00591     int integ(std::string x, std::string y, std::string ynew);
00592 
00593     /** \brief Return column maximum. Makes no assumptions about 
00594         ordering - O(R).
00595      */
00596     double max(std::string col) const;
00597 
00598     /** \brief Return column minimum. Makes no assumptions about 
00599         ordering - O(R).
00600      */
00601     double min(std::string col) const;
00602     //@}
00603 
00604     // --------------------------------------------------------
00605     /** \name Subtable method */
00606     //@{
00607 
00608     /** 
00609         \brief Make a subtable
00610 
00611         Uses the columns specified in \c list from the row \c top
00612         to the row of index \c bottom. If \c linked is false
00613         the the data will be independent from the original table.
00614     */
00615     table *subtable(std::string list, size_t top, size_t bottom,
00616                     bool linked=true);
00617     //@}
00618   
00619     // --------------------------------------------------------
00620     /** \name Add space */
00621     //@{
00622 
00623     /** \brief Manually increase the maximum number of lines
00624      */
00625     int inc_maxlines(size_t llines);
00626     //@}
00627 
00628     // --------------------------------------------------------
00629     /** \name Delete methods */
00630     //@{
00631 
00632     /** \brief Delete column named \c scol - O(C). 
00633       
00634         This is slow because
00635         the iterators in alist are mangled and we have to call
00636         reset_list to get them back.
00637     */
00638 
00639     int delete_column(std::string scol);
00640 
00641     /** \brief Delete the row with the value \c val in column \c scol.
00642      */
00643     int delete_row(std::string scol, double val);
00644 
00645     /** \brief Delete the row of index \c irow.
00646      */
00647     int delete_row(size_t irow);
00648     //@}
00649 
00650     // --------------------------------------------------------
00651     /** \name Clear methods */
00652     //@{
00653 
00654     /** \brief Zero the data entries but keep the column names 
00655         and nlines fixed
00656     */
00657     void zero_table();
00658 
00659     /** \brief Clear the table and the column names
00660      */
00661     void clear_table();
00662 
00663     /** \brief Remove all of the data by setting the number
00664         of lines to zero
00665 
00666         This leaves the column names intact and does not remove
00667         the constants.
00668      */
00669     void clear_data() {
00670       nlines=0;   
00671       if (intp_set==true) {
00672         delete si; 
00673         intp_set=false;
00674       }
00675       return;
00676     };
00677     //@}
00678 
00679     // --------------------------------------------------------
00680     /** \name Sorting methods */
00681     //@{
00682 
00683     /** \brief Sort the entire table by the column \c scol
00684      */
00685     int sort_table(std::string scol);
00686 
00687     /** \brief Individually sort the column \c scol
00688      */
00689     int sort_column(std::string scol);
00690     //@}
00691 
00692     // --------------------------------------------------------
00693     /** \name Summary method */
00694     //@{
00695     /** \brief Output a summary of the information stored
00696 
00697         Outputs the number of constants, the number of columns,
00698         a list of the column names, and the number of lines of
00699         data.
00700     */
00701     int summary(std::ostream *out, int ncol=79) const;
00702     //@}
00703 
00704     /// Set the base interpolation objects
00705     int set_interp(base_interp<ovector_view> &bi1,
00706                    base_interp<ovector_const_subvector> &bi2) {
00707       intp1=&bi1;
00708       intp2=&bi2;
00709       return 0;
00710     }
00711 
00712     /// Add a constant
00713     virtual int add_constant(std::string name, double val) {
00714       constants.insert(make_pair(name,val));
00715       return 0;
00716     }
00717 
00718     /// Remove a constant
00719     virtual int remove_constant(std::string name) {
00720       constants.erase(name);
00721       return 0;
00722     }
00723     
00724     /// The list of constants
00725     std::map<std::string,double> constants;
00726 
00727   protected:
00728 
00729 #ifndef DOXYGEN_INTERNAL
00730     
00731     friend class io_tlate<table>;
00732 
00733     /** \brief Set the elements of alist with the appropriate 
00734         iterators from atree - O(C).
00735 
00736         Generally, the end-user shouldn't need this method. It is 
00737         only used in delete_column() to rearrange the list when
00738         a column is deleted from the tree.
00739     */
00740     int reset_list();
00741   
00742     /// Column structure
00743     typedef struct col_s {
00744       /// Pointer to column
00745       ovector_view *dat;
00746       /// Owner of column
00747       bool owner;
00748       /// Column index
00749       int index;
00750     } col;
00751     
00752     /// \name Iterator types
00753     //@{
00754     typedef std::map<std::string,col,string_comp>::iterator aiter;
00755     typedef std::map<std::string,col,string_comp>::const_iterator aciter;
00756     typedef std::vector<aiter>::iterator aviter;
00757     //@}
00758   
00759     /// \name Actual data
00760     //@{
00761     /// The size of allocated memory
00762     size_t maxlines;
00763     /// The size of presently used memory
00764     size_t nlines;
00765     /// The tree of columns
00766     std::map<std::string,col,string_comp> atree;
00767     /// The list of tree iterators
00768     std::vector<aiter> alist;
00769     //@}
00770   
00771     /// \name Column manipulation methods
00772     //@{
00773     /// Return the iterator for a column
00774     aiter get_iterator(std::string lname);
00775     /// Return the column structure for a column
00776     col *get_col_struct(std::string lname);
00777     /// Return the beginning of the column tree
00778     aiter begin() {return atree.begin();};
00779     /// Return the end of the column tree
00780     aiter end() {return atree.end();};
00781     //@}
00782 
00783     /// The sorting function
00784     static int sortd_comp(const void *a, const void *b);
00785 
00786     /// A structure for sorting
00787     typedef struct sortd_s {
00788       /// Value to sort
00789       double val;
00790       /// Sorted index
00791       int indx;
00792     } sortd;
00793   
00794     /// \name Interpolation
00795     //@{
00796     /// The interpolation object
00797     sm_interp_vec *si;
00798 
00799     /// A pointer to the interpolation object
00800     base_interp<ovector_view> *intp1;
00801     /// A pointer to the subvector interpolation object
00802     base_interp<ovector_const_subvector> *intp2;
00803 
00804     /// The default interpolation object
00805     cspline_interp<ovector_view> cintp1;
00806     /// The default subvector interpolation object
00807     cspline_interp<ovector_const_subvector> cintp2;
00808     
00809     /// The vector-searching object
00810 #ifdef DOXYGENP
00811     search_vec<vec_t> se;
00812 #else
00813     search_vec<ovector> se;
00814 #endif
00815 
00816     /// The interpolation type
00817     int itype;
00818 
00819     /// True if the interpolation type has been set
00820     bool intp_set;
00821 
00822     /// The last x-column interpolated
00823     std::string intp_colx;
00824 
00825     /// The last y-column interpolated
00826     std::string intp_coly;
00827 
00828     //@}
00829 
00830 #endif
00831 
00832   };
00833 
00834   /// Input specialization
00835   template<> int io_tlate<table>::input
00836     (cinput *co, o2scl::in_file_format *ins, table *ta);
00837   /// Output specialization
00838   template<> int io_tlate<table>::output
00839     (coutput *co, o2scl::out_file_format *outs, 
00840      table *at);
00841   /// \fn Type specialization
00842   template<> const char *io_tlate<table>::type();
00843   
00844   typedef io_tlate<table> table_io_type;
00845   
00846 #ifndef DOXYGENP
00847 }
00848 #endif
00849 
00850 #endif

Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.