scide: Introspection - use smart pointers to ease memory management
[supercollider.git] / editors / sc-ide / core / sc_introspection.hpp
blobc7442352fef140eee91f0d2a0ac9d83429bc3c45
1 /*
2 SuperCollider Qt IDE
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
24 #include <QHash>
25 #include <QList>
26 #include <QMap>
27 #include <QMetaType>
28 #include <QSharedPointer>
29 #include <QString>
30 #include <QVector>
32 #include <string>
33 #include <map>
35 #include <boost/flyweight.hpp>
38 static inline std::size_t hash_value(QString const& b)
40 return qHash(b);
43 namespace ScIDE {
45 namespace ScLanguage {
47 typedef boost::flyweight<QString> FlyweightString;
49 typedef std::map<QString, QSharedPointer<class Class> > ClassMap;
50 typedef std::multimap<QString, QSharedPointer<class Method> > MethodMap;
51 typedef QVector<class Argument> ArgumentVector;
52 typedef QVector<class Method*> MethodVector;
54 struct Argument {
55 FlyweightString name;
56 FlyweightString defaultValue;
59 struct Class {
60 FlyweightString name;
61 Class *metaClass;
62 Class *superClass;
63 MethodVector methods;
64 struct {
65 FlyweightString path;
66 int position;
67 } definition;
70 struct Method {
71 Class *ownerClass;
72 FlyweightString name;
73 ArgumentVector arguments;
74 struct {
75 FlyweightString path;
76 int position;
77 } definition;
80 class Introspection
82 public:
83 Introspection();
84 ~Introspection();
86 typedef QMap< QString, QList<Method*> > ClassMethodMap; // maps Path to List of Methods
88 bool parse(const QString & yamlString );
90 const ClassMap & classMap() const { return mClassMap; }
91 const MethodMap & methodMap() const { return mMethodMap; }
93 const Class * findClass( QString const & className ) const;
94 ClassMethodMap constructMethodMap( const Class * klass ) const;
95 ClassMethodMap constructMethodMap( QString const & className ) const
97 return constructMethodMap(findClass(className));
100 QString const & classLibraryPath() const
102 return mClassLibraryPath;
105 // remove class library path, userExtensionDir and systemExtensionDir
106 QString compactLibraryPath(QString const & path) const;
108 private:
109 void inferClassLibraryPath();
111 void clear()
113 mClassMap.clear();
114 mMethodMap.clear();
115 mClassLibraryPath.clear();
118 ClassMap mClassMap;
119 MethodMap mMethodMap;
120 QString mClassLibraryPath;
121 QString mUserExtensionDir;
122 QString mSystemExtensionDir;
125 } // namespace ScLanguage
127 } // namespace ScIDE
129 Q_DECLARE_METATYPE(ScIDE::ScLanguage::Class*)
130 Q_DECLARE_METATYPE(const ScIDE::ScLanguage::Method*)
132 #endif // SCIDE_CORE_SC_INTROSPECTION_HPP_INCLUDED