1 /* 2 SPDX-FileCopyrightText: 2009 Milian Wolff <mail@milianw.de> 3 4 SPDX-License-Identifier: LGPL-2.0-or-later 5 */ 6 7 #ifndef PHP_STRUCTURETYPE_H 8 #define PHP_STRUCTURETYPE_H 9 10 #include <language/duchain/types/structuretype.h> 11 #include <language/duchain/types/typesystemdata.h> 12 #include <serialization/indexedstring.h> 13 14 #include "phpduchainexport.h" 15 16 namespace Php 17 { 18 19 class KDEVPHPDUCHAIN_EXPORT StructureTypeData : public KDevelop::StructureTypeData 20 { 21 public: 22 /// Constructor StructureTypeData()23 StructureTypeData() 24 : KDevelop::StructureTypeData() 25 { 26 } 27 /// Copy constructor. \param rhs data to copy StructureTypeData(const StructureTypeData & rhs)28 StructureTypeData( const StructureTypeData& rhs ) 29 : KDevelop::StructureTypeData(rhs), prettyName(rhs.prettyName) 30 { 31 } 32 33 KDevelop::IndexedString prettyName; 34 }; 35 36 /** 37 * Drop-In replacement for the StructureType in KDevplatform which 38 * makes it possible to store the type as lower case but 39 * keeping the "pretty" name intact. 40 */ 41 class KDEVPHPDUCHAIN_EXPORT StructureType: public KDevelop::StructureType 42 { 43 public: 44 typedef KDevelop::TypePtr<StructureType> Ptr; 45 46 /// Default constructor 47 StructureType(); 48 /// Copy constructor. \param rhs type to copy 49 StructureType(const StructureType& rhs); 50 /// Constructor using raw data. \param data internal data. 51 StructureType(StructureTypeData& data); 52 53 void setPrettyName(const KDevelop::IndexedString& name); 54 KDevelop::IndexedString prettyName() const; 55 56 QString toString() const override; 57 58 KDevelop::AbstractType* clone() const override; 59 60 uint hash() const override; 61 62 enum { 63 ///TODO: is that value OK? 64 Identity = 51 65 }; 66 67 typedef StructureTypeData Data; 68 typedef KDevelop::StructureType BaseType; 69 70 protected: 71 TYPE_DECLARE_DATA(StructureType); 72 }; 73 74 } 75 76 namespace KDevelop 77 { 78 79 template<> 80 inline Php::StructureType* fastCast<Php::StructureType*>(AbstractType* from) { 81 if ( !from || from->whichType() != AbstractType::TypeStructure ) { 82 return nullptr; 83 } else { 84 return dynamic_cast<Php::StructureType*>(from); 85 } 86 } 87 88 } 89 90 #endif // PHP_STRUCTURETYPE_H 91 92