From b79d680580a5832d7c3384e556f70776f2df5084 Mon Sep 17 00:00:00 2001 From: Laurens Voerman Date: Thu, 15 Feb 2018 14:53:52 +0100 Subject: [PATCH] move Get/SetScalarvalue out of ValueObject and provide specialization for GetScalarValue fixing MSVC waring C4800 --- include/osg/ValueObject | 111 ++++++++++++++++++++++++---------------- 1 file changed, 67 insertions(+), 44 deletions(-) diff --git a/include/osg/ValueObject b/include/osg/ValueObject index 604b25ec3..91c5b2392 100644 --- a/include/osg/ValueObject +++ b/include/osg/ValueObject @@ -58,6 +58,11 @@ class Plane; class Matrixf; class Matrixd; +template +class GetScalarValue; +template +class SetScalarValue; + class ValueObject : public Object { public: @@ -134,28 +139,6 @@ class ValueObject : public Object }; - template - class GetScalarValue : public ValueObject::GetValueVisitor - { - public: - - GetScalarValue() : set(false), value(0) {} - - bool set; - T value; - - virtual void apply(bool in_value) { value = in_value ? 1 : 0; set = true; } - virtual void apply(char in_value) { value = in_value; set = true; } - virtual void apply(unsigned char in_value) { value = in_value; set = true; } - virtual void apply(short in_value) { value = in_value; set = true; } - virtual void apply(unsigned short in_value) { value = in_value; set = true; } - virtual void apply(int in_value) { value = in_value; set = true; } - virtual void apply(unsigned int in_value) { value = in_value; set = true; } - virtual void apply(float in_value) { value = in_value; set = true; } - virtual void apply(double in_value) { value = in_value; set = true; } - }; - - class SetValueVisitor { public: @@ -213,28 +196,6 @@ class ValueObject : public Object virtual void apply(osg::BoundingSphered& /*in_value*/) {} }; - - template - class SetScalarValue : public ValueObject::SetValueVisitor - { - public: - - SetScalarValue(T in_value) : set(false), value(in_value) {} - - bool set; - T value; - - virtual void apply(bool& in_value) { in_value=(value!=0); set = true;} - virtual void apply(char& in_value) { in_value=value; set = true;} - virtual void apply(unsigned char& in_value) { in_value=value; set = true;} - virtual void apply(short& in_value) { in_value=value; set = true;} - virtual void apply(unsigned short& in_value) { in_value=value; set = true;} - virtual void apply(int& in_value) { in_value=value; set = true;} - virtual void apply(unsigned int& in_value) { in_value=value; set = true;} - virtual void apply(float& in_value) { in_value=value; set = true;} - virtual void apply(double& in_value) { in_value=value; set = true;} - }; - virtual bool get(GetValueVisitor& /*gvv*/) const { return false; } virtual bool set(SetValueVisitor& /*gvv*/) { return false; } @@ -248,6 +209,68 @@ protected: virtual ~ValueObject() {} }; +template +class GetScalarValue : public ValueObject::GetValueVisitor +{ +public: + + GetScalarValue() : set(false), value(0) {} + + bool set; + T value; + + virtual void apply(bool in_value) { value = in_value ? 1 : 0; set = true; } + virtual void apply(char in_value) { value = in_value; set = true; } + virtual void apply(unsigned char in_value) { value = in_value; set = true; } + virtual void apply(short in_value) { value = in_value; set = true; } + virtual void apply(unsigned short in_value) { value = in_value; set = true; } + virtual void apply(int in_value) { value = in_value; set = true; } + virtual void apply(unsigned int in_value) { value = in_value; set = true; } + virtual void apply(float in_value) { value = in_value; set = true; } + virtual void apply(double in_value) { value = in_value; set = true; } +}; +template<> +class GetScalarValue : public ValueObject::GetValueVisitor +{ +public: + + GetScalarValue() : set(false), value(0) {} + + bool set; + bool value; + + virtual void apply(bool in_value) { value = in_value; set = true; } + virtual void apply(char in_value) { value = in_value != 0; set = true; } + virtual void apply(unsigned char in_value) { value = in_value != 0; set = true; } + virtual void apply(short in_value) { value = in_value != 0; set = true; } + virtual void apply(unsigned short in_value) { value = in_value != 0; set = true; } + virtual void apply(int in_value) { value = in_value != 0; set = true; } + virtual void apply(unsigned int in_value) { value = in_value != 0; set = true; } + virtual void apply(float in_value) { value = in_value != 0.0f; set = true; } + virtual void apply(double in_value) { value = in_value != 0.0; set = true; } +}; + +template +class SetScalarValue : public ValueObject::SetValueVisitor +{ +public: + + SetScalarValue(T in_value) : set(false), value(in_value) {} + + bool set; + T value; + + virtual void apply(bool& in_value) { in_value=(value!=0); set = true;} + virtual void apply(char& in_value) { in_value=value; set = true;} + virtual void apply(unsigned char& in_value) { in_value=value; set = true;} + virtual void apply(short& in_value) { in_value=value; set = true;} + virtual void apply(unsigned short& in_value) { in_value=value; set = true;} + virtual void apply(int& in_value) { in_value=value; set = true;} + virtual void apply(unsigned int& in_value) { in_value=value; set = true;} + virtual void apply(float& in_value) { in_value=value; set = true;} + virtual void apply(double& in_value) { in_value=value; set = true;} +}; + template< typename T > struct ValueObjectClassNameTrait {