language/duchain
constantintegraltype.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef CONSTANTINTEGRALTYPE_H
00023 #define CONSTANTINTEGRALTYPE_H
00024
00025 #include "integraltype.h"
00026 #include "typesystemdata.h"
00027
00028 namespace KDevelop
00029 {
00030
00031 template<typename T>
00032 T constant_value(const qint64* realval)
00033 {
00034 T value;
00035 memcpy(&value, realval, sizeof(T));
00036 return value;
00037 }
00038
00039 class KDEVPLATFORMLANGUAGE_EXPORT ConstantIntegralType : public IntegralType
00040 {
00041 public:
00042 ConstantIntegralType(const ConstantIntegralType& rhs);
00043
00044 ConstantIntegralType(ConstantIntegralTypeData& data);
00045
00046 ConstantIntegralType(uint type = TypeNone);
00047
00048 typedef TypePtr<ConstantIntegralType> Ptr;
00049
00053 template<class ValueType>
00054 void setValue(ValueType value) {
00055 if(AbstractType::modifiers() & UnsignedModifier)
00056 setValueInternal<quint64>(value);
00057 else if(IntegralType::dataType() == TypeFloat)
00058 setValueInternal<float>(value);
00059 else if(IntegralType::dataType() == TypeDouble)
00060 setValueInternal<double>(value);
00061 else
00062 setValueInternal<qint64>(value);
00063 }
00064
00070 template<class ValueType>
00071 ValueType value() const {
00072 if(modifiers() & UnsignedModifier) {
00073 return constant_value<quint64>(&d_func()->m_value);
00074 } else if(dataType() == TypeFloat) {
00075 return constant_value<float>(&d_func()->m_value);
00076 } else if(dataType() == TypeDouble) {
00077 return constant_value<double>(&d_func()->m_value);
00078 } else {
00079 return constant_value<qint64>(&d_func()->m_value);
00080 }
00081 }
00082
00083 qint64 plainValue() const;
00084
00085 virtual QString toString() const;
00086
00087 virtual bool equals(const KDevelop::AbstractType* rhs) const;
00088
00089 virtual KDevelop::AbstractType* clone() const;
00090
00091 virtual uint hash() const;
00092
00093 enum {
00094 Identity = 14
00095 };
00096
00097 typedef ConstantIntegralTypeData Data;
00098
00099 protected:
00100 TYPE_DECLARE_DATA(ConstantIntegralType);
00101
00102 private:
00103
00104 template<class ValueType>
00105 void setValueInternal(ValueType value);
00106 };
00107
00108 template<>
00109 inline ConstantIntegralType* fastCast<ConstantIntegralType*>(AbstractType* from) {
00110 if(!from || from->whichType() != KDevelop::AbstractType::TypeIntegral)
00111 return 0;
00112 else
00113 return dynamic_cast<ConstantIntegralType*>(from);
00114 }
00115
00116 }
00117
00118
00119 #endif // CPPTYPES_H
00120