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
00017 void operator=(float x){
00018 datum=x;
00019
00020 }
00021
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
00034
00035
00036 friend std::ostream& operator << (std::ostream&, const TupleItem& );
00037
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
00058
00059 void nextStream(std::istream& in);
00060
00061
00062 void setTitle(const std::string&);
00063
00064
00065 float operator[](unsigned i)const;
00066
00067
00068 const char* name(unsigned i)const;
00069
00070
00071 int index(const std::string& name)const;
00072 const_iterator find(const std::string& name)const;
00073
00074
00075
00076 void fillArray(float array[])const;
00077
00078
00079 void writeHeader(std::ostream&)const;
00080
00081 public:
00082
00083
00084 friend std::istream& operator >> (std::istream&, Tuple&);
00085
00086
00087 virtual ~Tuple();
00088
00089
00090 const std::string& title() const {
00091 return m_title;
00092 }
00093
00094 const TupleItem* tupleItem(const std::string& name)const;
00095
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
00110
00111 #endif TUPLE_H