add: add set property functions

This commit is contained in:
Mike Solar
2025-08-10 21:08:47 +08:00
parent 2b4f19075c
commit a0a0bea87f
2 changed files with 307 additions and 40 deletions
+197 -22
View File
@@ -28,63 +28,230 @@ namespace olive
{
namespace plugin
{
class Value;
enum class Type {
FLOAT, STRING, INT, POINTER, ARRAY, NONE
};
class Array {
private:
Type type;
int strSize=0;
char** strings;
QVector<void *> pointers;
QVector<int> ints;
QVector<double> floats;
public:
Array()
{
type=Type::NONE;
}
Array(const int *data, size_t size)
{
this->type=Type::INT;
ints.reserve(size);
std::copy(data, data+size, ints.data());
}
Array(const double *data, size_t size)
{
this->type=Type::FLOAT;
floats.reserve(size);
std::copy(data, data+size, floats.data());
}
Array(void * const* data, size_t size)
{
this->type=Type::POINTER;
pointers.reserve(size);
std::copy(data, data+size, pointers.data());
}
Array(const char * const *data, size_t size)
{
strings=(char**)malloc(sizeof(char *)*size);
for (int i=0;i<size;i++) {
int len=strlen(data[i]);
strings[i]=(char*)malloc(sizeof(char)*len);
strncpy(strings[i], data[i], len);
}
strSize=size;
}
void setArray(int *data, size_t size)
{
this->type=Type::INT;
ints.clear();
ints.reserve(size);
std::copy(data, data+size, ints.data());
}
void setArray(double *data, size_t size)
{
this->type=Type::FLOAT;
floats.clear();
floats.reserve(size);
std::copy(data, data+size, floats.data());
}
void setArray(void *const*data, size_t size)
{
this->type=Type::POINTER;
pointers.reserve(size);
pointers.clear();
std::copy(data, data+size, pointers.data());
}
void setArray(const char * const *data, size_t size)
{
for (int i=0;i<this->strSize;i++) {
free(strings[i]);
}
free(strings);
strings=nullptr;
strings=(char**)malloc(sizeof(char *)*size);
for (int i=0;i<size;i++) {
int len=strlen(data[i]);
strings[i]=(char*)malloc(sizeof(char)*len);
strncpy(strings[i], data[i], len);
}
strSize=size;
}
int size()
{
switch (type) {
case Type::INT: {
return ints.size();
}
case Type::FLOAT: {
return floats.size();
}
case Type::POINTER: {
return pointers.size();
}
case Type::STRING: {
return strSize;
}
}
}
int *getInts(int *size)
{
*size=ints.size();
return ints.data();
}
double *getFLoats(int *size)
{
*size=floats.size();
return floats.data();
}
void **getPointers(int *size)
{
*size=pointers.size();
return pointers.data();
}
char **getStrings(int *size)
{
*size=strSize;
return strings;
}
bool isInt()
{
return type==Type::INT;
}
bool isFloat()
{
return type==Type::FLOAT;
}
bool isString()
{
return type==Type::STRING;
}
bool isPointer()
{
return type==Type::POINTER;
}
};
class Value {
private:
enum Type {
FLOAT, STRING, INT, NONE
};
int64_t valueInt=0;
int valueInt=0;
double valueDouble=0;
QString valueString;
Type type=NONE;
void *valuePointer;
Type type=Type::NONE;
Array array;
public:
Value()=default;
Value(int64_t val)
Value(int val)
{
valueInt=val;
type=INT;
type=Type::INT;
}
Value(double val)
{
valueDouble=val;
type=FLOAT;
type=Type::FLOAT;
}
Value(QString val)
{
valueString=val;
type=STRING;
type=Type::STRING;
}
Value(void *val)
{
valuePointer=val;
type=Type::POINTER;
}
Value(Array val)
{
array=val;
type=Type::ARRAY;
}
void setValue(int64_t val)
{
valueInt=val;
type=INT;
type=Type::INT;
}
void setValue(double val)
{
valueDouble=val;
type=FLOAT;
type=Type::FLOAT;
}
void setValue(QString val)
{
valueString=val;
type=STRING;
type=Type::STRING;
}
void setValue(void *val)
{
valuePointer=val;
type=Type::POINTER;
}
void setValue(nullptr_t val)
{
valueInt=0;
valueDouble=0;
valueString=QString();
type=NONE;
type=Type::NONE;
}
int64_t getInt() const
void setValue(Array val)
{
return valueInt;
valueInt=0;
valueDouble=0;
valueString=QString();
array=val;
type=Type::ARRAY;
}
int getInt() const
{
if (type==Type::INT)
return valueInt;
return 0;
}
double getFloat() const
{
return valueDouble;
if (type==Type::FLOAT)
return valueDouble;
return 0;
}
Array getArray() const
{
if (type==Type::ARRAY)
return array;
return Array();
}
QString getString()
{
@@ -92,26 +259,34 @@ public:
}
bool isInt()
{
return type==INT;
return type==Type::INT;
}
bool isFloat()
{
return type==FLOAT;
return type==Type::FLOAT;
}
bool isString()
{
return type==STRING;
return type==Type::STRING;
}
bool isPointer()
{
return type==Type::POINTER;
}
bool isArray()
{
return type==Type::ARRAY;
}
bool isNull()
{
return type==NONE;
return type==Type::NONE;
}
};
struct plugin_mem_ptr {
void *mem;
int32_t count=0;
};
class OlivePlugin {
public:
OlivePlugin()=default;
+110 -18
View File
@@ -24,25 +24,117 @@ OfxStatus propSetPointer(OfxPropertySetHandle properties,
{
olive::plugin::Value val;
if (properties->plugin) {
OfxStatus status= properties->plugin->getProp(property, index, val);
if (val.isInt()) {
value=calloc(1,sizeof(long));
*(int64_t*)value=val.getInt();
properties->plugin->addMem(value);
if (index<0) {
return kOfxStatErrBadIndex;
}
else if (val.isFloat()) {
value=calloc(1,sizeof(double));
*(double*)value=val.getFloat();
properties->plugin->addMem(value);
}
else if (val.isString()) {
QString str=val.getString();
value=(void *)calloc(str.size()+1, sizeof(char));
memcpy(value, str.data(), str.size());
properties->plugin->addMem(value);
}
return status;
properties->plugin->setProp(property, index, value);
return kOfxStatOK;
}
return kOfxStatErrBadHandle;
}
}
OfxStatus propSetString(OfxPropertySetHandle properties,
const char *property, int index, const char *value)
{
olive::plugin::Value val;
if (properties->plugin) {
if (index<0) {
return kOfxStatErrBadIndex;
}
properties->plugin->setProp(property, index, QString(value));
return kOfxStatOK;
}
return kOfxStatErrBadHandle;
}
OfxStatus propSetDouble(OfxPropertySetHandle properties,
const char *property, int index, double value)
{
olive::plugin::Value val;
if (properties->plugin) {
if (index<0) {
return kOfxStatErrBadIndex;
}
properties->plugin->setProp(property, index, static_cast<double>(value));
return kOfxStatOK;
}
return kOfxStatErrBadHandle;
}
OfxStatus propSetInt(OfxPropertySetHandle properties, const char *property,
int index, int value)
{
olive::plugin::Value val;
if (properties->plugin) {
if (index<0) {
return kOfxStatErrBadIndex;
}
properties->plugin->setProp(property, index, value);
return kOfxStatOK;
}
return kOfxStatErrBadHandle;
}
OfxStatus propSetPointerN(OfxPropertySetHandle properties,
const char *property, int index, int count, void * const*value)
{
olive::plugin::Value val;
olive::plugin::Array array(value,count);
val.setValue(array);
if (properties->plugin) {
if (index<0) {
return kOfxStatErrBadIndex;
}
properties->plugin->setProp(property, index, val);
return kOfxStatOK;
}
return kOfxStatErrBadHandle;
}
OfxStatus propSetStringN(OfxPropertySetHandle properties,
const char *property, int index, int count,const char *const *value)
{
olive::plugin::Value val;
olive::plugin::Array array(value,count);
val.setValue(array);
if (properties->plugin) {
if (index<0) {
return kOfxStatErrBadIndex;
}
properties->plugin->setProp(property, index, val);
return kOfxStatOK;
}
return kOfxStatErrBadHandle;
}
OfxStatus propSetDoubleN(OfxPropertySetHandle properties,
const char *property, int index, int count, const double* value)
{
olive::plugin::Value val;
olive::plugin::Array array(value,count);
val.setValue(array);
if (properties->plugin) {
if (index<0) {
return kOfxStatErrBadIndex;
}
properties->plugin->setProp(property, index, val);
return kOfxStatOK;
}
return kOfxStatErrBadHandle;
}
OfxStatus propSetIntN(OfxPropertySetHandle properties, const char *property,
int index, int count, const int *value)
{
olive::plugin::Value val;
olive::plugin::Array array(value, count);
val.setValue(array);
if (properties->plugin) {
if (index<0) {
return kOfxStatErrBadIndex;
}
properties->plugin->setProp(property, index, val);
return kOfxStatOK;
}
return kOfxStatErrBadHandle;
}