00001
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
00018 TupleItem(const std::string& name, float* x);
00019
00020 void operator=(float x){
00021 datum=x;
00022
00023 }
00024
00025
00026 float operator()()const{
00027 return *m_pdatum;
00028 }
00029
00030 operator float()const{
00031 return *m_pdatum;
00032 }
00033
00034 public:
00035 std::string name()const{return m_name;}
00036
00037
00038
00039 friend std::ostream& operator << (std::ostream&, const TupleItem& );
00040
00041 friend std::istream& operator >> (std::istream&, Tuple& );
00042
00043 private:
00044
00045 float& operator()();
00046 std::string m_name;
00047 float datum;
00048 float* m_pdatum;
00049 };
00050
00051
00052 class Tuple : public std::vector<TupleItem* >
00053 {
00054 private:
00055 friend class TupleItem;
00056
00057 public:
00058
00059 Tuple(const std::string& title);
00060 Tuple(std::istream& in);
00061
00062
00063 void nextStream(std::istream& in);
00064
00065
00066 void setTitle(const std::string&);
00067
00068
00069 float operator[](unsigned i)const;
00070
00071
00072 const char* name(unsigned i)const;
00073
00074
00075 int index(const std::string& name)const;
00076 const_iterator find(const std::string& name)const;
00077
00078
00079
00080 void fillArray(float array[])const;
00081
00082
00083 void writeHeader(std::ostream&)const;
00084
00085 public:
00086
00087
00088 friend std::istream& operator >> (std::istream&, Tuple&);
00089
00090
00091 virtual ~Tuple();
00092
00093
00094 const std::string& title() const {
00095 return m_title;
00096 }
00097
00098 virtual const TupleItem* tupleItem(const std::string& name)const;
00099
00100
00101 virtual bool nextEvent(){return false;};
00102 private:
00103
00104 std::string m_title;
00105
00106 static Tuple* s_currentTuple;
00107
00108
00109 };
00110
00111 std::ostream& operator << ( std::ostream&, const Tuple&);
00112
00113 std::istream& operator >> (std::istream&, Tuple&);
00114
00115
00116 #endif TUPLE_H