summaryrefslogtreecommitdiff
path: root/tests/cpp/include
diff options
context:
space:
mode:
authorvalmat <ufabiz@gmail.com>2014-03-28 00:42:09 +0600
committervalmat <ufabiz@gmail.com>2014-03-28 00:42:09 +0600
commit28152192b85cbe9bf5ea08ebe8c706d12e2e13e5 (patch)
treed8a5cbee7e39f6b21c0e698d1ac10ac764b00193 /tests/cpp/include
parentf56cff9e4f67a949e6f0ae35ca63aaaea16d9a41 (diff)
add test: class_obj/003-comparable.phpt
Diffstat (limited to 'tests/cpp/include')
-rw-r--r--tests/cpp/include/Classes_and_objects.h (renamed from tests/cpp/include/MyCustomClass.h)62
1 files changed, 57 insertions, 5 deletions
diff --git a/tests/cpp/include/MyCustomClass.h b/tests/cpp/include/Classes_and_objects.h
index 02ff44b..e9b7434 100644
--- a/tests/cpp/include/MyCustomClass.h
+++ b/tests/cpp/include/Classes_and_objects.h
@@ -1,7 +1,7 @@
/**
*
*
- *
+ * Classes_and_objects.h
*
*/
@@ -12,10 +12,6 @@
namespace TestBaseClass {
-/**
- * Namespace to use
- */
- using namespace std;
class MyCustomClass : public Php::Base, public Php::Countable
{
@@ -61,6 +57,62 @@ namespace TestBaseClass {
};
+ /**
+ * custom comparison operator
+ */
+ class Comparable : public Php::Base
+ {
+ private:
+ /**
+ * Internal value of the class
+ * @var int
+ */
+ static int count;
+ int _nom;
+ int _value;
+
+ public:
+ /**
+ * C++ constructor
+ */
+ Comparable()
+ {
+ // start with random value
+ //_value = rand();
+ _nom = ++count;
+ _value = _nom%2+1;
+ }
+
+ /**
+ * C++ destructor
+ */
+ virtual ~Comparable() {}
+
+ /**
+ * Cast the object to a string
+ * @return std::string
+ */
+ std::string __toString()
+ {
+ return "Obj#" + std::to_string(_nom) + "(" + std::to_string(_value) + ")";
+ }
+
+ /**
+ * Compare with a different object
+ * @param that
+ * @return int
+ */
+ int __compare(const Comparable &that) const
+ {
+ return _value - that._value;
+ }
+ };
+ int Comparable::count = 0;
+
+
+
+
+
/**
* End of namespace