summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-14 15:02:40 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-14 15:02:40 +0100
commitab98c70a98e860f4cce0332d7164077cffa51b30 (patch)
tree44f429f0b0c920cb51724171ebd167b926cc8122
parent6c64773dc5edd4b56eabcfa76b66b53ab76ecdf6 (diff)
Value::numericValue() now returns a int64_t, and no longer a long
-rw-r--r--include/callstatic.h64
-rw-r--r--include/value.h12
-rw-r--r--src/arithmetic.h14
-rw-r--r--src/classbase.cpp6
-rw-r--r--src/includes.h2
-rw-r--r--src/numericmember.h (renamed from src/longmember.h)10
-rw-r--r--src/value.cpp4
7 files changed, 27 insertions, 85 deletions
diff --git a/include/callstatic.h b/include/callstatic.h
deleted file mode 100644
index 3979ef3..0000000
--- a/include/callstatic.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * CallStatic.h
- *
- * Class that performs a lot of C++11 magic to find out if the __callStatic()
- * method was implemented by the user, and if it was, calls it
- *
- */
-
-namespace Php {
-
-/**
- * SFINAE test to check if the __callStatic method is defined
- *
- * This type trait checks if the __callStatic method is defined in class T
- *
- * @see http://stackoverflow.com/questions/257288/is-it-possible-to-write-a-c-template-to-check-for-a-functions-existence
- */
-template <typename T>
-class HasCallStatic
-{
- typedef char one;
- typedef long two;
-
- template <typename C> static one test( decltype(&C::__callStatic) ) ;
- template <typename C> static two test(...);
-
-public:
- static const bool value = sizeof(test<T>(0)) == sizeof(char);
-};
-
-/**
- * Function that only exists if the class T has a __callStatic method
- * @param name Name of the function
- * @param params Parameters passed to the function
- * @return Value
- */
-template<typename T>
-typename std::enable_if<HasCallStatic<T>::value, Value >::type
-callStatic(const char *name, Parameters &params)
-{
- // call the __callStatic() function
- return T::__callStatic(name, params);
-}
-
-/**
- * Function that only exists if the class T does not have a __callStatic method
- * @param name Name of the function
- * @param params Parameters passed to the function
- * @return Value
- */
-template<typename T>
-typename std::enable_if<!HasCallStatic<T>::value >::type
-callStatic(const char *name, Parameters &params)
-{
- std::cout << "has NO call static" << std::endl;
-
- return nullptr;
-}
-
-/**
- * End namespace
- */
-}
-
diff --git a/include/value.h b/include/value.h
index 9c48f1f..fce8750 100644
--- a/include/value.h
+++ b/include/value.h
@@ -381,9 +381,15 @@ public:
/**
* Retrieve the value as number
- * @return long
- */
- long numericValue() const;
+ *
+ * We force this to be a int64_t because we assume that most
+ * servers run 64 bits nowadays, and because we use int32_t, int64_t
+ * almost everywhere, instead of 'long' and on OSX neither of
+ * these intxx_t types is defined as 'long'...
+ *
+ * @return int64_t
+ */
+ int64_t numericValue() const;
/**
* Retrieve the value as boolean
diff --git a/src/arithmetic.h b/src/arithmetic.h
index ae690bc..21343d1 100644
--- a/src/arithmetic.h
+++ b/src/arithmetic.h
@@ -55,7 +55,7 @@ public:
if (_value->isFloat()) return Value(F<double>()(_value->floatValue(), value));
// apply to natural numbers
- return Value(F<long>()(_value->numericValue(), value));
+ return Value(F<int64_t>()(_value->numericValue(), value));
}
/**
@@ -69,7 +69,7 @@ public:
if (_value->isFloat()) return Value(F<double>()(_value->floatValue(), value));
// apply to natural numbers
- return Value(F<long>()(_value->numericValue(), value));
+ return Value(F<int64_t>()(_value->numericValue(), value));
}
/**
@@ -83,7 +83,7 @@ public:
if (_value->isFloat()) return Value(F<double>()(_value->floatValue(), value));
// apply to natural numbers
- return Value(F<long>()(_value->numericValue(), value));
+ return Value(F<int64_t>()(_value->numericValue(), value));
}
/**
@@ -97,7 +97,7 @@ public:
if (_value->isFloat()) return Value(F<double>()(_value->floatValue(), value?1:0));
// apply to natural numbers
- return Value(F<long>()(_value->numericValue(), value?1:0));
+ return Value(F<int64_t>()(_value->numericValue(), value?1:0));
}
/**
@@ -114,7 +114,7 @@ public:
if (_value->isFloat()) return Value(F<double>()(_value->floatValue(), v));
// apply to natural numbers
- return Value(F<long>()(_value->numericValue(), v));
+ return Value(F<int64_t>()(_value->numericValue(), v));
}
/**
@@ -174,7 +174,7 @@ public:
if (_value->isFloat()) return _value->operator=(F<double>()(_value->floatValue(), value));
// do a numeric operation
- return _value->operator=(F<long>()(_value->numericValue(), value));
+ return _value->operator=(F<int64_t>()(_value->numericValue(), value));
}
/**
@@ -188,7 +188,7 @@ public:
if (_value->isFloat()) return _value->operator=(F<double>()(_value->floatValue(), value));
// do a numeric operation
- return _value->operator=(F<long>()(_value->numericValue(), value));
+ return _value->operator=(F<int64_t>()(_value->numericValue(), value));
}
/**
diff --git a/src/classbase.cpp b/src/classbase.cpp
index 09850a7..ea24cfd 100644
--- a/src/classbase.cpp
+++ b/src/classbase.cpp
@@ -1595,7 +1595,7 @@ void ClassBase::property(const char *name, std::nullptr_t value, int flags)
void ClassBase::property(const char *name, int16_t value, int flags)
{
// add property
- _members.push_back(std::make_shared<LongMember>(name, value, flags));
+ _members.push_back(std::make_shared<NumericMember>(name, value, flags));
}
/**
@@ -1607,7 +1607,7 @@ void ClassBase::property(const char *name, int16_t value, int flags)
void ClassBase::property(const char *name, int32_t value, int flags)
{
// add property
- _members.push_back(std::make_shared<LongMember>(name, value, flags));
+ _members.push_back(std::make_shared<NumericMember>(name, value, flags));
}
/**
@@ -1619,7 +1619,7 @@ void ClassBase::property(const char *name, int32_t value, int flags)
void ClassBase::property(const char *name, int64_t value, int flags)
{
// add property
- _members.push_back(std::make_shared<LongMember>(name, value, flags));
+ _members.push_back(std::make_shared<NumericMember>(name, value, flags));
}
/**
diff --git a/src/includes.h b/src/includes.h
index 721b29e..0c00df3 100644
--- a/src/includes.h
+++ b/src/includes.h
@@ -83,7 +83,7 @@
#include "method.h"
#include "member.h"
#include "nullmember.h"
-#include "longmember.h"
+#include "numericmember.h"
#include "boolmember.h"
#include "stringmember.h"
#include "floatmember.h"
diff --git a/src/longmember.h b/src/numericmember.h
index 09d3d8a..99889c6 100644
--- a/src/longmember.h
+++ b/src/numericmember.h
@@ -1,7 +1,7 @@
/**
- * LongMember.h
+ * NumericMember.h
*
- * Implementation for a property that is initially set to a long value
+ * Implementation for a property that is initially set to a numeric value
*
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
* @copyright 2013, 2014 Copernica BV
@@ -15,7 +15,7 @@ namespace Php {
/**
* Class definition
*/
-class LongMember : public Member
+class NumericMember : public Member
{
private:
/**
@@ -31,12 +31,12 @@ public:
* @param value
* @param flags
*/
- LongMember(const char *name, long value, int flags) : Member(name, flags), _value(value) {}
+ NumericMember(const char *name, long value, int flags) : Member(name, flags), _value(value) {}
/**
* Destructor
*/
- virtual ~LongMember() {}
+ virtual ~NumericMember() {}
/**
* Declare class constant
diff --git a/src/value.cpp b/src/value.cpp
index 29b6dcd..9af2d14 100644
--- a/src/value.cpp
+++ b/src/value.cpp
@@ -74,7 +74,7 @@ Value::Value(int32_t value)
}
/**
- * Constructor based on long value
+ * Constructor based on int64_t value
* @param value
*/
Value::Value(int64_t value)
@@ -1415,7 +1415,7 @@ Value Value::clone(Type type) const
* Retrieve the value as integer
* @return long
*/
-long Value::numericValue() const
+int64_t Value::numericValue() const
{
// already a long?
if (isNumeric()) return Z_LVAL_P(_val);