Skip to content

Commit 30338c0

Browse files
Redefining Wrapper kind property as template class
1 parent 14d1f27 commit 30338c0

14 files changed

+63
-282
lines changed

extras/test/src/test_CloudWrapperFloat.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include <CBORDecoder.h>
1212

13-
#include <property/types/CloudWrapperFloat.h>
13+
#include <property/PropertyContainer.h>
1414

1515
/**************************************************************************************
1616
TEST CODE

extras/test/src/test_callback.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <util/CBORTestUtil.h>
1212
#include <CBORDecoder.h>
1313
#include <PropertyContainer.h>
14-
#include "types/CloudWrapperBool.h"
1514
#include <memory>
1615

1716
/**************************************************************************************

extras/test/src/test_decode.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
#include <util/CBORTestUtil.h>
1515

1616
#include <CBORDecoder.h>
17-
#include "types/CloudWrapperBool.h"
18-
#include "types/CloudWrapperFloat.h"
19-
#include "types/CloudWrapperInt.h"
2017
#include "types/CloudWrapperString.h"
2118
#include "types/automation/CloudColoredLight.h"
2219
#include "types/automation/CloudDimmedLight.h"

extras/test/src/test_encode.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
#include <memory>
1212

1313
#include <util/CBORTestUtil.h>
14-
#include "types/CloudWrapperBool.h"
15-
#include "types/CloudWrapperFloat.h"
16-
#include "types/CloudWrapperInt.h"
1714
#include "types/CloudWrapperString.h"
1815

1916
/**************************************************************************************

src/ArduinoIoTCloud.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@
3939

4040
#include "property/Property.h"
4141
#include "property/PropertyContainer.h"
42-
#include "property/types/CloudWrapperBool.h"
43-
#include "property/types/CloudWrapperFloat.h"
44-
#include "property/types/CloudWrapperInt.h"
45-
#include "property/types/CloudWrapperUnsignedInt.h"
4642
#include "property/types/CloudWrapperString.h"
4743

4844
#include "utility/time/TimeService.h"

src/ArduinoIoTCloudThing.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
#include "ArduinoIoTCloudThing.h"
2121
#include "interfaces/CloudProcess.h"
22-
#include "property/types/CloudWrapperInt.h"
23-
#include "property/types/CloudWrapperUnsignedInt.h"
2422

2523
/******************************************************************************
2624
* CTOR/DTOR

src/property/PropertyContainer.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,15 @@ extern "C" unsigned long getTime();
5454

5555
typedef std::list<Property *> PropertyContainer;
5656

57-
typedef PropertyPrimitive<bool> CloudBool;
58-
typedef PropertyPrimitive<float> CloudFloat;
59-
typedef PropertyPrimitive<int> CloudInt;
60-
typedef PropertyPrimitive<unsigned int> CloudUnsignedInt;
57+
typedef PropertyPrimitive<bool> CloudBool;
58+
typedef PropertyPrimitive<float> CloudFloat;
59+
typedef PropertyPrimitive<int> CloudInt;
60+
typedef PropertyPrimitive<unsigned int> CloudUnsignedInt;
61+
62+
typedef CloudWrapperProperty<bool> CloudWrapperBool;
63+
typedef CloudWrapperProperty<float> CloudWrapperFloat;
64+
typedef CloudWrapperProperty<int> CloudWrapperInt;
65+
typedef CloudWrapperProperty<unsigned int> CloudWrapperUnsignedInt;
6166

6267
typedef CloudFloat CloudEnergy;
6368
typedef CloudFloat CloudForce;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "CloudWrapperBase.h"
2+
#include "../math_utils.h"
3+
4+
// template specialization for float CloudWrapperProperty to handle nan values
5+
template<>
6+
bool CloudWrapperProperty<float>::isDifferentFromCloud() {
7+
return arduino::math::ieee754_different(_primitive_value, _cloud_value, Property::_min_delta_property);
8+
}

src/property/types/CloudWrapperBase.h

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,52 @@
2323
******************************************************************************/
2424

2525
#include <Arduino.h>
26-
#include "../Property.h"
26+
#include "PropertyPrimitive.h"
2727

2828
/******************************************************************************
2929
CLASS DECLARATION
3030
******************************************************************************/
3131

32-
class CloudWrapperBase : public Property {
32+
class CloudWrapperBaseInterface {
3333
public:
3434
virtual bool isChangedLocally() = 0;
3535
};
3636

37+
class CloudWrapperBase : public Property, public CloudWrapperBaseInterface {
38+
public:
39+
virtual bool isChangedLocally() = 0;
40+
};
41+
42+
template<typename T>
43+
class CloudWrapperProperty : public PropertyPrimitive<T>, public CloudWrapperBaseInterface {
44+
public:
45+
CloudWrapperProperty(T& value)
46+
: PropertyPrimitive<T>(value), _primitive_value(value) { }
47+
48+
bool isDifferentFromCloud() override {
49+
return _primitive_value != PropertyPrimitive<T>::_cloud_value;
50+
}
51+
52+
void fromCloudToLocal() override {
53+
_primitive_value = PropertyPrimitive<T>::_cloud_value;
54+
}
55+
void fromLocalToCloud() override {
56+
PropertyPrimitive<T>::_cloud_value = _primitive_value;
57+
}
58+
59+
CborError appendAttributesToCloud(CborEncoder *encoder) override {
60+
return PropertyPrimitive<T>::appendAttribute(_primitive_value, "", encoder);
61+
}
62+
void setAttributesFromCloud() override {
63+
PropertyPrimitive<T>::setAttribute(PropertyPrimitive<T>::_cloud_value, "");
64+
}
65+
66+
bool isChangedLocally() override {
67+
return _primitive_value != PropertyPrimitive<T>::_value;
68+
}
69+
protected:
70+
T &_primitive_value;
71+
};
72+
3773

3874
#endif /* CLOUDWRAPPERBASE_H_ */

src/property/types/CloudWrapperBool.h

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)