epics-base / pvDataCPP

pvDataCPP is an EPICS V4 C++ module
https://epics-base.github.io/pvDataCPP/
Other
6 stars 16 forks source link

Default values for scalar fields #63

Closed mdavidsaver closed 2 years ago

mdavidsaver commented 5 years ago

So far all fields are initialized to a fixed default value based on the field type (0, "', [], or NULL). This change allows customized default values of scalar and scalar array field. Adds overloads to FieldCreate and FieldBuilder which accept variant containers AnyScalar or shared_vector<const void> which convey both type and initial value.

StructureConstPtr mydef(FieldBuilder::begin()
                        ->add("myname", pvInt)     # defaults to zero
                        ->add("other", uint32(42)) # also pvInt, defaults to 42
                        ->createStructure());

PVStructurePtr inst(mydef->build());
assert(inst->getSubFieldT<PVInt>("myname")->get==0);
assert(inst->getSubFieldT<PVInt>("other")->get==42);

In support of https://github.com/epics-base/pvDataCPP/pull/62 to provide a non-empty default for "display.form.choices".

mdavidsaver commented 5 years ago

This is not a protocol change as defaults are applied prior to serialization of instances.

This isn't ideal. It can work semi-transparently because most existing servers are lazy about changed tracking. Preferring to set bit zero (entire structure changed).

It would be better if either:

  1. Changed tracking were integrated in PVField.
  2. The default value was included in the serialized type description.

However, both are more work than I have time for at present. So it's either this, or encode defaults in multiple downstream modules (which can be done anyway). Also with 2) it isn't clear to me how to do this in a backward compatible way (a firm requirement now).

mdavidsaver commented 2 years ago

Abandoned.