3 Copyright (c) 2012 Jakob Leben & Tim Blechmann
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program 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
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef SCIDE_CORE_SC_INTROSPECTION_HPP_INCLUDED
22 #define SCIDE_CORE_SC_INTROSPECTION_HPP_INCLUDED
28 #include <QSharedPointer>
35 #include <boost/flyweight.hpp>
38 static inline std::size_t hash_value(QString
const& b
)
44 namespace ScLanguage
{
46 typedef boost::flyweight
<QString
> FlyweightString
;
48 typedef std::map
<QString
, QSharedPointer
<class Class
> > ClassMap
;
49 typedef std::multimap
<QString
, QSharedPointer
<class Method
> > MethodMap
;
50 typedef QVector
<class Argument
> ArgumentVector
;
51 typedef QVector
<class Method
*> MethodVector
;
55 FlyweightString defaultValue
;
68 bool isSubclassOf(const Class
* parentClass
) const
70 if (superClass
== parentClass
)
73 if (superClass
== NULL
)
76 return superClass
->isSubclassOf(parentClass
);
82 SignatureWithoutArguments
,
83 SignatureWithArguments
,
84 SignatureWithArgumentsAndDefaultValues
87 QString
signature( SignatureStyle style
) const;
91 ArgumentVector arguments
;
98 static inline QString
makeFullMethodName(QString
const & className
, QString
const & methodName
)
100 QString
ret (className
);
101 if (ret
.startsWith("Meta_")) {
106 ret
.append(methodName
);
114 Introspection( QString
const & yamlString
);
117 typedef QMap
< QString
, QList
<Method
*> > ClassMethodMap
; // maps Path to List of Methods
119 const ClassMap
& classMap() const { return mClassMap
; }
120 const MethodMap
& methodMap() const { return mMethodMap
; }
122 const Class
* findClass( QString
const & className
) const;
123 ClassMethodMap
constructMethodMap( const Class
* klass
) const;
124 ClassMethodMap
constructMethodMap( QString
const & className
) const
126 return constructMethodMap(findClass(className
));
129 QString
const & classLibraryPath() const
131 return mClassLibraryPath
;
134 // remove class library path, userExtensionDir and systemExtensionDir
135 QString
compactLibraryPath(QString
const & path
) const;
137 bool isClassMethod (const Method
* method
) const
139 return (method
->ownerClass
->name
.get().startsWith("Meta_"));
142 bool introspectionAvailable() const
144 return !mClassMap
.empty();
149 bool parse(const QString
& yamlString
);
150 void inferClassLibraryPath();
156 mClassLibraryPath
.clear();
160 MethodMap mMethodMap
;
161 QString mClassLibraryPath
;
162 QString mUserExtensionDir
;
163 QString mSystemExtensionDir
;
166 } // namespace ScLanguage
170 Q_DECLARE_METATYPE(ScIDE::ScLanguage::Class
*)
171 Q_DECLARE_METATYPE(const ScIDE::ScLanguage::Method
*)
173 #endif // SCIDE_CORE_SC_INTROSPECTION_HPP_INCLUDED