QVdt.hh
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _Q_VDT_H
00018 #define _Q_VDT_H
00019 #include <string>
00020 #include <iostream>
00021 #include <vector>
00022
00023 class QVdt {
00024
00025 public:
00026
00027 enum QVdt_type {
00028 Int_QVdt = 'I',
00029 Double_QVdt = 'F',
00030 String_QVdt = 'S',
00031 Vector_QVdt = 'V',
00032 Unassigned_QVdt = 'U'
00033 };
00034
00035 typedef std::vector<QVdt> QVdt_vector;
00036
00037 QVdt (): type_internal(Unassigned_QVdt), name_s("") { }
00038
00039 QVdt (const std::string& value, const std::string& name = "", QVdt_type type = Unassigned_QVdt);
00040
00041 QVdt (long int value): name_s("") { value_i = value; type_internal = Int_QVdt; fBuiltFromString = false;}
00042
00043 QVdt (double value): name_s("") { value_f = value; type_internal = Double_QVdt; fBuiltFromString = false;}
00044
00045 template<typename V> QVdt (const std::vector<V, std::allocator<V> >& value): name_s("") {
00046
00047
00048 type_internal = Vector_QVdt;
00049 std::back_insert_iterator<std::vector<QVdt> > inserter(value_v);
00050 std::copy (value.begin (), value.end (), inserter);
00051 fBuiltFromString = false;
00052 }
00053
00054 QVdt (int value): name_s("") { value_i = value; type_internal = Int_QVdt; fBuiltFromString = false;}
00055
00056 QVdt (short value): name_s("") { value_i = value; type_internal = Int_QVdt; fBuiltFromString = false;}
00057
00058 QVdt (char value): name_s("") { value_i = value; type_internal = Int_QVdt; fBuiltFromString = false;}
00059 QVdt (unsigned long value): name_s("") { value_i = value; type_internal = Int_QVdt; fBuiltFromString = false;}
00060 QVdt (unsigned short value): name_s("") { value_i = value; type_internal = Int_QVdt; fBuiltFromString = false;}
00061 QVdt (unsigned char value): name_s("") { value_i = value; type_internal = Int_QVdt; fBuiltFromString = false;}
00062 QVdt (float value): name_s("") { value_f = value; type_internal = Double_QVdt; fBuiltFromString = false;}
00063
00064 void SetName (const std::string& name) { name_s = name; }
00065 std::string GetName () const { return name_s; }
00066
00067 const QVdt& operator= (const std::string& value);
00068 const QVdt& operator= (long int value);
00069 const QVdt& operator= (double value);
00070
00071 template<typename V> const QVdt& operator= (const std::vector<V, std::allocator<V> >& value) {
00072
00073 if (type_internal != Unassigned_QVdt) CheckType (QVdt::Vector_QVdt);
00074 type_internal = Vector_QVdt;
00075 std::back_insert_iterator<std::vector<QVdt> > inserter(value_v);
00076 std::copy (value.begin (), value.end (), inserter);
00077 fBuiltFromString = false;
00078 return *this;
00079 }
00080
00081
00082 const QVdt& operator = (int value) { return (*this) = (long int)(value); }
00083 const QVdt& operator = (short value) { return (*this) = (long int)(value); }
00084 const QVdt& operator = (char value) { return (*this) = (long int)(value); }
00085 const QVdt& operator = (unsigned long value) { return (*this) = (long int)(value); }
00086 const QVdt& operator = (unsigned short value) { return (*this) = (long int)(value); }
00087 const QVdt& operator = (unsigned char value) { return (*this) = (long int)(value); }
00088 const QVdt& operator = (float value) { return (*this) = double(value); }
00089 const QVdt& operator = (const QVdt& other);
00090
00091 bool is_valid () const { return (type_internal == Unassigned_QVdt) ? 0 : 1; }
00092
00093 QVdt_type GetType () const { return type_internal; }
00094 long int GetInt () const;
00095 double GetDouble () const;
00096 const std::string& GetString () const;
00097 const QVdt_vector& GetVector () const;
00098 bool GetBool () const { return bool (GetInt ()); }
00099
00100 private:
00101 QVdt_type type_internal;
00102
00103 long int value_i;
00104 double value_f;
00105 mutable std::string value_s;
00106 QVdt_vector value_v;
00107
00108 std::string name_s;
00109 bool fBuiltFromString;
00110 void CheckType (QVdt_type new_type) const;
00111 std::string ToString() const;
00112
00113 QVdt_type SearchType (const std::string& str);
00114 void AssignValue (const std::string& str);
00115 };
00116
00117 std::ostream& operator<< (std::ostream&, const QVdt&);
00118 #endif