summaryrefslogtreecommitdiff
path: root/include/ini.h
diff options
context:
space:
mode:
authorvalmat <ufabiz@gmail.com>2014-04-13 21:20:52 +0600
committervalmat <ufabiz@gmail.com>2014-04-13 21:20:52 +0600
commit9b2ac923e4bf98ca76441362b1d15e58de4297c8 (patch)
treebab2b2e67b526550f9bfced48395f260ae36ad55 /include/ini.h
parent7df281b04d7286cd1cf7cad55848b6bf4a250c24 (diff)
Class IniValue designed for extracting values from ini entries
Diffstat (limited to 'include/ini.h')
-rw-r--r--include/ini.h133
1 files changed, 133 insertions, 0 deletions
diff --git a/include/ini.h b/include/ini.h
index 49587d7..83e287d 100644
--- a/include/ini.h
+++ b/include/ini.h
@@ -18,6 +18,127 @@ struct _zend_ini_entry;
namespace Php {
/**
+ * Class IniValue designed for extracting values from ini entries.
+ */
+class IniValue
+{
+public:
+ /**
+ * Constructors for floating point values
+ *
+ * @param name Name of the php.ini variable
+ * @param isorig Is the original value
+ */
+ IniValue(const char *name, const bool isorig) : _name(name), _isorig(isorig) {}
+
+ /**
+ * Cast to a number
+ * @return int32_t
+ */
+ operator int16_t () const
+ {
+ return (int16_t)numericValue();
+ }
+
+ /**
+ * Cast to a number
+ * @return int32_t
+ */
+ operator int32_t () const
+ {
+ return (int32_t)numericValue();
+ }
+
+ /**
+ * Cast to a number
+ * @return uint64_t
+ */
+ operator int64_t () const
+ {
+ return numericValue();
+ }
+
+ /**
+ * Cast to a boolean
+ * @return boolean
+ */
+ operator bool () const
+ {
+ return (bool)numericValue();
+ }
+
+ /**
+ * Cast to a string
+ * @return string
+ */
+ operator std::string () const
+ {
+ return rawValue();
+ }
+
+ /**
+ * Cast to byte array
+ * @return const char *
+ */
+ operator const char * () const
+ {
+ return rawValue();
+ }
+
+ /**
+ * Cast to a floating point
+ * @return double
+ */
+ operator double() const;
+
+
+private:
+
+
+ /**
+ * Retrieve the value as number
+ *
+ * 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;
+
+ /**
+ * Get access to the raw buffer for read operationrs.
+ * @return const char *
+ */
+ const char *rawValue() const;
+
+ /**
+ * ini entry name
+ * @var std::string
+ */
+ std::string _name;
+
+ /**
+ * Is the orig value?
+ * @var bool
+ */
+ bool _isorig = false;
+};
+
+/**
+ * Custom output stream operator
+ * @param stream
+ * @param ini_val
+ * @return ostream
+ */
+std::ostream &operator<<(std::ostream &stream, const IniValue &ini_val)
+{
+ return stream << static_cast<const char*>(ini_val);
+}
+
+
+/**
* Class definition
*/
class Ini
@@ -117,6 +238,18 @@ public:
*/
void fill(struct _zend_ini_entry *ini_entry, int module_number);
+
+ static IniValue get(const char* name)
+ {
+ return IniValue(name, false);
+ }
+
+ static IniValue get_orig(const char* name)
+ {
+ return IniValue(name, true);
+ }
+
+
private:
/**
* Helper function to convert a boolean to a string