OSDN Git Service

[dennco] Changed the name format for plugin cell. The name format is now "value name...
authortkawata <tkawata@users.sourceforge.jp>
Tue, 29 Jan 2013 14:08:02 +0000 (23:08 +0900)
committertkawata <tkawata@users.sourceforge.jp>
Tue, 29 Jan 2013 14:08:02 +0000 (23:08 +0900)
Source/Source.pro
Source/layer1/TKContainer.cpp
Source/layer1/TKContainer.h
Source/layer1/dnplugininfo.cpp [new file with mode: 0644]
Source/layer1/dnplugininfo.h [new file with mode: 0644]
Source/layer3/QtScript/dnqscontainer.cpp
Source/layer3/QtScript/dnqscontainer.h
Source/layer3/dnplugininputcell.cpp
Source/layer3/dnplugininputcell.h
Source/layer3/dnpluginoutputcell.cpp
Source/layer3/dnpluginoutputcell.h

index 5261628..111069f 100644 (file)
@@ -66,7 +66,8 @@ SOURCES += \
     layer3/dnplugininputcell.cpp \
     layer3/dnpluginoutputcell.cpp \
     layer3/platform/qt/qtdnpluginmanager.cpp \
-    layer3/platform/qt/qtdnplugin.cpp
+    layer3/platform/qt/qtdnplugin.cpp \
+    layer1/dnplugininfo.cpp
 
 HEADERS  += \
     layer1/TKLockImpl.h \
@@ -135,7 +136,8 @@ HEADERS  += \
     layer3/dnplugin.h \
     layer3/platform/qt/qtdnpluginmanager.h \
     layer3/platform/qt/qtdnplugin.h \
-    plugins/dennco_plugin.h
+    plugins/dennco_plugin.h \
+    layer1/dnplugininfo.h
 
 FORMS += layer3/QtDennco/mainwindow.ui
 FORMS += layer3/QtDennco/portinfodialog.ui
index 8cf1e6d..121b274 100644 (file)
@@ -22,6 +22,7 @@
 #include "TKCellCode.h"
 #include "DNStorage.h"
 #include "DNUtils.h"
+#include "dnplugininfo.h"
 
 #include <string>
 
@@ -164,12 +165,32 @@ TKCell* TKContainer::addCell(std::string theLocation, std::string theName, std::
     }
     else if (type == CELLTYPE_PLUGIN_IN)
     {
-        cell = cellFactory(theLocation, theName, type, true, false);
+        DNPluginInfo info = DNPluginInfo::create(theName);
+        if (info.isValid)
+        {
+            cell = pluginCellFactory(theLocation, theName, type, info.pluginName, info.pluginValueName, true, false);
+        }
+        else
+        {
+            std::string message = std::string("Failed to initialize cell '").append(theLocation).append("#").append(theName);
+            message.append("'\nThis is a plugin input cell. The name of the cell should be described by following form:\n'pluginValueName'@'pluginName'");
+            dnNotifyError("Initialization failed", message);
+        }
         noScript = true;
     }
     else if (type == CELLTYPE_PLUGIN_OUT)
     {
-        cell = cellFactory(theLocation, theName, type, false, true);
+        DNPluginInfo info = DNPluginInfo::create(theName);
+        if (info.isValid)
+        {
+            cell = pluginCellFactory(theLocation, theName, type, info.pluginName, info.pluginValueName, false, true);
+        }
+        else
+        {
+            std::string message = std::string("Failed to initialize cell '").append(theLocation).append("#").append(theName);
+            message.append("'\nThis is a plugin output cell. The name of the cell should be described by following form:\n'pluginValueName'@'pluginName'");
+            dnNotifyError("Initialization failed", message);
+        }
         noScript = true;
     }
     else
index 36b704c..4a1eb89 100644 (file)
@@ -80,6 +80,7 @@ public:
     inline virtual float    getValue(std::string key) const = 0;
 
     virtual TKCell*         cellFactory(std::string location, std::string name, std::string type, bool canInterfaceIn, bool canInterfaceOut) = 0;
+    virtual TKCell*         pluginCellFactory(std::string location, std::string fullName, std::string type, std::string pluginName, std::string pluginValue, bool canInterfaceIn, bool canInterfaceOut) = 0;
     virtual TKAxon*         axonFactory(TKCell *theOwner) = 0;
     virtual TKReceptor*     receptorFactory(TKCell *theOwner) = 0;
     virtual TKAxonTerminal* axonTerminalFactory(TKAxon *theOwner) = 0;
diff --git a/Source/layer1/dnplugininfo.cpp b/Source/layer1/dnplugininfo.cpp
new file mode 100644 (file)
index 0000000..83deb1a
--- /dev/null
@@ -0,0 +1,48 @@
+//  Copyright (c) 2013 Dennco Project
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+//
+//  Created by tkawata on 1/29/2013.
+//
+
+#include "dnplugininfo.h"
+#include "DNUtils.h"
+
+DNPluginInfo::DNPluginInfo()
+{
+    isValid = false;
+}
+
+DNPluginInfo::DNPluginInfo(const DNPluginInfo &other)
+{
+    isValid = other.isValid;
+    pluginName = other.pluginName;
+    pluginValueName = other.pluginValueName;
+}
+
+//static
+DNPluginInfo DNPluginInfo::create(const std::string &name)
+{
+    DNPluginInfo result;
+    unsigned int idx = name.find("@");
+    if (idx != std::string::npos && idx > 0 && idx + 1 < name.length())
+    {
+        result.isValid = true;
+        result.pluginValueName = name.substr(0,idx);
+        result.pluginName = name.substr(name.find_last_of("@")+1);
+    }
+
+    return result;
+}
diff --git a/Source/layer1/dnplugininfo.h b/Source/layer1/dnplugininfo.h
new file mode 100644 (file)
index 0000000..570ea3e
--- /dev/null
@@ -0,0 +1,37 @@
+//  Copyright (c) 2013 Dennco Project
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+//
+//  Created by tkawata on 1/29/2013.
+//
+
+#ifndef DNPLUGININFO_H
+#define DNPLUGININFO_H
+
+#include <string>
+
+struct DNPluginInfo
+{
+    DNPluginInfo();
+    DNPluginInfo(const DNPluginInfo &other);
+
+    std::string pluginName;
+    std::string pluginValueName;
+    bool    isValid;
+
+    static DNPluginInfo create(const std::string& name);
+};
+
+#endif // DNPLUGININFO_H
index 17b8d39..f5abfbe 100644 (file)
@@ -117,35 +117,46 @@ TKCell* DNQSContainer::cellFactory(std::string location, std::string name, std::
     if (type == CELLTYPE_JSBASIC || type.length() == 0)
     {
         cell = new DNQSBasicCell(this, location, name, canInterfaceIn, canInterfaceOut);
-        cell->init();
     }
     else if (type == CELLTYPE_IN)
     {
         cell = new DNQSInputCell(this, location, name);
-        cell->init();
     }
     else if (type == CELLTYPE_OUT)
     {
         cell = new DNQSOutputCell(this, location, name);
-        cell->init();
     }
     else if (type == CELLTYPE_BASICSTORAGE)
     {
         cell = new DNQSBasicStorageCell(this, location, name, canInterfaceIn, canInterfaceOut);
-        cell->init();
     }
-    else if (type == CELLTYPE_PLUGIN_IN)
-    {
-        cell = new DNPluginInputCell(this, location, name);
+
+    if (cell)
         cell->init();
 
+    return cell;
+}
+
+TKCell* DNQSContainer::pluginCellFactory(std::string location, std::string fullName, std::string type, std::string pluginName, std::string pluginValue, bool canInterfaceIn, bool canInterfaceOut)
+{
+    Q_ASSERT(canInterfaceIn != canInterfaceOut);
+
+    (void)canInterfaceOut;
+
+    TKCell *cell = NULL;
+
+    if (canInterfaceIn)
+    {
+        cell = new DNPluginInputCell(this, location, fullName, pluginName, pluginValue);
     }
-    else if (type == CELLTYPE_PLUGIN_OUT)
+    else
     {
-        cell = new DNPluginOutputCell(this, location, name);
-        cell->init();
+        cell = new DNPluginOutputCell(this, location, fullName, pluginName, pluginValue);
     }
 
+    if (cell)
+        cell->init();
+
     return cell;
 }
 
index d055db8..d466537 100644 (file)
@@ -38,6 +38,7 @@ public:
     inline QScriptValue     getQSCellContainer() { return mQSCellContainer; }
 
     virtual TKCell*         cellFactory(std::string location, std::string name, std::string type, bool canInterfaceIn, bool canInterfaceOut);
+    virtual TKCell*         pluginCellFactory(std::string location, std::string fullName, std::string type, std::string pluginName, std::string pluginValue, bool canInterfaceIn, bool canInterfaceOut);
     virtual TKAxon*         axonFactory(TKCell *theOwner);
     virtual TKReceptor*     receptorFactory(TKCell *theOwner);
     virtual TKAxonTerminal* axonTerminalFactory(TKAxon *theOwner);
index e4bd03b..4821856 100644 (file)
 
 #include <limits>
 
-DNPluginInputCell::DNPluginInputCell(TKContainer *container, std::string location, std::string name):
+DNPluginInputCell::DNPluginInputCell(TKContainer *container, std::string location, std::string name, std::string pluginName, std::string valueName):
     DNCellInterfaceable(container,location,name, true, false),
-    d_plugin(NULL), d_inputValue(std::numeric_limits<float>::quiet_NaN())
+    d_plugin(NULL), d_valueName(valueName), d_inputValue(std::numeric_limits<float>::quiet_NaN())
 {
-    bool parsed = false;
-    unsigned int idx = name.find("?");
-    if (idx != std::string::npos && idx + 1 < name.length())
-    {
-        std::string pluginInfo = name.substr(idx+1);
-        unsigned int idx2 = pluginInfo.find(":");
-        if (idx != std::string::npos && idx2 > 0 && idx2 + 1 < pluginInfo.length())
-        {
-            parsed = true;
-            std::string pluginName = pluginInfo.substr(0,idx2);
-            d_valueName = pluginInfo.substr(idx2+1);
-            d_plugin = DNPluginManager::instance()->getPlugin(pluginName);
-            if (!d_plugin)
-            {
-                std::string message = std::string("Failed to initialize cell '").append(location).append("#").append(name);
-                message.append("'\nLoading the specified plugin : '").append(pluginName).append("' failed");
-                dnNotifyError("Initialization failed", message);
-            }
-        }
-    }
-    if (!parsed)
+    d_plugin = DNPluginManager::instance()->getPlugin(pluginName);
+    if (!d_plugin)
     {
         std::string message = std::string("Failed to initialize cell '").append(location).append("#").append(name);
-        message.append("'\nThis is a plugin input cell. The name of the cell should be described by following form:\n'cellName'?'pluginName':'pluginValueName'");
+        message.append("'\nLoading the specified plugin : '").append(pluginName).append("' failed");
         dnNotifyError("Initialization failed", message);
     }
 }
index e0cc0d9..8b31131 100644 (file)
@@ -30,7 +30,7 @@ class DNPluginInputCell : public DNCellInterfaceable
     float       d_inputValue;
 
 public:
-    DNPluginInputCell(TKContainer *container, std::string location, std::string name);
+    DNPluginInputCell(TKContainer *container, std::string location, std::string name, std::string pluginName, std::string valueName);
     virtual ~DNPluginInputCell();
 
     virtual bool doTick(float time);
index cc7ef79..7ad6b7b 100644 (file)
 
 #include <limits>
 
-DNPluginOutputCell::DNPluginOutputCell(TKContainer *container, std::string location, std::string name)
+DNPluginOutputCell::DNPluginOutputCell(TKContainer *container, std::string location, std::string name, std::string pluginName, std::string valueName)
     : DNCellInterfaceable(container, location, name, false, true),
-      d_plugin(NULL), d_outputValue(std::numeric_limits<float>::quiet_NaN())
+      d_plugin(NULL), d_valueName(valueName), d_outputValue(std::numeric_limits<float>::quiet_NaN())
 {
-    bool parsed = false;
-    unsigned int idx = name.find("?");
-    if (idx != std::string::npos && idx + 1 < name.length())
-    {
-        std::string pluginInfo = name.substr(idx+1);
-        unsigned int idx2 = pluginInfo.find(":");
-        if (idx != std::string::npos && idx2 > 0 && idx2 + 1 < pluginInfo.length())
-        {
-            parsed = true;
-            std::string pluginName = pluginInfo.substr(0,idx2);
-            d_valueName = pluginInfo.substr(idx2+1);
-            d_plugin = DNPluginManager::instance()->getPlugin(pluginName);
-            if (!d_plugin)
-            {
-                std::string message = std::string("Failed to initialize cell '").append(location).append("#").append(name);
-                message.append("'\nLoading the specified plugin : '").append(pluginName).append("' failed");
-                dnNotifyError("Initialization failed", message);
-            }
-        }
-    }
-    if (!parsed)
+    d_plugin = DNPluginManager::instance()->getPlugin(pluginName);
+    if (!d_plugin)
     {
         std::string message = std::string("Failed to initialize cell '").append(location).append("#").append(name);
-        message.append("'\nThis is a plugin output cell. The name of the cell should be described by following form:\n'cellName'?'pluginName':'pluginValueName'");
+        message.append("'\nLoading the specified plugin : '").append(pluginName).append("' failed");
         dnNotifyError("Initialization failed", message);
     }
 }
index c3b5c0d..2caa4c9 100644 (file)
@@ -30,7 +30,7 @@ class DNPluginOutputCell : public DNCellInterfaceable
     float       d_outputValue;
 
 public:
-    DNPluginOutputCell(TKContainer *container, std::string location, std::string name);
+    DNPluginOutputCell(TKContainer *container, std::string location, std::string name, std::string pluginName, std::string valueName);
     virtual ~DNPluginOutputCell();
 
     virtual bool doTick(float time);