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

Tuple.h

Go to the documentation of this file.
00001 //$Header: /nfs/slac/g/glast/ground/cvs/reconstruction/reconstruction/analysis/Tuple.h,v 1.1 2000/11/27 02:16:43 burnett Exp $
00002 #ifndef TUPLE_H
00003 #define TUPLE_H
00004 
00005 #include <iostream>
00006 #include <string>
00007 #include <vector>
00008 
00009 class TupleItem  {
00010 private:
00011    friend class Tuple;
00012 public:
00013 
00014     TupleItem(){}
00015     TupleItem(const std::string& name, float x=0);
00016 
00017     void operator=(float x){
00018       datum=x;
00019 
00020     }
00021     // assign value to the tuple element
00022     
00023     float operator()()const{
00024       return datum;
00025 }
00026 
00027     operator float()const{
00028       return datum;
00029     }
00030 
00031 public:
00032     std::string name()const{return m_name;}
00033     // extract the value
00034 
00035 
00036     friend std::ostream& operator << (std::ostream&, const TupleItem& );
00037     // print "name=value" for the tupleitem
00038     friend std::istream& operator >> (std::istream&,  Tuple& );
00039 
00040    private:
00041 
00042     float& operator()();
00043     std::string m_name;
00044     float datum;
00045 };
00046 
00047 
00048 class Tuple : public std::vector<TupleItem* >
00049 {
00050 private:
00051  friend class TupleItem;
00052 
00053  public:
00054 
00055    Tuple(const std::string& title);
00056    Tuple(std::istream& in);
00057    // constructors
00058 
00059    void nextStream(std::istream& in);
00060    // start reading from a new stream. columns must be the same as currently
00061     
00062    void setTitle(const std::string&);
00063    // set title after the fact
00064 
00065    float operator[](unsigned i)const;
00066    // access to value of the ith element (start from 0)
00067 
00068    const char* name(unsigned i)const;
00069    // access to name of the ith element
00070 
00071    int index(const std::string& name)const;
00072    const_iterator find(const std::string& name)const;
00073    // return index of element by name, if found (-1 otherwise)
00074    // return iterator for element with name, end() otherwise
00075 
00076    void fillArray(float array[])const;
00077    // fill the given array from the tuple
00078 
00079    void writeHeader(std::ostream&)const;
00080 
00081 public:
00082    // make a list of the names of the tupleitems
00083 
00084    friend std::istream& operator >> (std::istream&, Tuple&);
00085 
00086 
00087    virtual ~Tuple();
00088    // dtor
00089 
00090    const std::string& title() const {
00091      return m_title;
00092    }
00093 
00094    const TupleItem* tupleItem(const std::string& name)const;
00095    // return pointer to the tuple item by name. Error if not found
00096 
00097  private:
00098 
00099     std::string m_title;
00100 
00101     static Tuple* s_currentTuple;
00102 
00103 
00104 };
00105 
00106 std::ostream& operator << ( std::ostream&, const Tuple&);
00107 
00108 std::istream& operator >> (std::istream&, Tuple&);
00109 // read in values from open stream
00110 
00111 #endif TUPLE_H

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