00001 /*00002 * @file QVdt.hh00003 * @class QVdt00004 * @author A. Razeto00005 * @author M. Vignati (mantainer)00006 * @brief Variable Data Type00007 *00008 * Variable Data Type is an object which is constructed from00009 * a string and holds the type of the assigne value.00010 * QVdt("1000") creates a QVdt obj holding an integer with value00011 * 1000. Later the obj value can be fetced only if the query00012 * matches the QVdt type, else an exception is generated.00013 * An assignement operator is present, which does not allow00014 * runtime type change (except float/int).00015 * 00016 */00017 #ifndef _Q_VDT_H00018 #define _Q_VDT_H00019 #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 (longint 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("") { // This should stay in .cc file, but00046 // gcc does not have export for templates00047
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 // Since cast is not called in some onstructor operator these methods are necessary00054 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 (unsignedlong value): name_s("") { value_i = value; type_internal = Int_QVdt; fBuiltFromString = false;}
00060 QVdt (unsignedshort value): name_s("") { value_i = value; type_internal = Int_QVdt; fBuiltFromString = false;}
00061 QVdt (unsignedchar 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= (longint value);
00069 const QVdt& operator= (double value);
00070
00071 template<typename V> const QVdt& operator= (const std::vector<V, std::allocator<V> >& value) { // This should stay in .cc file, but00072 // gcc does not have export for templates00073 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 // Since cast is not called in assignement operator these methods are necessary00082 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 = (unsignedlong value) { return (*this) = (long int)(value); }
00086 const QVdt& operator = (unsignedshort value) { return (*this) = (long int)(value); }
00087 const QVdt& operator = (unsignedchar 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 longint 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 longint 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; // Throws an exception if the internal type 00111 std::string ToString() const;
00112 // is different from the required type00113 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
Generated on Tue Nov 16 10:49:55 2010 for CUORE Software by
1.5.6
In questo sito non sono utilizzati cookie per la profilazione degli utenti. Utilizza cookie di sessione, necessari per il corretto funzionamento dello stesso e per gestire l'autenticazione ai servizi on-line, alla intranet e alle aree riservate... leggi tutto