Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

StringTable.h

Go to the documentation of this file.
00001 // -*- C++ -*- 00002 00003 // Copyright (c) 2002 by Julien Keable 00004 00005 // Redistribution and use in source and binary forms, with or without 00006 // modification, are permitted provided that the following conditions are met: 00007 // 00008 // 1. Redistributions of source code must retain the above copyright 00009 // notice, this list of conditions and the following disclaimer. 00010 // 00011 // 2. Redistributions in binary form must reproduce the above copyright 00012 // notice, this list of conditions and the following disclaimer in the 00013 // documentation and/or other materials provided with the distribution. 00014 // 00015 // 3. The name of the authors may not be used to endorse or promote 00016 // products derived from this software without specific prior written 00017 // permission. 00018 // 00019 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00020 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00021 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00022 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00024 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00025 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00026 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00027 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 // 00030 // This file is part of the PLearn library. For more information on the PLearn 00031 // library, go to the PLearn Web site at www.plearn.org 00032 00033 #ifndef STRTABLE_INC 00034 #define STRTABLE_INC 00035 00036 #include <string> 00037 #include <vector> 00038 #include <map> 00039 #include <list> 00040 #include <plearn/math/TMat.h> 00041 00042 namespace PLearn { 00043 using namespace std; 00044 00045 00046 using namespace std; 00047 00048 00049 class StringTable 00050 { 00051 TMat<string> data; 00052 vector<string> fieldnames; // fieldnames 00053 map<string, int> rev_fn; // maps fieldnames to column numbers 00054 00055 public: 00056 /* construct a string table from a '.strtable' file 00057 File format is: 00058 00059 #size: length width [optionnal] 00060 #: fieldname1 fieldname2 ... [optionnal] 00061 f1;f2;f3 00062 f1;f2;f3 00063 ... 00064 00065 e.g: 00066 #:date bench machine compiler compilerOpt custCompilation custExecution benchOpt userTime realTime result 00067 2002/08/20 15:43:47;nearest;P3;pymake;-opt;;;-nrepeat 1 -ndata 1000 -nfeat 50;1.11;1.11;3.08696 00068 2002/08/20 15:43:47;nearest;P3;pymake;-opt;;;-nrepeat 1 -ndata 1000 -nfeat 100;2.13;2.13;8.36876 00069 ... 00070 */ 00071 00072 00073 StringTable(const string & filename); 00074 StringTable(); 00075 inline int length() const {return data.length();} 00076 inline int width() const {return data.width();} 00077 inline string& operator()(int i,int j){return data(i,j);} 00078 inline TVec<string> operator()(int i)const {return data(i);} 00079 // next 2 functions are to construct a string table on the fly 00080 // (don't bother with them if you're only loading .strtable files) 00081 void appendRow(const list<pair<string,string> >& row); 00082 void declareFields(const list<pair<string,string> > &row); 00083 friend ostream& operator<<(ostream& out,const StringTable& st); 00084 string getFieldName(int i)const {return fieldnames[i];} 00085 }; 00086 00087 } // end of namespace PLearn 00088 00089 00090 #endif

Generated on Tue Aug 17 16:07:31 2004 for PLearn by doxygen 1.3.7