• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDevelop Platform Libraries
  • Sitemap
  • Contact Us
 

language/duchain

constantintegraltype.h

00001 /* This file is part of KDevelop
00002     Copyright 2002-2005 Roberto Raggi <roberto@kdevelop.org>
00003     Copyright 2006 Adam Treat <treat@kde.org>
00004     Copyright 2006-2008 Hamish Rodda <rodda@kde.org>
00005     Copyright 2007-2008 David Nolden <david.nolden.kdevelop@art-master.de>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License version 2 as published by the Free Software Foundation.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
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   //Sets the value without casting
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 

language/duchain

Skip menu "language/duchain"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDevelop Platform Libraries

Skip menu "KDevelop Platform Libraries"
  • interfaces
  • language
  •   codegen
  •   duchain
  •   editor
  • outputview
  • project
  • shell
  • sublime
  • util
  • vcs
Generated for KDevelop Platform Libraries by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal