• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdevelop API Reference
  • KDE Home
  • Contact Us
 

kdevplatform/language/duchain

  • sources
  • kfour-appscomplete
  • kdevelop
  • kdevplatform
  • language
  • duchain
  • types
constantintegraltype.h
Go to the documentation of this file.
1 /* This file is part of KDevelop
2  Copyright 2002-2005 Roberto Raggi <[email protected]>
3  Copyright 2006 Adam Treat <[email protected]>
4  Copyright 2006-2008 Hamish Rodda <[email protected]>
5  Copyright 2007-2008 David Nolden <[email protected]>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License version 2 as published by the Free Software Foundation.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef KDEVPLATFORM_CONSTANTINTEGRALTYPE_H
23 #define KDEVPLATFORM_CONSTANTINTEGRALTYPE_H
24 
25 #include "integraltype.h"
26 #include "typesystemdata.h"
27 
28 namespace KDevelop {
29 template <typename T>
30 T constant_value(const qint64* realval)
31 {
32  T value;
33  memcpy(&value, realval, sizeof(T));
34  return value;
35 }
36 
37 class KDEVPLATFORMLANGUAGE_EXPORT ConstantIntegralType
38  : public IntegralType
39 {
40 public:
41  ConstantIntegralType(const ConstantIntegralType& rhs);
42 
43  explicit ConstantIntegralType(ConstantIntegralTypeData& data);
44 
45  explicit ConstantIntegralType(uint type = TypeNone);
46 
47  ConstantIntegralType& operator=(const ConstantIntegralType& rhs) = delete;
48 
49  using Ptr = TypePtr<ConstantIntegralType>;
50 
54  template <class ValueType>
55  void setValue(ValueType value)
56  {
57  if (AbstractType::modifiers() & UnsignedModifier)
58  setValueInternal<quint64>(value);
59  else if (IntegralType::dataType() == TypeFloat)
60  setValueInternal<float>(value);
61  else if (IntegralType::dataType() == TypeDouble)
62  setValueInternal<double>(value);
63  else
64  setValueInternal<qint64>(value);
65  }
66 
72  template <class ValueType>
73  ValueType value() const
74  {
75  if (modifiers() & UnsignedModifier) {
76  return constant_value<quint64>(&d_func()->m_value);
77  } else if (dataType() == TypeFloat) {
78  return constant_value<float>(&d_func()->m_value);
79  } else if (dataType() == TypeDouble) {
80  return constant_value<double>(&d_func()->m_value);
81  } else {
82  return constant_value<qint64>(&d_func()->m_value);
83  }
84  }
85 
86  qint64 plainValue() const;
87 
88  QString toString() const override;
89 
90  QString valueAsString() const;
91 
92  bool equals(const KDevelop::AbstractType* rhs) const override;
93 
94  KDevelop::AbstractType* clone() const override;
95 
96  uint hash() const override;
97 
98  enum {
99  Identity = 14
100  };
101 
102  using Data = ConstantIntegralTypeData;
103 
104 protected:
105  TYPE_DECLARE_DATA(ConstantIntegralType);
106 
107 private:
108  //Sets the value without casting
109  template <class ValueType>
110  void setValueInternal(ValueType value);
111 };
112 
113 template <>
114 inline ConstantIntegralType* fastCast<ConstantIntegralType*>(AbstractType* from)
115 {
116  if (!from || from->whichType() != KDevelop::AbstractType::TypeIntegral)
117  return nullptr;
118  else
119  return dynamic_cast<ConstantIntegralType*>(from);
120 }
121 }
122 
123 #endif // KDEVPLATFORM_CONSTANTINTEGRALTYPE_H
KDevelop::ConstantIntegralType::setValue
void setValue(ValueType value)
The types and modifiers are not changed! The values are casted internally to the local representation...
Definition: constantintegraltype.h:55
KDevelop::ConstantIntegralType::value
ValueType value() const
For booleans, the value is 1 for true, and 0 for false.
Definition: constantintegraltype.h:73
integraltype.h
KDevelop::fastCast< ConstantIntegralType * >
ConstantIntegralType * fastCast< ConstantIntegralType * >(AbstractType *from)
Definition: constantintegraltype.h:114
KDevelop::AbstractType::modifiers
quint32 modifiers() const
Access the type modifiers.
Definition: abstracttype.cpp:49
TYPE_DECLARE_DATA
#define TYPE_DECLARE_DATA(Class)
This macro is used to declare type-specific data-access functions within subclasses of AbstractType.
Definition: abstracttype.h:38
AbstractTypeData
KDevelop::TypePtr< AbstractType >
KDevelop::AbstractType::whichType
virtual WhichType whichType() const
Determine which data type this abstract type represents.
Definition: abstracttype.cpp:120
typesystemdata.h
QString
KDevelop::IntegralType
A type representing inbuilt data types.
Definition: integraltype.h:35
KDevelop::IntegralType::dataType
uint dataType() const
Access the integral type.
Definition: integraltype.cpp:38
KDevelop::ConstantIntegralType
Definition: constantintegraltype.h:37
KDevelop::ConstantIntegralTypeData
Private data structure for ConstantIntegralType.
Definition: typesystemdata.h:246
KDevelop
Definition: abstractfunctiondeclaration.cpp:27
KDevelop::AbstractType::TypeIntegral
an integral
Definition: abstracttype.h:216
KDevelop::constant_value
T constant_value(const qint64 *realval)
Definition: constantintegraltype.h:30
KDevelop::AbstractType
Base class for all types.
Definition: abstracttype.h:87
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Mar 4 2021 23:31:17 by doxygen 1.8.16 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kdevplatform/language/duchain

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

kdevelop API Reference

Skip menu "kdevelop API Reference"
  • kdevplatform
  •   debugger
  •   documentation
  •   interfaces
  •   language
  •     assistant
  •     backgroundparser
  •     checks
  •     classmodel
  •     codecompletion
  •     codegen
  •     duchain
  •     editor
  •     highlighting
  •     interfaces
  •     util
  •   outputview
  •   project
  •   serialization
  •   shell
  •   sublime
  •   tests
  •   util
  •   vcs

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal