[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [smokegen/smokev4] /: fix smokeapi
From: Arno Rehn <arno () arnorehn ! de>
Date: 2012-10-12 14:03:19
Message-ID: 20121012140319.22B00A60EC () git ! kde ! org
[Download RAW message or body]
Git commit 4dcd4cc3df2318c255c52a039d29393def1fa4d2 by Arno Rehn.
Committed on 12/10/2012 at 15:31.
Pushed by arnorehn into branch 'smokev4'.
fix smokeapi
M +1 -1 CMakeLists.txt
M +5 -2 smoke/smokemanager.cpp
M +5 -0 smoke/smokemanager.h
M +14 -31 smokeapi/main.cpp
http://commits.kde.org/smokegen/4dcd4cc3df2318c255c52a039d29393def1fa4d2
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 75dec51..c0ba6f1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -53,5 +53,5 @@ install( FILES smokegen_string.h DESTINATION \
${CMAKE_INSTALL_PREFIX}/share/smoke add_subdirectory(cmake)
add_subdirectory(generators)
add_subdirectory(smoke)
-# add_subdirectory(smokeapi)
+add_subdirectory(smokeapi)
# add_subdirectory(deptool)
diff --git a/smoke/smokemanager.cpp b/smoke/smokemanager.cpp
index 563abec..4e2f07b 100644
--- a/smoke/smokemanager.cpp
+++ b/smoke/smokemanager.cpp
@@ -33,8 +33,6 @@
static const int SMOKE_VERSION = 3;
-typedef std::map<std::string, Smoke*> StringSmokeMap;
-
#ifndef _WIN32
typedef std::vector<void*> HandleList;
#else
@@ -101,6 +99,11 @@ Smoke* SmokeManager::get(const std::string& moduleName, \
SmokeManager::LoadOption return smoke;
}
+const SmokeManager::StringSmokeMap& SmokeManager::loadedModules() const
+{
+ return d->moduleNameMap;
+}
+
Smoke* SmokeManager::load(const std::string& moduleName)
{
std::ostringstream libName;
diff --git a/smoke/smokemanager.h b/smoke/smokemanager.h
index ba483ee..1711573 100644
--- a/smoke/smokemanager.h
+++ b/smoke/smokemanager.h
@@ -21,6 +21,7 @@
#include "smoke.h"
+#include <map>
#include <string>
#include <vector>
@@ -29,6 +30,8 @@ class Smoke;
class BASE_SMOKE_EXPORT SmokeManager
{
public:
+ typedef std::map<std::string, Smoke*> StringSmokeMap;
+
enum LoadOptions {
DoNotLoad = 0,
LoadIfRequired = 1,
@@ -40,6 +43,8 @@ public:
Smoke *load(const std::string& moduleName);
Smoke *get(const std::string& moduleName, LoadOptions options = DoNotLoad);
+ const StringSmokeMap& loadedModules() const;
+
/// find class id for 'className'
Smoke::ModuleIndex findClass(const char* className);
inline Smoke::ModuleIndex findClass(const std::string& className) { return \
findClass(className.c_str()); }
diff --git a/smokeapi/main.cpp b/smokeapi/main.cpp
index 9196e92..1ed8e4c 100644
--- a/smokeapi/main.cpp
+++ b/smokeapi/main.cpp
@@ -21,36 +21,19 @@
#include <QtCore>
#include <QtDebug>
-#include <smoke.h>
+#include <smoke/smoke.h>
+#include <smoke/smokemanager.h>
static QTextStream qOut(stdout);
-typedef Smoke *(*InitSmokeFn)();
typedef QPair<Smoke::ModuleIndex,int> ClassEntry;
-static QList<Smoke*> smokeModules;
-
static bool showClassNamesOnly;
static bool showParents;
static bool matchPattern;
static bool caseInsensitive;
static QRegExp targetPattern;
-static Smoke*
-loadSmokeModule(QString moduleName) {
- QFileInfo file(QString("libsmoke") + moduleName);
- QLibrary lib(file.filePath());
-
- QString init_name = "init_" + moduleName + "_Smoke";
- InitSmokeFn init = (InitSmokeFn) lib.resolve(init_name.toLatin1());
-
- if (!init)
- qFatal("Couldn't resolve %s: %s", qPrintable(init_name), \
qPrintable(lib.errorString()));
-
- Smoke *smoke = (*init)();
- return smoke;
-}
-
static QString
methodToString(Smoke::ModuleIndex methodId)
{
@@ -126,8 +109,8 @@ getAllParents(const Smoke::ModuleIndex& classId, int indent)
*parent != 0;
parent++ )
{
- Smoke::ModuleIndex parentId = \
Smoke::findClass(smoke->classes[*parent].className);
- Q_ASSERT(parentId != Smoke::NullModuleIndex);
+ Smoke::ModuleIndex parentId = \
SmokeManager::self()->findClass(smoke->classes[*parent].className); + \
Q_ASSERT(parentId); result << getAllParents(parentId, indent + 1);
}
@@ -141,10 +124,10 @@ showClass(const Smoke::ModuleIndex& classId, int indent)
if (showClassNamesOnly) {
QString className = \
QString::fromLatin1(classId.smoke->classes[classId.index].className); if \
(!matchPattern || targetPattern.indexIn(className) != -1) {
- while (indent > 0) {
- qOut << " ";
- indent--;
- }
+ while (indent > 0) {
+ qOut << " ";
+ indent--;
+ }
qOut << className << "\n";
}
@@ -232,7 +215,7 @@ int main(int argc, char** argv)
} else if (arguments[i] == QLatin1String("-r") || arguments[i] == \
QLatin1String("--require")) { i++;
if (i < arguments.length()) {
- smokeModules << loadSmokeModule(arguments[i]);
+ SmokeManager::self()->load(arguments[i].toStdString());
}
i++;
} else if (arguments[i] == QLatin1String("-c") || arguments[i] == \
QLatin1String("--classes")) { @@ -259,15 +242,15 @@ int main(int argc, char** argv)
if (caseInsensitive) {
targetPattern.setCaseSensitivity(Qt::CaseInsensitive);
}
-
- smokeModules << loadSmokeModule("qtcore");
-
+
if (i >= arguments.length()) {
if (targetPattern.isEmpty()) {
PRINT_USAGE();
return 0;
} else {
- foreach (Smoke * smoke, smokeModules) {
+ typedef std::pair<std::string, Smoke*> StringSmokePair;
+ foreach (const StringSmokePair& pair, \
SmokeManager::self()->loadedModules()) { + Smoke *smoke = pair.second;
for (int i = 1; i <= smoke->numClasses; i++) {
if (!(smoke->classes[i].flags & Smoke::cf_undefined)) {
showClass(Smoke::ModuleIndex(smoke, i), 0);
@@ -282,7 +265,7 @@ int main(int argc, char** argv)
while (i < arguments.length()) {
QString className = arguments[i];
- Smoke::ModuleIndex classId = Smoke::findClass(className.toLatin1());
+ Smoke::ModuleIndex classId = \
SmokeManager::self()->findClass(className.toLatin1()); if (classId == \
Smoke::NullModuleIndex) {
qFatal("Error: class '%s' not found", className.toLatin1().constData());
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic