[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [smokegen/smokev4] /: move construct_copy to smokeutils
From:       Arno Rehn <arno () arnorehn ! de>
Date:       2012-10-12 14:03:19
Message-ID: 20121012140319.10122A60E8 () git ! kde ! org
[Download RAW message or body]

Git commit d174fb2073477de0918f62b970e73268a7a9f355 by Arno Rehn.
Committed on 11/10/2012 at 15:42.
Pushed by arnorehn into branch 'smokev4'.

move construct_copy to smokeutils

M  +28   -0    smokeutils.cpp
M  +8    -1    smokeutils.h

http://commits.kde.org/smokegen/d174fb2073477de0918f62b970e73268a7a9f355

diff --git a/smokeutils.cpp b/smokeutils.cpp
index 3dd452a..251d73d 100644
--- a/smokeutils.cpp
+++ b/smokeutils.cpp
@@ -159,6 +159,34 @@ std::vector<SmokeType> SmokeType::templateArguments() const {
     return ret;
 }
 
+void *SmokeClass::constructCopy(void *obj, SmokeBinding *binding) const
+{
+    std::string ccSig = unqualifiedName();
+    ccSig.append("#");
+
+    std::string ccArg; ccArg.reserve(ccSig.size() + static_strlen("const &"));
+    ccArg.append("const ").append(className()).push_back('&');
+
+    std::vector<std::string> argTypes; argTypes.push_back(ccArg);
+
+    SmokeMethod ccMeth = SmokeManager::self()->findMethod(moduleIndex(), ccSig, argTypes);
+
+    if(!ccMeth) {
+        return 0;
+    }
+
+    // Okay, ccMeth is the copy constructor. Time to call it.
+    Smoke::StackItem args[2];
+    args[0].s_voidp = 0;
+    args[1].s_voidp = obj;
+    ccMeth.call(args);
+
+    // Initialize the binding for the new instance
+    setBindingForObject(args[0].s_voidp, binding);
+
+    return args[0].s_voidp;
+}
+
 bool SmokeClass::resolve() {
     if (!isExternal()) return false;
     Smoke::ModuleIndex newId = SmokeManager::self()->findClass(_c->className);
diff --git a/smokeutils.h b/smokeutils.h
index e6cb74a..96f4617 100644
--- a/smokeutils.h
+++ b/smokeutils.h
@@ -43,7 +43,12 @@
 #include "smokemanager.h"
 
 template <typename CharType, std::size_t N>
-constexpr std::size_t static_strlen(const CharType (&) [N]) {
+#if __cplusplus >= 201103L
+constexpr
+#else
+inline
+#endif
+std::size_t static_strlen(const CharType (&) [N]) {
     // subtract trailing zero
     return N - 1;
 }
@@ -164,6 +169,8 @@ public:
         classFn()(0, obj, stack);
     }
 
+    void *constructCopy(void *obj, SmokeBinding *binding) const;
+
     operator bool() const { return _c && _c->className != 0; }
 
     Smoke::ModuleIndex moduleIndex() const { return _mi; }

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic