-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add data converter and data types for conversion
First PR for converters support. It adds the abstract data_converter class And adds new data value objects that can be passed between converters to easily transform one type of data to another https://github.com/user-attachments/assets/e8a0fdee-8845-4d0d-a894-c948c2b0a209 Diffs= 4bf7c7545 add data converter and data types for conversion (#7734) Co-authored-by: hernan <[email protected]>
- Loading branch information
Showing
34 changed files
with
684 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
d9f5701ec10c0d0eecb0e3d2f5b0ee80499c746d | ||
4bf7c75453f0fc3fec1519a9a3dfe7a4ed63a054 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "DataConverter", | ||
"key": { | ||
"int": 488, | ||
"string": "dataconverter" | ||
}, | ||
"abstract": true, | ||
"properties": { | ||
"order": { | ||
"type": "FractionalIndex", | ||
"initialValue": "FractionalIndex.invalid", | ||
"initialValueRuntime": "0", | ||
"key": { | ||
"int": 661, | ||
"string": "order" | ||
}, | ||
"description": "Order value for sorting data converters", | ||
"runtime": false | ||
}, | ||
"name": { | ||
"type": "String", | ||
"initialValue": "''", | ||
"key": { | ||
"int": 662, | ||
"string": "name" | ||
}, | ||
"description": "Non-unique identifier, used to give friendly names to data converters." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef _RIVE_DATA_CONVERTER_HPP_ | ||
#define _RIVE_DATA_CONVERTER_HPP_ | ||
#include "rive/generated/data_bind/converters/data_converter_base.hpp" | ||
#include "rive/data_bind/data_values/data_value.hpp" | ||
#include <stdio.h> | ||
namespace rive | ||
{ | ||
class DataConverter : public DataConverterBase | ||
{ | ||
public: | ||
virtual DataValue* convert(DataValue* value) { return value; }; | ||
virtual DataValue* reverseConvert(DataValue* value) { return value; }; | ||
virtual DataType outputType() { return DataType::none; }; | ||
StatusCode import(ImportStack& importStack) override; | ||
}; | ||
} // namespace rive | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef _RIVE_DATA_TYPE_HPP_ | ||
#define _RIVE_DATA_TYPE_HPP_ | ||
namespace rive | ||
{ | ||
/// Data types used for converters. | ||
enum class DataType : unsigned int | ||
{ | ||
/// None. | ||
none = 0, | ||
|
||
/// String. | ||
string = 1, | ||
|
||
/// Number. | ||
number = 2, | ||
|
||
/// Bool. | ||
boolean = 3, | ||
|
||
/// Color. | ||
color = 4, | ||
|
||
/// List. | ||
list = 5, | ||
|
||
/// Enum. | ||
enumType = 6 | ||
}; | ||
} // namespace rive | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef _RIVE_DATA_VALUE_HPP_ | ||
#define _RIVE_DATA_VALUE_HPP_ | ||
#include "rive/data_bind/data_values/data_type.hpp" | ||
|
||
#include <stdio.h> | ||
namespace rive | ||
{ | ||
class DataValue | ||
{ | ||
public: | ||
virtual bool isTypeOf(DataType dataType) const { return false; } | ||
template <typename T> inline bool is() const { return isTypeOf(T::typeKey); } | ||
template <typename T> inline T* as() | ||
{ | ||
assert(is<T>()); | ||
return static_cast<T*>(this); | ||
} | ||
}; | ||
} // namespace rive | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef _RIVE_DATA_VALUE_BOOLEAN_HPP_ | ||
#define _RIVE_DATA_VALUE_BOOLEAN_HPP_ | ||
#include "rive/data_bind/data_values/data_value.hpp" | ||
|
||
#include <stdio.h> | ||
namespace rive | ||
{ | ||
class DataValueBoolean : public DataValue | ||
{ | ||
private: | ||
bool m_value = false; | ||
|
||
public: | ||
DataValueBoolean(bool value) : m_value(value){}; | ||
DataValueBoolean(){}; | ||
static const DataType typeKey = DataType::boolean; | ||
bool isTypeOf(DataType typeKey) const override { return typeKey == DataType::boolean; } | ||
bool value() { return m_value; }; | ||
void value(bool value) { m_value = value; }; | ||
}; | ||
} // namespace rive | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef _RIVE_DATA_VALUE_COLOR_HPP_ | ||
#define _RIVE_DATA_VALUE_COLOR_HPP_ | ||
#include "rive/data_bind/data_values/data_value.hpp" | ||
|
||
#include <stdio.h> | ||
namespace rive | ||
{ | ||
class DataValueColor : public DataValue | ||
{ | ||
private: | ||
int m_value = false; | ||
|
||
public: | ||
DataValueColor(int value) : m_value(value){}; | ||
DataValueColor(){}; | ||
static const DataType typeKey = DataType::color; | ||
bool isTypeOf(DataType typeKey) const override { return typeKey == DataType::color; } | ||
int value() { return m_value; }; | ||
void value(int value) { m_value = value; }; | ||
}; | ||
} // namespace rive | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef _RIVE_DATA_VALUE_ENUM_HPP_ | ||
#define _RIVE_DATA_VALUE_ENUM_HPP_ | ||
#include "rive/data_bind/data_values/data_value.hpp" | ||
#include "rive/viewmodel/data_enum.hpp" | ||
|
||
#include <iostream> | ||
namespace rive | ||
{ | ||
class DataValueEnum : public DataValue | ||
{ | ||
private: | ||
uint32_t m_value = 0; | ||
DataEnum* m_dataEnum; | ||
|
||
public: | ||
DataValueEnum(uint32_t value, DataEnum* dataEnum) : m_value(value), m_dataEnum(dataEnum){}; | ||
DataValueEnum(){}; | ||
static const DataType typeKey = DataType::enumType; | ||
bool isTypeOf(DataType typeKey) const override { return typeKey == DataType::enumType; }; | ||
uint32_t value() { return m_value; }; | ||
void value(uint32_t value) { m_value = value; }; | ||
DataEnum* dataEnum() { return m_dataEnum; }; | ||
void dataEnum(DataEnum* value) { m_dataEnum = value; }; | ||
}; | ||
} // namespace rive | ||
#endif |
Oops, something went wrong.