diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-29 13:10:46 +0100 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-29 13:10:46 +0100 |
commit | 7b7efa4f80dc5c9d26b59087270a8d89fedcc808 (patch) | |
tree | 1dfb0ce4a6662a5bcb6562b40ab91f813a959afc /tests/cpp/include/variables/005-cast-objects-to-scalars.h | |
parent | c0e1f20eeab6445d6355ea11ef7d264cb37c52cf (diff) | |
parent | 8bd7f5162870e4b39c7629c1a67a3372402406c9 (diff) |
Merge pull request #56 from valmat/tests
New tests
Diffstat (limited to 'tests/cpp/include/variables/005-cast-objects-to-scalars.h')
-rw-r--r-- | tests/cpp/include/variables/005-cast-objects-to-scalars.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/cpp/include/variables/005-cast-objects-to-scalars.h b/tests/cpp/include/variables/005-cast-objects-to-scalars.h new file mode 100644 index 0000000..f053c4d --- /dev/null +++ b/tests/cpp/include/variables/005-cast-objects-to-scalars.h @@ -0,0 +1,75 @@ +/** + * + * Test variables + * 005-cast-objects-to-scalars.phpt + * + */ + + + +/** + * Set up namespace + */ +namespace TestVariables { + + /** + * A sample class, with methods to cast objects to scalars + */ + class Obj2Scalar : public Php::Base + { + public: + /** + * C++ constructor and C++ destructpr + */ + Obj2Scalar() {} + virtual ~Obj2Scalar() {} + + /** + * Cast to a string + * + * Note that now we use const char* as return value, and not Php::Value. + * The __toString function is detected at compile time, and it does + * not have a fixed signature. You can return any value that can be picked + * up by a Php::Value object. + * + * @return const char * + */ + const char *__toString() + { + return "Mount Meru, also called Sumeru (Sanskrit)"; + } + + /** + * Cast to a integer + * @return long + */ + long __toInteger() + { + return 27032014; + } + + /** + * Cast to a floating point number + * @return double + */ + double __toFloat() + { + return 3.14159265359; + } + + /** + * Cast to a boolean + * @return bool + */ + bool __toBool() + { + return true; + } + }; + + +/** + * End of namespace + */ +} + |