summaryrefslogtreecommitdiff
path: root/src/members.cpp
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-10-14 07:42:37 -0700
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-10-14 07:42:37 -0700
commitb2042dbd58c043ab49e9b0dbb51bf8516fe8cea8 (patch)
tree25c7806d4c9d5fb237c0995b4bd12c4664bf853a /src/members.cpp
parent53272534a76a9d8cbee4ee887e1f360c4a99728b (diff)
Initial attempt to register native C++ class methods directly to PHP
Diffstat (limited to 'src/members.cpp')
-rw-r--r--src/members.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/members.cpp b/src/members.cpp
new file mode 100644
index 0000000..5711a4b
--- /dev/null
+++ b/src/members.cpp
@@ -0,0 +1,94 @@
+/**
+ * Members.cpp
+ *
+ * Implementation of the members class
+ *
+ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * @copyright 2013 Copernica BV
+ */
+#include "includes.h"
+
+/**
+ * Set up namespace
+ */
+namespace Php {
+
+/**
+ * Destructor
+ */
+Members::~Members()
+{
+ // check if there are methods
+ if (_methods) delete[] _methods;
+}
+
+/**
+ * Number of methods
+ * @return integer
+ */
+int Members::methods()
+{
+ // result variable
+ int result = 0;
+
+ // loop through the functions
+ for (auto it = begin(); it != end(); it++)
+ {
+ std::cout << "iter" << std::endl;
+
+ // check if this is a method
+ if (it->isMethod()) result++;
+ }
+
+ // done
+ return result;
+}
+
+/**
+ * Get access to the methods
+ * @return Methods
+ */
+struct _zend_function_entry *Members::methods(const char *classname)
+{
+ // already set?
+ if (_methods) return _methods;
+
+ // the number of methods
+ int count = methods();
+
+ std::cout << "allocate " << count << " methods" << std::endl;
+
+ // allocate memory for the functions
+ _methods = new zend_function_entry[count + 1];
+
+ // keep iterator counter
+ int i = 0;
+
+ // loop through the functions
+ for (auto it = begin(); it != end(); it++)
+ {
+ // skip if this is not a method
+ if (!it->isMethod()) continue;
+
+ // retrieve entry
+ zend_function_entry *entry = &_methods[i++];
+
+ // let the function fill the entry
+ it->fill(entry, classname);
+ }
+
+ // last entry should be set to all zeros
+ zend_function_entry *last = &_methods[i];
+
+ // all should be set to zero
+ memset(last, 0, sizeof(zend_function_entry));
+
+ // done
+ return _methods;
+}
+
+/**
+ * End of namespace
+ */
+}
+