Commit a7b9d99f authored by Ronan's avatar Ronan
Browse files

feat(variant): add impl (in progress) on getValue

parent 0c9fbfc1
......@@ -19,8 +19,6 @@
#ifndef _CHAT_MESSAGE_P_H_
#define _CHAT_MESSAGE_P_H_
#include <unordered_map>
#include "chat-message.h"
#include "db/events-db.h"
#include "object/object-p.h"
......
......@@ -16,8 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <unordered_map>
#include "db/events-db.h"
#include "object/object-p.h"
......@@ -88,7 +86,7 @@ shared_ptr<const ErrorInfo> ChatMessage::getErrorInfo () const {
void ChatMessage::send () {
L_D(ChatMessage);
if (d->contents.size() > 1) {
MultipartChatMessageModifier mcmm;
mcmm.encode(d);
......@@ -159,7 +157,7 @@ void ChatMessage::addContent (const shared_ptr<Content> &content) {
void ChatMessage::removeContent (const shared_ptr<const Content> &content) {
L_D(ChatMessage);
if (d->isReadOnly) return;
d->contents.remove(const_pointer_cast<Content>(content));
}
......
......@@ -67,8 +67,6 @@ public:
std::shared_ptr<const ErrorInfo> getErrorInfo () const;
std::string getContentType () const;
void send ();
bool containsReadableText () const;
......
......@@ -16,8 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <unordered_map>
#include <belr/abnf.h>
#include <belr/grammarbuilder.h>
......
......@@ -16,8 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <unordered_map>
#ifdef SOCI_ENABLED
#include <soci/soci.h>
#endif // ifdef SOCI_ENABLED
......
......@@ -20,6 +20,8 @@
// =============================================================================
using namespace std;
LINPHONE_BEGIN_NAMESPACE
class VariantPrivate {
......@@ -27,10 +29,13 @@ public:
union Value {
int i;
unsigned int ui;
short s;
unsigned short us;
long l;
unsigned long ul;
long long ll;
unsigned long long ull;
char c;
bool b;
double d;
float f;
......@@ -61,42 +66,57 @@ Variant::Variant (int value) : Variant(Int) {
d->value.i = value;
}
Variant::Variant (unsigned int value) : Variant(Int) {
Variant::Variant (unsigned int value) : Variant(UnsignedInt) {
L_D(Variant);
d->value.ui = value;
}
Variant::Variant (long value) : Variant(Int) {
Variant::Variant (short value) : Variant(Short) {
L_D(Variant);
d->value.s = value;
}
Variant::Variant (unsigned short value) : Variant(UnsignedShort) {
L_D(Variant);
d->value.us = value;
}
Variant::Variant (long value) : Variant(Long) {
L_D(Variant);
d->value.l = value;
}
Variant::Variant (unsigned long value) : Variant(Int) {
Variant::Variant (unsigned long value) : Variant(UnsignedLong) {
L_D(Variant);
d->value.ul = value;
}
Variant::Variant (long long value) : Variant(Int) {
Variant::Variant (long long value) : Variant(LongLong) {
L_D(Variant);
d->value.ll = value;
}
Variant::Variant (unsigned long long value) : Variant(Int) {
Variant::Variant (unsigned long long value) : Variant(UnsignedLongLong) {
L_D(Variant);
d->value.ull = value;
}
Variant::Variant (bool value) : Variant(Int) {
Variant::Variant (char value) : Variant(Char) {
L_D(Variant);
d->value.c = value;
}
Variant::Variant (bool value) : Variant(Bool) {
L_D(Variant);
d->value.b = value;
}
Variant::Variant (double value) : Variant(Int) {
Variant::Variant (double value) : Variant(Double) {
L_D(Variant);
d->value.d = value;
}
Variant::Variant (float value) : Variant(Int) {
Variant::Variant (float value) : Variant(Float) {
L_D(Variant);
d->value.f = value;
}
......@@ -163,12 +183,113 @@ void Variant::swap (const Variant &variant) {
}
// -----------------------------------------------------------------------------
// Number conversions.
// -----------------------------------------------------------------------------
static inline long long getValueAsNumber (const VariantPrivate &p, bool *soFarSoGood) {
// TODO.
return 0;
}
static inline unsigned long long getValueAsUnsignedNumber (const VariantPrivate &p, bool *soFarSoGood) {
// TODO.
return 0;
}
// -----------------------------------------------------------------------------
// Specific conversions.
// -----------------------------------------------------------------------------
static inline bool getValueAsBool (const VariantPrivate &p, bool *soFarSoGood) {
// TODO.
return false;
}
static inline double getValueAsDouble (const VariantPrivate &p, bool *soFarSoGood) {
// TODO.
return 0.0;
}
void Variant::getValue (int type, void *value, bool *soFarSoGood) {
if (type <= 0 || type >= MaxDefaultTypes)
return; // Unable to get value.
static inline float getValueAsFloat (const VariantPrivate &p, bool *soFarSoGood) {
// TODO.
return 0.f;
}
static inline float getValueAsString (const VariantPrivate &p, bool *soFarSoGood) {
// TODO.
return 0.f;
}
static inline void *getValueAsGeneric (const VariantPrivate &p, bool *soFarSoGood) {
// TODO.
return nullptr;
}
// -----------------------------------------------------------------------------
void Variant::getValue (int type, void *value, bool *soFarSoGood) const {
L_D(const Variant);
if (type <= 0 || type >= MaxDefaultTypes) {
*soFarSoGood = false;
// Unable to get value. It will be great to support custom types.
return;
}
switch (static_cast<Type>(type)) {
// Cast as Number.
case Int:
*static_cast<int *>(value) = static_cast<int>(getValueAsNumber(*d, soFarSoGood));
break;
case Short:
*static_cast<short *>(value) = static_cast<short>(getValueAsNumber(*d, soFarSoGood));
break;
case Long:
*static_cast<long *>(value) = static_cast<long>(getValueAsNumber(*d, soFarSoGood));
break;
case LongLong:
*static_cast<long long *>(value) = getValueAsNumber(*d, soFarSoGood);
break;
case Char:
*static_cast<char *>(value) = static_cast<char>(getValueAsNumber(*d, soFarSoGood));
break;
// Cast as Unsigned number.
case UnsignedInt:
*static_cast<unsigned int *>(value) = static_cast<unsigned int>(getValueAsNumber(*d, soFarSoGood));
break;
case UnsignedShort:
*static_cast<unsigned short *>(value) = static_cast<unsigned short>(getValueAsNumber(*d, soFarSoGood));
break;
case UnsignedLong:
*static_cast<unsigned long *>(value) = static_cast<unsigned long>(getValueAsNumber(*d, soFarSoGood));
break;
case UnsignedLongLong:
*static_cast<unsigned long long *>(value) = getValueAsNumber(*d, soFarSoGood);
break;
// Cast as specific value.
case Bool:
*static_cast<bool *>(value) = getValueAsBool(*d, soFarSoGood);
break;
case Double:
*static_cast<double *>(value) = getValueAsDouble(*d, soFarSoGood);
break;
case Float:
*static_cast<float *>(value) = getValueAsFloat(*d, soFarSoGood);
break;
case String:
*static_cast<string *>(value) = getValueAsString(*d, soFarSoGood);
break;
case Generic:
*static_cast<void **>(value) = getValueAsGeneric(*d, soFarSoGood);
break;
case Invalid:
case MaxDefaultTypes:
*soFarSoGood = false;
break;
}
}
LINPHONE_END_NAMESPACE
......@@ -30,15 +30,18 @@ LINPHONE_BEGIN_NAMESPACE
#define L_DECLARE_VARIANT_TYPES(FUNC) \
FUNC(int, Int, 1) \
FUNC(unsigned int, UnsignedInt, 2) \
FUNC(long, Long, 3) \
FUNC(unsigned long, UnsignedLong, 4) \
FUNC(long long, LongLong, 5) \
FUNC(unsigned long long, UnsignedLongLong, 6) \
FUNC(bool, Bool, 7) \
FUNC(double, Double, 8) \
FUNC(float, Float, 9) \
FUNC(std::string, String, 10) \
FUNC(void *, Generic, 11)
FUNC(short, Short, 3) \
FUNC(unsigned short, UnsignedShort, 4) \
FUNC(long, Long, 5) \
FUNC(unsigned long, UnsignedLong, 6) \
FUNC(long long, LongLong, 7) \
FUNC(unsigned long long, UnsignedLongLong, 8) \
FUNC(char, Char, 9) \
FUNC(bool, Bool, 10) \
FUNC(double, Double, 11) \
FUNC(float, Float, 12) \
FUNC(std::string, String, 13) \
FUNC(void *, Generic, 14)
#define L_DECLARE_VARIANT_ENUM_TYPE(TYPE, NAME, ID) NAME = ID,
#define L_DECLARE_VARIANT_TRAIT_TYPE(TYPE, NAME, ID) \
......@@ -65,10 +68,13 @@ public:
Variant (int value);
Variant (unsigned int value);
Variant (short value);
Variant (unsigned short value);
Variant (long value);
Variant (unsigned long value);
Variant (long long value);
Variant (unsigned long long value);
Variant (char value);
Variant (bool value);
Variant (double value);
Variant (float value);
......@@ -100,7 +106,12 @@ public:
static_assert(id != Invalid, "Unable to get value of unsupported type.");
T value;
getValue(id, &value, &soFarSoGood);
bool ok;
getValue(id, static_cast<void *>(&value), &ok);
if (soFarSoGood)
*soFarSoGood = ok;
return value;
}
......@@ -115,7 +126,7 @@ private:
static const int id = Invalid;
};
void getValue (int type, void *value, bool *soFarSoGood);
void getValue (int type, void *value, bool *soFarSoGood) const;
VariantPrivate *mPrivate = nullptr;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment