[SERVER-31656] Provide a way for IDL types to reset to default values Created: 20/Oct/17  Updated: 27/Oct/23  Resolved: 19/Jan/18

Status: Closed
Project: Core Server
Component/s: IDL
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Samantha Ritter (Inactive) Assignee: DO NOT USE - Backlog - Platform Team
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Participants:

 Description   

If I have an IDL type with many integer fields (perhaps that are counters, for example) it would be nice to be able to reset them without having to do the following:

IDLObject obj;
 
obj.setFieldOne(0);
obj.setFieldTwo(0);
obj.setFieldThree(0);
obj.setFieldFour(0);
obj.setFieldFive(0);
obj.setFieldSix(0);

Perhaps something like:

IDLObject obj;
obj.setAllFieldsToDefaultValues();



 Comments   
Comment by Mark Benvenuto [ 19/Jan/18 ]

It is unclear what the use case for this given the the constructor of the IDL generated class initializes members with default values to their values.

Comment by Mark Benvenuto [ 20/Oct/17 ]

Fields with default values are initialized to their default values.

For instance, in this test

    default_values:
        description: UnitTest for a single safeInt32
        fields:
            V_string:
                type: string
                default: '"a default"'
            V_int:
                type: int
                default: 42
    ...

It generates a class with members initialized:

class Default_values {
...
private:
    std::string _v_string{"a default"};
    std::int32_t _v_int{37};

Generated at Thu Feb 08 04:27:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.