Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

LbldData.h

Go to the documentation of this file.
00001 // $Id: LbldData.h,v 1.1.1.1 1999/12/28 01:36:02 burnett Exp $
00002 // Original author: Bill Atwood
00003 // Modified by T. Burnett
00004 
00005 #ifndef __LbldData_H
00006 #define __LbldData_H 1
00007 #ifdef _MSC_VER
00008 #pragma warning(disable:4786)
00009 #endif
00010 
00011 #include <iostream>
00012 #include <map>
00013 #include <string>
00014 #include <vector>
00015 
00016 //   LbldData
00017 //   A Labelled Data Array class based on D. Britton's RecoArray
00018 //
00019 // Comments
00020 //   Define the LbldData class.  This is designed to hold data as
00021 //   an array  of floats. with an associated label 
00022 //
00023 //   There are methods for adding and retrieving data:
00024 //   addData(...) methods takes one argument in addition
00025 //   to the actual (float) data.
00026 //   The FASTEST WAY to add data is to use the following:
00027 //   addData(int entry, float data);
00028 //                                --> array[entry] = data
00029 //   but there is also a method where the "int entry" is replaced
00030 //   with "char* data_name" .  This method is slower than the above
00031 //   because the correct integer has to be found by looping over
00032 //   a contents list .
00033 //   All the addData methods return an integer which is -1 on error
00034 //   or the  the entry number. Thus the first
00035 //   time data is added one can use one of the slower methods and
00036 //   "remember" the returned integer so subsequent calls can use the
00037 //   more efficient methods.
00038 //   getData(...) methods also come in a variety of colours. Again,
00039 //   the calls can take integers (for fastest access) or names and
00040 //   owners for slower access. The error return is FLT_MAX.
00041 //
00042 //   A modernization allows access by the operator[](string), since it now
00043 //   has public inheritance form map<string, float>. Also added is an 
00044 //   float operator[](iterator entry) to return the float associated with the 
00045 //   iterator, or a reference to allow setting the value
00046 class LbldData  : public std::vector<std::pair<std::string,float> >
00047 {
00048 public:
00049     
00050     LbldData ();
00051      
00052     ~LbldData ();
00053     
00054     iterator addElement (const char* c);
00055     // create a new element, return iterator for it
00056     
00057     void addData (iterator entry, float x);
00058     // set the value of the entry
00059     
00060     iterator addData (char* c, float x);
00061     // set value (and add if not already in the list
00062     
00063     //  get Data  Methods (see comments)
00064     float getData (iterator entry)const;
00065     
00066     float getData (const char* name)const;
00067     
00068     // operators that are equivalent to, but more convenient than the above
00069     float operator[](iterator entry)const{return getData(entry);}
00070     float operator[](const char* name)const{return getData(name);}
00071 
00072     // this allows data[entry]=x;
00073     float& operator[](iterator entry){return (*entry).second;}
00074 
00075     int dataCount () const { return size(); }
00076     
00077     //  returns iterator of the entry or end() if not found
00078     const_iterator checkEntry (const char* c) const;
00079     
00080     
00081     //  sets all data to zero. Doesn't delete array
00082     void clear ();
00083     
00084     value_type& operator[](int i)const{ return *(m_iteratorlist[i]);}
00085     // so data[i].first or data[i].second can be used to access the 
00086     // name and value (resp.), with i in order of definition.
00087     
00088     //  print all
00089     void printOn (std::ostream& out );
00090     
00091 private:
00092     std::vector<iterator> m_iteratorlist;
00093     // separate list of pointers, in order of definition.
00094   
00095 };
00096 
00097 
00098 inline std::ostream& operator<<(std::ostream& out, LbldData& x) {
00099     x.printOn(out); 
00100     return out;
00101 }
00102 
00103 #endif

Generated at Wed Nov 21 12:20:44 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000